Randell Dawson c8f6d15688
feat(tool): Add ability to view all open PRs for repos other than freeCodeCamp in the Dashboard app (#40453)
* feat: show open boilerplate prs on dashboard

fix:  rest of boilerplate server changes

fix: more

fix: other

* fix: update lib functions

* fix: retrofitted one-off scripts

* feat: added rateLimit for requests

* fix: reduce time

* fix: put limiter inside each route

* fix: make client show when rated limited

* fix: removed unused probot from app

* fix: renamed folders

* fix: consolidate config.js and constants.js

* chore: update octokit to latest version

* fix: remove invalid file

* fix: refactored update-db.js

* feat: add fcc logo

* fix: logo url

* fix: remove Home link

* fix: change link colors

* fix: added rate limiter to landing page

* fix: ran npm install in client to create package-lock.json

* fix: correct typo in doc

Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>

* fix: Replace favicon, Gitter => Discord

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* fix: add extra linting guidance to package.json

* Ignore contributor app

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

* fix: revert linting rules for client

* fix: add skip_preflight_check=true for tests

Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Kris Koishigawa <scissorsneedfoodtoo@gmail.com>
Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
2020-12-22 13:43:36 +09:00

58 lines
1.5 KiB
JavaScript

const { addComment } = require('./add-comment');
const { rateLimiter } = require('../utils');
const {
github: { owner, secret, freeCodeCampRepo, defaultBase }
} = require('../config');
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({ auth: secret });
/* closes and reopens an open PR with applicable comment */
const closeOpen = async number => {
await octokit.pulls
.update({
owner,
repo: freeCodeCampRepo,
number,
state: 'closed',
base: defaultBase
})
.then(async () => {
await rateLimiter(5000);
return octokit.pulls.update({
owner,
repo: freeCodeCampRepo,
number,
state: 'open',
base: defaultBase
});
})
.then(async () => {
await rateLimiter(1000);
const msg = 'Closed/Reopened to resolve a specific Travis build failure.';
await addComment(number, msg);
})
.catch(async err => {
// Octokit stores message as a stringified object
const { errorMg } = JSON.parse(err.message);
if (
errorMg ===
'state cannot be changed. The repository that submitted this pull request has been deleted.'
) {
await rateLimiter(1000);
await addComment(
number,
"This PR was closed because user's repo was deleted."
);
console.log(
`PR #${number} was closed because user's repo was deleted.`
);
} else {
throw err;
}
});
};
module.exports = { closeOpen };