Skip to content

Commit

Permalink
Replace got with axios (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 committed Dec 25, 2018
1 parent 8540bd5 commit 0345d19
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
- run:
name: Creating Artifacts
command: |
npm run -s shorturl || (mkdir -p /tmp/short_urls/lib && cp lib/*.json /tmp/short_urls/lib)
npm run -s shorturl || tar -zcvf shorturl.tar.gz lib/*.json
when: always
- store_artifacts:
path: /tmp/short_urls
path: shorturl.tar.gz
destination: short URLs
- store_test_results:
path: ~/lint-reports
12 changes: 5 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ root = true
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 2
tab_width = 4
insert_final_newline = true
trim_trailing_whitespace = true
block_comment_start = /*
Expand All @@ -16,12 +18,8 @@ block_comment_end = */
[*.{cmd,bat}]
end_of_line = crlf

[*.md]
tab_width = 2

[{package.json,*.yml}]
[*.{yml,md}]
indent_style = space
indent_size = 2

[lib/*.json]
insert_final_newline = false
[package.json]
indent_style = space
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ gulp-reporter
======

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

Expand Down Expand Up @@ -33,8 +33,8 @@ npm install gulp-reporter

```js
gulp.src('test/fixtures/eslint/invalid.js')
.pipe(eslint())
.pipe(reporter(options));
.pipe(eslint())
.pipe(reporter(options));
```

![demo](demo.png)
Expand Down Expand Up @@ -110,15 +110,15 @@ Convert errors.

```
reporter({
mapper: file => {
const path = file.path;
return error => {
// Do not report unrelated errors.
if (error.fileName === path) {
return error
}
}
}
mapper: file => {
const path = file.path;
return error => {
// Do not report unrelated errors.
if (error.fileName === path) {
return error
}
}
}
})
```

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

- AppVeyor
> Output as compilation message use [Build Worker API](https://www.appveyor.com/docs/build-worker-api/#add-compilation-message)
> Output as compilation message use [Build Worker API](https://www.appveyor.com/docs/build-worker-api/#add-compilation-message)
- CircleCI
> 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/).
> 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/).
- Jenkins
> 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.
> 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.
## Related

Expand Down
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install:
- npm install -g npm@latest
# install modules
- npm install || (7z a logs.zip %APPDATA%/npm-cache/_logs/*.log && appveyor PushArtifact logs.zip)
- bash -c "cd node_modules/nyc && npm i https://github.com/pangrr/spawn-wrap/archive/fix/shebang-path-space.tar.gz --production"
- bash -c "cd node_modules/nyc && npm i https://github.com/gucong3000/spawn-wrap/archive/shebang-path-space.tar.gz --production"

# to run your custom scripts instead of automatic tests
test_script:
Expand All @@ -23,4 +23,3 @@ test_script:
# to run your custom scripts instead of provider deployments
after_test:
- npm run report-coverage
- npm run -s shorturl || (7z a shorturl.zip lib/*.json && appveyor PushArtifact shorturl.zip)
17 changes: 8 additions & 9 deletions lib/ci-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const checkstyleFormatter = require('checkstyle-formatter');
const reportBuilder = require('junit-report-builder');
const yaml = require('js-yaml');
const fs = require('fs-extra');
const axios = require('axios');
const ci = require('ci-info');
const path = require('path');
const got = require('got');
const url = require('url');
const os = require('os');
const icons = require('./icons');

const privatePrefix = ci.isCI && ci.name && ci.name.replace(/\s*CI$/i, '').toUpperCase() + '_';
const reportPath = path.join.bind(
path,
Expand All @@ -32,21 +33,19 @@ function noop () {
}

function appveyor (errors) {
errors = errors.map(error => {
got.post(appveyorApiUrl, {
body: {
return Promise.all(
errors.map(error => (
axios.post(appveyorApiUrl, {
message: `${icons[error.severity] || icons.success} ${error.message}`,
category: category[error.severity] || error.severity,
details: [error.plugin, error.rule, (error.docShort || error.doc)].filter(Boolean).join(' '),
fileName: error.fileName,
line: error.lineNumber,
column: error.columnNumber,
projectName: [error.plugin, error.rule].filter(Boolean).join(' '),
},
json: true,
});
});
return Promise.all(errors);
})
))
);
}

function getEnv (names) {
Expand Down
23 changes: 10 additions & 13 deletions lib/short-doc-url.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
const got = require('got');
const locale = require('./locale');
const ci = require('ci-info');
const inGFW = require('in-gfw');
const axios = require('axios');
const ci = require('ci-info');
const locale = require('./locale');

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

Expand Down Expand Up @@ -32,18 +32,15 @@ function shortUrl (url) {
}
return isInGFW.then(inGFW => (
inGFW
? got(`https://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=${encodeURIComponent(url)}`, {
json: true,
}).then(result => (
result.body[0].url_short.replace(/^https?/i, 'https')
? axios.get(
`https://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=${encodeURIComponent(url)}`
).then(result => (
result.data[0].url_short.replace(/^https?/i, 'https')
))
: got.post('https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyACqNSi3cybDvDfWMaPyXZEzQ6IeaPehLE', {
json: true,
body: {
'longUrl': url,
},
: axios.post('https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyACqNSi3cybDvDfWMaPyXZEzQ6IeaPehLE', {
'longUrl': url,
}).then(result =>
result.body.id
result.data.id
)
));
});
Expand Down
Loading

0 comments on commit 0345d19

Please sign in to comment.