Permalink
Browse files

tools, feat: adapt github's new authentication. (#416)

  • Loading branch information...
richardo2016 authored and xicilion committed May 5, 2018
1 parent da53123 commit 7dd3d90a1568780d54dcaadf597702bee1270e0c
Showing with 13 additions and 11 deletions.
  1. +13 −11 tools/awesome.js
View
@@ -24,24 +24,26 @@ function clean_folder(p) {
clean_folder(docsFolder);
fs.mkdir(path.join(docsFolder, 'module'));
var token = 'xxxxxxxxxxxxxx';
var basicAuthentication = process.env.GITHUB_AUTH_USER || 'username:token';
var list = new Buffer(http.get("https://api.github.com/repos/fibjs/awesome/readme", {
headers: {
"Authorization": "token " + token
}
}).json().content, 'base64').toString();
var token = require('base64').encode(basicAuthentication)
var headers = {
"Authorization": "Basic " + token,
}
var tokenInfo = http.get(`https://api.github.com/user`, { headers }).json()
if (!tokenInfo.login) {
throw 'github basic authorization failed'
}
var list = new Buffer(http.get("https://api.github.com/repos/fibjs/awesome/readme", { headers }).json().content, 'base64').toString();
var ls = [];
list = list.replace(/- \[(.+?)\]\((.+?)\)/g, (s, s1, s2) => {
var u = s2.replace(/^https:\/\/github.com\//, 'https://api.github.com/repos/') + '/readme';
console.log('getting', u);
coroutine.sleep(100);
var doc = new Buffer(http.get(u, {
headers: {
"Authorization": "token " + token
}
}).json().content, 'base64').toString();
var doc = new Buffer(http.get(u, { headers }).json().content, 'base64').toString();
fs.writeTextFile(path.join(docsFolder, 'module', s1 + '.md'), doc);
var s = `[${s1}](./module/${s1}.md)`

0 comments on commit 7dd3d90

Please sign in to comment.