Skip to content

Commit 423deed

Browse files
authoredJun 15, 2018
infrastructure(site) Add GitHub token to GitHub API calls (webpack#2270)
* testing gh token * fix lint * verbose * reexport env var * fix lint * test token * source env fro mTravis * put back rest of fetch script
1 parent ea2af1e commit 423deed

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed
 

‎.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ sudo: required
99
install:
1010
- yarn
1111
- sudo pip install proselint
12+
before_script:
13+
- source ./src/scripts/env.sh
1214
script:
1315
- bash ./src/scripts/deploy.sh

‎src/scripts/env.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -e # Exit with nonzero exit code if anything fails
3+
4+
export GITHUB_TOKEN=$GITHUB_TOKEN
5+

‎src/scripts/fetch_package_names.js

+35-26
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,67 @@
11
#!/usr/bin/env node
22
// ./fetch_package_names <suffix> > output
33
// ./fetch_package_names "-loader" > output.json
4-
const GitHubApi = require("github");
4+
const GitHubApi = require('github');
55

66
if (require.main === module) {
7-
main();
7+
main();
88
} else {
9-
module.exports = fetchPackageNames;
9+
module.exports = fetchPackageNames;
1010
}
1111

1212
function main() {
1313
const organization = process.argv[2];
1414
const suffix = process.argv[3];
1515

16-
if(!organization) {
16+
if (!organization) {
1717
return console.error('Missing organization!');
1818
}
19-
if(!suffix) {
19+
if (!suffix) {
2020
return console.error('Missing suffix!');
2121
}
2222

23-
fetchPackageNames({
24-
organization: organization,
25-
suffix: suffix
26-
}, function(err, d) {
27-
if (err) {
28-
return console.error(err);
29-
}
23+
fetchPackageNames(
24+
{
25+
organization: organization,
26+
suffix: suffix
27+
},
28+
function(err, d) {
29+
if (err) {
30+
return console.error(err);
31+
}
3032

31-
console.log(JSON.stringify(d, null, 4));
32-
});
33+
console.log(JSON.stringify(d, null, 4));
34+
}
35+
);
3336
}
3437

3538
function fetchPackageNames(options, cb) {
3639
const github = new GitHubApi();
3740

38-
if(process.env.GITHUB_TOKEN) {
41+
if (process.env.GITHUB_TOKEN) {
3942
github.authenticate({
4043
type: 'token',
4144
token: process.env.GITHUB_TOKEN
4245
});
4346
}
4447

4548
// XXX: weak since this handles only one page
46-
github.repos.getForOrg({
47-
org: options.organization,
48-
per_page: 100
49-
}, function (err, d) {
50-
if (err) {
51-
return cb(err);
52-
}
49+
github.repos.getForOrg(
50+
{
51+
org: options.organization,
52+
per_page: 100
53+
},
54+
function(err, d) {
55+
if (err) {
56+
return cb(err);
57+
}
5358

54-
return cb(null, d.data.filter(function(o) {
55-
return o.name.endsWith(options.suffix);
56-
}));
57-
});
59+
return cb(
60+
null,
61+
d.data.filter(function(o) {
62+
return o.name.endsWith(options.suffix);
63+
})
64+
);
65+
}
66+
);
5867
}

0 commit comments

Comments
 (0)