Skip to content

Instantly share code, notes, and snippets.

@mbenford
Last active April 17, 2017 09:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbenford/3765a3bfd017744d4ed0aaaa16c54fd7 to your computer and use it in GitHub Desktop.
Save mbenford/3765a3bfd017744d4ed0aaaa16c54fd7 to your computer and use it in GitHub Desktop.
ngTagsInput spring cleaning script
const path = require('path');
const GitHubApi = require('github');
const jsonfile = require('jsonfile');
const moment = require('moment');
const async = require('async');
const config = require('./config.json');
const github = new GitHubApi({ protocol: 'https' });
github.authenticate({ type: 'oauth', token: config.token });
const owner = 'mbenford';
const repo = 'ngTagsInput';
const issues = jsonfile.readFileSync(path.join(__dirname, 'issues.json'));
const selectedIssues = issues.filter(issue => moment().diff(issue.updated_at, 'days') > 30);
async.eachSeries(selectedIssues,
(issue, next) => {
closeIssue(issue.number)
.then(() => {
console.log(`Issue ${issue.number} closed`);
next();
})
.catch(err => {
console.log(`Error closing issue %{issue.number}: ${err}`);
next(err);
});
},
err => {
if (err) {
console.log(`Error: ${err}`);
process.exit(1);
}
console.log('Finished');
});
function closeIssue(issueId) {
const createComment = () => {
const message = 'This issue was selected to be spring-cleaned by a script. More information can be found [here](https://github.com/mbenford/ngTagsInput/issues/790).\n\n' +
'If anyone thinks this was a mistake and this issue should be reopened, ' +
'please leave a message below explaining why. ' +
'Before doing so, please consider reading the [CONTRIBUTING](https://github.com/mbenford/ngTagsInput/blob/master/CONTRIBUTING.md) file.';
return github.issues.createComment({ owner, repo, number: issueId, body: message });
};
const addLabel = () => {
return github.issues.addLabels({ owner, repo, number: issueId, labels: ['spring-cleaned'] });
};
const close = () => {
return github.issues.edit({ owner, repo, number: issueId, state: 'closed' });
};
return createComment()
.then(addLabel)
.then(close);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment