Skip to content

Commit 0345d19

Browse files
authored
Replace got with axios (#310)
1 parent 8540bd5 commit 0345d19

File tree

10 files changed

+378
-53
lines changed

10 files changed

+378
-53
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828
- run:
2929
name: Creating Artifacts
3030
command: |
31-
npm run -s shorturl || (mkdir -p /tmp/short_urls/lib && cp lib/*.json /tmp/short_urls/lib)
31+
npm run -s shorturl || tar -zcvf shorturl.tar.gz lib/*.json
3232
when: always
3333
- store_artifacts:
34-
path: /tmp/short_urls
34+
path: shorturl.tar.gz
3535
destination: short URLs
3636
- store_test_results:
3737
path: ~/lint-reports

.editorconfig

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ root = true
77
charset = utf-8
88
end_of_line = lf
99
indent_style = tab
10+
indent_size = 2
11+
tab_width = 4
1012
insert_final_newline = true
1113
trim_trailing_whitespace = true
1214
block_comment_start = /*
@@ -16,12 +18,8 @@ block_comment_end = */
1618
[*.{cmd,bat}]
1719
end_of_line = crlf
1820

19-
[*.md]
20-
tab_width = 2
21-
22-
[{package.json,*.yml}]
21+
[*.{yml,md}]
2322
indent_style = space
24-
indent_size = 2
2523

26-
[lib/*.json]
27-
insert_final_newline = false
24+
[package.json]
25+
indent_style = space

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ gulp-reporter
22
======
33

44
[![NPM version](https://img.shields.io/npm/v/gulp-reporter.svg?style=flat-square)](https://www.npmjs.com/package/gulp-reporter)
5-
[![Travis](https://img.shields.io/travis/gucong3000/gulp-reporter.svg?&label=Linux)](https://travis-ci.org/gucong3000/gulp-reporter)
6-
[![AppVeyor](https://img.shields.io/appveyor/ci/gucong3000/gulp-reporter.svg?&label=Windows)](https://ci.appveyor.com/project/gucong3000/gulp-reporter)
5+
[![Travis](https://img.shields.io/travis/gucong3000/gulp-reporter.svg?label=Linux)](https://travis-ci.org/gucong3000/gulp-reporter)
6+
[![AppVeyor](https://img.shields.io/appveyor/ci/gucong3000/gulp-reporter.svg?label=Windows)](https://ci.appveyor.com/project/gucong3000/gulp-reporter)
77
[![Codecov](https://img.shields.io/codecov/c/github/gucong3000/gulp-reporter.svg)](https://codecov.io/gh/gucong3000/gulp-reporter)
88
[![David](https://img.shields.io/david/gucong3000/gulp-reporter.svg)](https://david-dm.org/gucong3000/gulp-reporter)
99

@@ -33,8 +33,8 @@ npm install gulp-reporter
3333

3434
```js
3535
gulp.src('test/fixtures/eslint/invalid.js')
36-
.pipe(eslint())
37-
.pipe(reporter(options));
36+
.pipe(eslint())
37+
.pipe(reporter(options));
3838
```
3939

4040
![demo](demo.png)
@@ -110,15 +110,15 @@ Convert errors.
110110

111111
```
112112
reporter({
113-
mapper: file => {
114-
const path = file.path;
115-
return error => {
116-
// Do not report unrelated errors.
117-
if (error.fileName === path) {
118-
return error
119-
}
120-
}
121-
}
113+
mapper: file => {
114+
const path = file.path;
115+
return error => {
116+
// Do not report unrelated errors.
117+
if (error.fileName === path) {
118+
return error
119+
}
120+
}
121+
}
122122
})
123123
```
124124

@@ -149,11 +149,11 @@ Enable or disable [git-blame](https://git-scm.com/docs/git-blame) related featur
149149
## Special output format
150150

151151
- AppVeyor
152-
> Output as compilation message use [Build Worker API](https://www.appveyor.com/docs/build-worker-api/#add-compilation-message)
152+
> Output as compilation message use [Build Worker API](https://www.appveyor.com/docs/build-worker-api/#add-compilation-message)
153153
- CircleCI
154-
> Output as junit format to directory that defined in [`$CIRCLE_TEST_REPORTS` ](https://circleci.com/docs/1.0/test-metadata/) or [`store_test_results`](https://circleci.com/docs/2.0/collect-test-data/).
154+
> Output as junit format to directory that defined in [`$CIRCLE_TEST_REPORTS` ](https://circleci.com/docs/1.0/test-metadata/) or [`store_test_results`](https://circleci.com/docs/2.0/collect-test-data/).
155155
- Jenkins
156-
> Output as [checkstyle](http://checkstyle.sourceforge.net) format to directory defined in `$CI_REPORTS`, you need to install [Checkstyle Plugin](https://plugins.jenkins.io/checkstyle) to view it.
156+
> Output as [checkstyle](http://checkstyle.sourceforge.net) format to directory defined in `$CI_REPORTS`, you need to install [Checkstyle Plugin](https://plugins.jenkins.io/checkstyle) to view it.
157157
158158
## Related
159159

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ install:
1414
- npm install -g npm@latest
1515
# install modules
1616
- npm install || (7z a logs.zip %APPDATA%/npm-cache/_logs/*.log && appveyor PushArtifact logs.zip)
17-
- bash -c "cd node_modules/nyc && npm i https://github.com/pangrr/spawn-wrap/archive/fix/shebang-path-space.tar.gz --production"
17+
- bash -c "cd node_modules/nyc && npm i https://github.com/gucong3000/spawn-wrap/archive/shebang-path-space.tar.gz --production"
1818

1919
# to run your custom scripts instead of automatic tests
2020
test_script:
@@ -23,4 +23,3 @@ test_script:
2323
# to run your custom scripts instead of provider deployments
2424
after_test:
2525
- npm run report-coverage
26-
- npm run -s shorturl || (7z a shorturl.zip lib/*.json && appveyor PushArtifact shorturl.zip)

lib/ci-reporter.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ const checkstyleFormatter = require('checkstyle-formatter');
33
const reportBuilder = require('junit-report-builder');
44
const yaml = require('js-yaml');
55
const fs = require('fs-extra');
6+
const axios = require('axios');
67
const ci = require('ci-info');
78
const path = require('path');
8-
const got = require('got');
99
const url = require('url');
1010
const os = require('os');
1111
const icons = require('./icons');
12+
1213
const privatePrefix = ci.isCI && ci.name && ci.name.replace(/\s*CI$/i, '').toUpperCase() + '_';
1314
const reportPath = path.join.bind(
1415
path,
@@ -32,21 +33,19 @@ function noop () {
3233
}
3334

3435
function appveyor (errors) {
35-
errors = errors.map(error => {
36-
got.post(appveyorApiUrl, {
37-
body: {
36+
return Promise.all(
37+
errors.map(error => (
38+
axios.post(appveyorApiUrl, {
3839
message: `${icons[error.severity] || icons.success} ${error.message}`,
3940
category: category[error.severity] || error.severity,
4041
details: [error.plugin, error.rule, (error.docShort || error.doc)].filter(Boolean).join(' '),
4142
fileName: error.fileName,
4243
line: error.lineNumber,
4344
column: error.columnNumber,
4445
projectName: [error.plugin, error.rule].filter(Boolean).join(' '),
45-
},
46-
json: true,
47-
});
48-
});
49-
return Promise.all(errors);
46+
})
47+
))
48+
);
5049
}
5150

5251
function getEnv (names) {

lib/short-doc-url.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
2-
const got = require('got');
3-
const locale = require('./locale');
4-
const ci = require('ci-info');
52
const inGFW = require('in-gfw');
3+
const axios = require('axios');
4+
const ci = require('ci-info');
5+
const locale = require('./locale');
66

77
const isInGFW = ci.isCI && ci.name ? Promise.resolve(locale === 'zh_CN') : inGFW('goo.gl', 't.cn');
88

@@ -32,18 +32,15 @@ function shortUrl (url) {
3232
}
3333
return isInGFW.then(inGFW => (
3434
inGFW
35-
? got(`https://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=${encodeURIComponent(url)}`, {
36-
json: true,
37-
}).then(result => (
38-
result.body[0].url_short.replace(/^https?/i, 'https')
35+
? axios.get(
36+
`https://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=${encodeURIComponent(url)}`
37+
).then(result => (
38+
result.data[0].url_short.replace(/^https?/i, 'https')
3939
))
40-
: got.post('https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyACqNSi3cybDvDfWMaPyXZEzQ6IeaPehLE', {
41-
json: true,
42-
body: {
43-
'longUrl': url,
44-
},
40+
: axios.post('https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyACqNSi3cybDvDfWMaPyXZEzQ6IeaPehLE', {
41+
'longUrl': url,
4542
}).then(result =>
46-
result.body.id
43+
result.data.id
4744
)
4845
));
4946
});

0 commit comments

Comments
 (0)