Skip to content

Commit

Permalink
Switch from node-fetch to axios
Browse files Browse the repository at this point in the history
  • Loading branch information
devnook committed Apr 13, 2022
1 parent 829d7bb commit 2c81d18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
15 changes: 6 additions & 9 deletions approvals/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

const micromatch = require('micromatch');
const fetch = require('node-fetch');
const axios = require('axios');

const CONFIG_FILE = 'chrome-devrel-bot.json';
const CONFIG_FILE = '.github/chrome-devrel-bot.json';

const CHECK_RESULTS = {
success: {
Expand Down Expand Up @@ -163,16 +163,13 @@ module.exports = (app) => {
};

// Get Config file
const url = `https://raw.githubusercontent.com/${owner}/${repo}/main/.github/${CONFIG_FILE}`;
const response = await fetch(url);
let config;
if (response.ok) {
const body = await response.text();
config = JSON.parse(body);
} else {
const url = `https://raw.githubusercontent.com/${owner}/${repo}/main/${CONFIG_FILE}`;
const response = await axios.get(url);
if (response.status !== 200) {
result = createCompletedResult(CHECK_RESULTS.no_config);
return await createCheck(octokit, checkOptions, result);
}
const config = response.data;

// Get PR files
const files = await getFiles(octokit, checkOptions, pullNumber);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"express": "4.17.1",
"markdownlint": "0.21.1",
"micromatch": "^4.0.5",
"node-fetch": "2.6.7",
"probot": "^12.2.2"
},
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions test/approvals/app.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const nock = require('nock');
const axios = require('axios');
// Requiring our app implementation
const Approvals = require('../../approvals/app');
const { Probot, ProbotOctokit } = require('probot');
Expand All @@ -10,6 +11,8 @@ const checkRunSuccess = require('./fixtures/check_run.success');
const checkRunNoApprovals = require('./fixtures/check_run.no_approvals');
const checkRunApprovalMissing = require('./fixtures/check_run.approval_missing');

// Configure Axios to use Node adapter (@see https://github.com/nock/nock#axios)
axios.defaults.adapter = require('axios/lib/adapters/http');

const privateKey = fs.readFileSync(
path.join(__dirname, 'fixtures/mock-cert.pem'),
Expand Down

0 comments on commit 2c81d18

Please sign in to comment.