Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created February 26, 2010 13:10
Show Gist options
  • Save tim-smart/315694 to your computer and use it in GitHub Desktop.
Save tim-smart/315694 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Export Github Issues
// @namespace http://userscripts.org/users/tim
// @description Can export issues by state and label
// @include http://github.com/*/issues*
// ==/UserScript==
(function() {
var GITHUB_API_URL, GithubRequest, URL_EXPRESSION, formatOutput, menuCallback, repo, url, user;
URL_EXPRESSION = /^.*\/(.*?)\/(.*?)\/issues.*$/;
GITHUB_API_URL = 'http://github.com/api/v2/json';
url = top.location.href.match(URL_EXPRESSION);
if (!url instanceof Array) {
return null;
}
user = url[1];
repo = url[2];
// Now for the github API goodness
GithubRequest = function GithubRequest() {
arguments = Array.prototype.slice.call(arguments, 0);
this._options = arguments;
return this;
};
GithubRequest.prototype.send = function send(callback) {
var self;
self = this;
return GM_xmlhttpRequest({
method: 'GET',
url: GITHUB_API_URL + '/' + this._makeApiParams(),
onload: function onload(xhr) {
return callback.call(self, JSON.parse(xhr.responseText));
}
});
};
GithubRequest.prototype._makeApiParams = function _makeApiParams() {
return this._options.join('/');
};
// Formatter
formatOutput = function formatOutput(source) {
var output;
output = '';
source.forEach(function(issue) {
// Title
output = output + 'Title: ' + issue.title + "\n";
// State
output = output + 'State: ' + issue.state + "\n";
// Labels
output = output + 'Labels: ' + issue.labels.join(', ' + "\n");
// Created
output = output + 'Created On: ' + issue.created_at + "\n";
// Updated
output = output + 'Last Updated' + issue.updated_at + "\n";
// Body
//output: output + "Body:\n" + issue.body + "\n"
return output = output + "\n\n";
});
return output;
};
// Make the callbacks
menuCallback = function menuCallback() {
var labels, state;
state = prompt('What state should the issues be? ("open", "closed")', 'closed');
state = state.toLowerCase();
if ('closed' !== state && 'open' !== state) {
alert('Invalid state!');
return null;
}
labels = prompt('What labels should the issues have? (Seperated by ",")');
labels = labels.toLowerCase();
0 === labels.length ? (labels = false) : (labels = labels.split(','));
return new GithubRequest('issues', 'list', user, repo, state).send(function(response) {
var issues;
if ('object' === typeof response.issues) {
issues = response.issues;
} else {
alert('Bad response!');
return null;
}
false !== labels ? (issues = issues.filter(function(issue) {
var _a, _b, _c, _d, label;
if (0 >= issue.labels.length) {
return false;
}
_a = []; _b = issue.labels;
for (_c = 0, _d = _b.length; _c < _d; _c++) {
label = _b[_c];
if (-1 !== labels.indexOf(label.toLowerCase())) {
return true;
}
}
return _a;
})) : null;
issues = formatOutput(issues);
return GM_openInTab('data:text/plain;charset=utf-8,' + encodeURIComponent(issues));
});
};
return GM_registerMenuCommand('Export Github Issues', menuCallback);
})();
# ==UserScript==
# @name Export Github Issues
# @namespace http://userscripts.org/users/tim
# @description Can export issues by state and label
# @include http://github.com/*/issues*
# ==/UserScript==
(->
URL_EXPRESSION: /^.*\/(.*?)\/(.*?)\/issues.*$/
GITHUB_API_URL: 'http://github.com/api/v2/json'
url: top.location.href.match URL_EXPRESSION
if not url instanceof Array
return
user: url[1]
repo: url[2]
# Now for the github API goodness
GithubRequest: ->
@_options: arguments
return @
GithubRequest::send: (callback) ->
self: @
GM_xmlhttpRequest {
method: 'GET'
url: GITHUB_API_URL + '/' + @_makeApiParams()
onload: (xhr) ->
callback.call self, JSON.parse xhr.responseText
}
GithubRequest::_makeApiParams: ->
@_options.join '/'
# Formatter
formatOutput: (source) ->
output: ''
source.forEach (issue) ->
# Title
output: output + 'Title: ' + issue.title + "\n"
# State
output: output + 'State: ' + issue.state + "\n"
# Labels
output: output + 'Labels: ' + issue.labels.join ', ' + "\n"
# Created
output: output + 'Created On: ' + issue.created_at + "\n"
# Updated
output: output + 'Last Updated' + issue.updated_at + "\n"
# Body
#output: output + "Body:\n" + issue.body + "\n"
output: output + "\n\n"
output
# Make the callbacks
menuCallback: ->
state: prompt 'What state should the issues be? ("open", "closed")', 'closed'
state: state.toLowerCase()
if 'closed' isnt state and 'open' isnt state
alert 'Invalid state!'
return
labels: prompt 'What labels should the issues have? (Seperated by ",")'
labels: labels.toLowerCase()
if 0 is labels.length
labels: false
else
labels: labels.split ','
new GithubRequest('issues', 'list', user, repo, state).send (response)->
if 'object' is typeof response.issues
issues: response.issues
else
alert 'Bad response!'
return
if false isnt labels
issues: issues.filter (issue) ->
if 0 >= issue.labels.length
return false
for label in issue.labels
if -1 isnt labels.indexOf label.toLowerCase()
return true
issues: formatOutput issues
GM_openInTab 'data:text/plain;charset=utf-8,' + encodeURIComponent issues
GM_registerMenuCommand 'Export Github Issues', menuCallback
)()
// ==UserScript==
// @name Export GitHub Issues
// @namespace http://userscripts.org/users/tim
// @description Can export issues by state and label
// @include http://github.com/*/issues*
// ==/UserScript==
(function() {
const URL_EXPRESSION = /^.*\/(.*?)\/(.*?)\/issues.*$/;
const GITHUB_API_URL = 'http://github.com/api/v2/json';
var url = top.location.href.match(URL_EXPRESSION);
if (!url)
return;
[, user, repo] = url;
// Now for the github api goodness
var GithubRequest = function() {
arguments = Array.prototype.slice.call(arguments);
this._options = arguments;
};
GithubRequest.prototype = {
send: function(callback) {
var self = this;
GM_xmlhttpRequest({
method: 'GET',
url: GITHUB_API_URL + '/' + this._makeApiParams(),
onload: function(xhr) {
var response = JSON.parse(xhr.responseText);
callback.call(self, response);
}
});
},
_makeApiParams: function() {
return this._options.join('/');
}
};
// Formatter
var formatOutput = function(source) {
var output = '';
for (var i = 0, issue; issue = source[i]; i++) {
// Title
output += "Title: " + issue.title + "\n";
// State
output += "State: " + issue.state + "\n";
// Labels
output += "Labels: " + issue.labels.join(', ') + "\n";
// Created
output += "Created On: " + issue.created_at + "\n";
// Updated
output += "Last Updated: " + issue.updated_at + "\n";
// Body
//output += "Body:\n" + issue.body + "\n";
output += "\n\n";
}
return output;
};
// Make the callbacks
var menuCallback = function() {
var state = prompt('What state should the issues be? ("open", "closed")', 'closed');
state = state.toLowerCase();
if ('closed' !== state && 'open' !== state) {
alert('Invalid state!');
return;
}
var labels = prompt('What labels should the issues have? (Seperated by ",")');
labels = labels.toLowerCase();
if ('' === labels)
labels = false;
else
labels = labels.split(',');
new GithubRequest('issues', 'list', user, repo, state).send(function(response) {
if ("object" === typeof response.issues)
var issues = response.issues;
else {
alert('Bad response!');
return;
}
if (false !== labels) {
issues = issues.filter(function(issue) {
if (0 >= issue.labels.length)
return false;
for (var i = 0, label; label = issue.labels[i]; i++) {
if (-1 !== labels.indexOf(label.toLowerCase()))
return true;
}
});
}
issues = formatOutput(issues);
GM_openInTab("data:text/plain;charset=utf-8," + encodeURIComponent(issues));
});
};
GM_registerMenuCommand('Export Github Issues', menuCallback);
})();
@Acorn-zz
Copy link

How did you preserve the metadata comments? Did you just copy and paste them after compiling?

@tim-smart
Copy link
Author

Notice the date :) Once upon a time coffeescript preserved comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment