Skip to content

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 9 commits into from
Jun 15, 2018
Merged
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ sudo: required
install:
- yarn
- sudo pip install proselint
before_script:
- source ./src/scripts/env.sh
script:
- bash ./src/scripts/deploy.sh
5 changes: 5 additions & 0 deletions src/scripts/env.sh
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

61 changes: 35 additions & 26 deletions src/scripts/fetch_package_names.js
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) {
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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

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);
})
);
}
);
}