Skip to content

Commit

Permalink
refactor: use urllib instead of request
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drop Node.js < 14 support
  • Loading branch information
fengmk2 committed Jan 8, 2023
1 parent 9c67356 commit e1d5c9a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
node-version: [ 16 ]
node-version: [ 14, 16, 18 ]
steps:
- name: Checkout Git Source
uses: actions/checkout@v3
Expand All @@ -29,7 +29,6 @@ jobs:

- name: Install dependencies
run: |
npm i npm@6 -g
npm i
- name: Continuous integration
Expand All @@ -38,4 +37,4 @@ jobs:
- name: Code coverage
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
20 changes: 10 additions & 10 deletions lib/git-contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const {
parse
} = require('url');
const path = require('path');
const Promise = require('bluebird');
const request = require('request-promise');
const httpclient = require('urllib');

const pkg = require('../package');

Expand All @@ -26,17 +25,18 @@ const gitLog2MailList = () => {
const getInfoFromGithub = maillist => {
const api = 'https://api.github.com/search/users?q=';
const tasks = maillist.map(email => {
const uri = `${api}${encodeURIComponent(email + ' in:email type:user')}`;
const options = {
uri: `${api}${encodeURIComponent(email + ' in:email type:user')}`,
json: true,
dataType: 'json',
headers: {
'user-agent': Date.now()
}
},
timeout: 30000
};
if (process.env.OAUTH_TOKEN) {
options.headers['Authorization'] = `token ${process.env.OAUTH_TOKEN}`;
}
return request(options);
return httpclient.request(uri, options).then(res => res.data);
});

return Promise.all(tasks).then(list => {
Expand All @@ -52,16 +52,16 @@ const getInfoFromGithubNewAPI = info => {
// https://docs.github.com/en/rest/reference/repos#list-repository-contributors get top 100 contributors
const uri = `https://api.github.com/repos/${info.groupName}/${info.repoName}/contributors?per_page=100`;
const options = {
uri,
json: true,
dataType: 'json',
headers: {
'user-agent': Date.now()
}
},
timeout: 30000
};
if (process.env.OAUTH_TOKEN) {
options.headers['Authorization'] = `token ${process.env.OAUTH_TOKEN}`;
}
return request(options);
return httpclient.request(uri, options).then(res => res.data);
};

const format = list => {
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@
},
"homepage": "https://github.com/xudafeng/git-contributor",
"dependencies": {
"bluebird": "^3.5.1",
"commander": "^2.15.1",
"request": "^2.85.0",
"request-promise": "^4.2.2",
"urllib": "^3.10.0",
"xutil": "^1.0.11"
},
"devDependencies": {
"babel-eslint": "^8.2.2",
"co-mocha": "*",
"c8": "^7.12.0",
"eslint": "*",
"eslint-plugin-mocha": "^4.11.0",
"mocha": "*",
"nyc": "^11.6.0",
"mocha": "^10.2.0",
"pre-commit": "*"
},
"scripts": {
"ci": "npm run lint && npm run test",
"test": "nyc --reporter=lcov --reporter=text mocha",
"test": "c8 --reporter=lcov --reporter=text mocha",
"lint": "eslint . --fix",
"contributor": "./bin/git-contributor"
"contributor": "./bin/git-contributor.js"
},
"pre-commit": [
"lint"
],
"engines": {
"node": ">= 14.17.0"
},
"license": "MIT"
}
20 changes: 8 additions & 12 deletions test/git-contributor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ const assert = require('assert');
const contributor = require('..');

describe('test', () => {
it('should be ok', (done) => {
contributor.getAuthor().then(list => {
const res = contributor.genMarkDown(list);
assert.equal(/auto updated/.test(res.content), true);
done();
});
it('should be ok', async () => {
const list = await contributor.getAuthor();
const res = contributor.genMarkDown(list);
assert.equal(/auto updated/.test(res.content), true);
});

it('should handle more than 12 authors', (done) => {
contributor.getAuthor({
it('should handle more than 12 authors', async () => {
const list = await contributor.getAuthor({
cwd: '/',
url: 'git://github.com/macacajs/macacajs.github.io.git'
}).then(list => {
const res = contributor.genMarkDown(list);
assert.equal(res.content.split('|\n').length >= 4, true);
done();
});
const res = contributor.genMarkDown(list);
assert.equal(res.content.split('|\n').length >= 4, true);
});
});

0 comments on commit e1d5c9a

Please sign in to comment.