Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating authentication scope, repo list and adding blacklist #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Both `<org>` and `<repo>` may optionally be formatted as `<org/repo>`.

## Examples

Standardaze the labels in a Red Flag repository:

```bash
org-labels standardize RedFlagTeam/<repo-name> RedFlagTeam/shared-github -d
```

The following would add a `docs` issue label with the color `d4c5f9` to every repo in `repo-utils`.

```bash
Expand Down
10 changes: 9 additions & 1 deletion bin/org-labels
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ program
.version(version)
.usage('<command>')
.option('-d, --destructive', 'allow standardize to remove labels that are not found in the config file')
.option('-b, --blacklist [value]', 'comma separated list of repositories to ignore', _collectRepos, []);

program
.command('add <org> <label> <color>')
Expand Down Expand Up @@ -73,14 +74,21 @@ function co_labels(fn, args) {
})
}

function _collectRepos(arg, repos) {
arg.split(",").forEach(function(s) {
repos.push(s);
});
return repos;
}

function* _org_labels(fn, args) {
yield* check_version()

var auth = yield ghauth({
configName: 'org-labels'
, userAgent : 'org-labels'
, note : 'org-labels CLI tool'
, scopes : []
, scopes : ['repo']
})

yield check_github_ratelimit(auth)
Expand Down
17 changes: 11 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = Labeler
*
* opts = {
* destructive: <boolean>
* blacklist: [array]
* }
}
*/
Expand Down Expand Up @@ -142,7 +143,7 @@ function* standardize(args) {
org = org_and_repo[0]
} else {
// if no single repo is specified, do all the repos! \o/
var repos = yield* this.get_repos(org)
var repos = yield* this.get_repos(org, this.opts.blacklist)
}

console.log('checking %d labels across %d repos', config.length, repos.length)
Expand Down Expand Up @@ -253,15 +254,15 @@ function compare_labels(config, _existing, destructive) {
*
* returns a list of repos
*/
function* get_repos(org) {
function* get_repos(org, blacklist) {
var repos = []
var page = 0
var last_length = 0

// handle github pagination for orgs with many repos
while (++page) {
var res = yield request({
uri : 'https://api.github.com/users/' + org + '/repos?page=' + page
uri : 'https://api.github.com/orgs/' + org + '/repos?page=' + page
, headers: header
, auth : this.auth
, json : true
Expand All @@ -271,7 +272,12 @@ function* get_repos(org) {

var i = res.length
while (i--) {
repos.push(res[i].name)
var name = res[i].name;
if(blacklist && blacklist.indexOf(name) != -1) {
console.log("Repo '" + name + "' is blacklisted; Ignoring")
} else {
repos.push(name)
}
}

// if this page has less repos than the last, then it is the last page.
Expand All @@ -293,9 +299,8 @@ function* get_repos(org) {
* returns an array of responses
*/
function* handle_label(org, method, opts, done) {
var repos = yield* this.get_repos(org)
var repos = yield* this.get_repos(org, this.opts.blacklist)
var results = yield* this.send_label(org, repos, opts, method)

var i = results.length
while (i--) {
log_result(results[i], opts.name)
Expand Down