-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add GitHub token to GitHub API calls #2270
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ddd708c
testing gh token
montogeek 4a718ce
fix lint
montogeek ba497e3
verbose
montogeek ee75b0a
reexport env var
montogeek 8456a64
fix lint
montogeek 4b50707
test token
montogeek bffced6
source env fro mTravis
montogeek 4c84621
put back rest of fetch script
montogeek 278c232
Merge branch 'master' into infra-github-token
montogeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
set -e # Exit with nonzero exit code if anything fails | ||
|
||
export GITHUB_TOKEN=$GITHUB_TOKEN | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,67 @@ | ||
#!/usr/bin/env node | ||
// ./fetch_package_names <suffix> > output | ||
// ./fetch_package_names "-loader" > output.json | ||
const GitHubApi = require("github"); | ||
const GitHubApi = require('github'); | ||
|
||
if (require.main === module) { | ||
main(); | ||
main(); | ||
} else { | ||
module.exports = fetchPackageNames; | ||
module.exports = fetchPackageNames; | ||
} | ||
|
||
function main() { | ||
const organization = process.argv[2]; | ||
const suffix = process.argv[3]; | ||
|
||
if(!organization) { | ||
if (!organization) { | ||
return console.error('Missing organization!'); | ||
} | ||
if(!suffix) { | ||
if (!suffix) { | ||
return console.error('Missing suffix!'); | ||
} | ||
|
||
fetchPackageNames({ | ||
organization: organization, | ||
suffix: suffix | ||
}, function(err, d) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
fetchPackageNames( | ||
{ | ||
organization: organization, | ||
suffix: suffix | ||
}, | ||
function(err, d) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
|
||
console.log(JSON.stringify(d, null, 4)); | ||
}); | ||
console.log(JSON.stringify(d, null, 4)); | ||
} | ||
); | ||
} | ||
|
||
function fetchPackageNames(options, cb) { | ||
const github = new GitHubApi(); | ||
|
||
if(process.env.GITHUB_TOKEN) { | ||
if (process.env.GITHUB_TOKEN) { | ||
github.authenticate({ | ||
type: 'token', | ||
token: process.env.GITHUB_TOKEN | ||
}); | ||
} | ||
|
||
// XXX: weak since this handles only one page | ||
github.repos.getForOrg({ | ||
org: options.organization, | ||
per_page: 100 | ||
}, function (err, d) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
github.repos.getForOrg( | ||
{ | ||
org: options.organization, | ||
per_page: 100 | ||
}, | ||
function(err, d) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
|
||
return cb(null, d.data.filter(function(o) { | ||
return o.name.endsWith(options.suffix); | ||
})); | ||
}); | ||
return cb( | ||
null, | ||
d.data.filter(function(o) { | ||
return o.name.endsWith(options.suffix); | ||
}) | ||
); | ||
} | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you define the error handler outside of function call and just pass it here pls? This would make it even more readable, same goes for following error handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of the scope of this PR, I just reformatted that file, actually I should revert it.
Also, we should change how fetch script works, one is reading stdout from the previous one, making it harder to test in isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah dont revert, formatting is good now