feat: modified the close/open scripts
This commit is contained in:
committed by
mrugesh mohapatra
parent
925a1d8a55
commit
37aceca8b0
@ -29,16 +29,16 @@ const getUserInput = async () => {
|
|||||||
const lastPR = prs[prs.length - 1].number;
|
const lastPR = prs[prs.length - 1].number;
|
||||||
log.setFirstLast({ firstPR, lastPR });
|
log.setFirstLast({ firstPR, lastPR });
|
||||||
for (let { number, data: { errorDesc } } of prs) {
|
for (let { number, data: { errorDesc } } of prs) {
|
||||||
if (errorDesc !== "unknown error") {
|
//if (errorDesc !== "unknown error") {
|
||||||
log.add(number, { closedOpened: true, errorDesc });
|
log.add(number, { closedOpened: true, errorDesc });
|
||||||
if (process.env.PRODUCTION_RUN === 'true') {
|
if (process.env.PRODUCTION_RUN === 'true') {
|
||||||
await closeOpen(number);
|
await closeOpen(number);
|
||||||
await rateLimiter(30000);
|
await rateLimiter(2000);
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
else {
|
//else {
|
||||||
log.add(number, { closedOpened: false, errorDesc });
|
// log.add(number, { closedOpened: false, errorDesc });
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -24,7 +24,7 @@ const errorsToFind = require(path.resolve(__dirname, '../input-files/failuresToF
|
|||||||
(async () => {
|
(async () => {
|
||||||
const { firstPR, lastPR } = await getUserInput();
|
const { firstPR, lastPR } = await getUserInput();
|
||||||
log.setFirstLast({ firstPR, lastPR });
|
log.setFirstLast({ firstPR, lastPR });
|
||||||
const prPropsToGet = ['number', 'head'];
|
const prPropsToGet = ['number', 'labels', 'head'];
|
||||||
const { openPRs } = await getPRs(firstPR, lastPR, prPropsToGet);
|
const { openPRs } = await getPRs(firstPR, lastPR, prPropsToGet);
|
||||||
|
|
||||||
if (openPRs.length) {
|
if (openPRs.length) {
|
||||||
@ -32,31 +32,34 @@ const errorsToFind = require(path.resolve(__dirname, '../input-files/failuresToF
|
|||||||
log.start();
|
log.start();
|
||||||
console.log('Starting error finding process...');
|
console.log('Starting error finding process...');
|
||||||
for (let count in openPRs) {
|
for (let count in openPRs) {
|
||||||
let { number, head: { sha: ref } } = openPRs[count];
|
let { number, labels, head: { sha: ref } } = openPRs[count];
|
||||||
const { data: statuses } = await octokit.repos.listStatusesForRef({ owner, repo, ref });
|
const existingLabels = labels.map(({ name }) => name);
|
||||||
|
|
||||||
if (statuses.length) {
|
if (!existingLabels.includes('status: merge conflict') && !existingLabels.includes('status: needs update') && !existingLabels.includes('status: discussing')) {
|
||||||
const { state, target_url } = statuses[0]; // first element contain most recent status
|
const { data: statuses } = await octokit.repos.listStatusesForRef({ owner, repo, ref });
|
||||||
const hasProblem = state === 'failure' || state === 'error';
|
if (statuses.length) {
|
||||||
if (hasProblem) {
|
const { state, target_url } = statuses[0]; // first element contain most recent status
|
||||||
let buildNum = Number(target_url.match(/\/builds\/(\d+)\?/i)[1]);
|
const hasProblem = state === 'failure' || state === 'error';
|
||||||
//const logNumber = 'need to use Travis api to access the full log for the buildNum above'
|
if (hasProblem) {
|
||||||
const logNumber = ++buildNum;
|
let buildNum = Number(target_url.match(/\/builds\/(\d+)\?/i)[1]);
|
||||||
const travisLogUrl = `https://api.travis-ci.org/v3/job/${logNumber}/log.txt`;
|
//const logNumber = 'need to use Travis api to access the full log for the buildNum above'
|
||||||
const response = await fetch(travisLogUrl)
|
const logNumber = ++buildNum;
|
||||||
const logText = await response.text();
|
const travisLogUrl = `https://api.travis-ci.org/v3/job/${logNumber}/log.txt`;
|
||||||
let found = false;
|
const response = await fetch(travisLogUrl)
|
||||||
let error;
|
const logText = await response.text();
|
||||||
for (let { error: errorDesc, regex } of errorsToFind) {
|
let found = false;
|
||||||
regex = RegExp(regex);
|
let error;
|
||||||
if (regex.test(logText)) {
|
for (let { error: errorDesc, regex } of errorsToFind) {
|
||||||
error = errorDesc;
|
regex = RegExp(regex);
|
||||||
found = true;
|
if (regex.test(logText)) {
|
||||||
break;
|
error = errorDesc;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
const errorDesc = error ? error : 'unknown error';
|
||||||
|
log.add(number, { errorDesc, buildLog: travisLogUrl });
|
||||||
}
|
}
|
||||||
const errorDesc = error ? error : 'unknown error';
|
|
||||||
log.add(number, { errorDesc, buildLog: travisLogUrl });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,24 @@ octokit.authenticate(octokitAuth);
|
|||||||
const closeOpen = async (number) => {
|
const closeOpen = async (number) => {
|
||||||
const result = await octokit.pullRequests.update({ owner, repo , number, state: 'closed', base: 'master' })
|
const result = await octokit.pullRequests.update({ owner, repo , number, state: 'closed', base: 'master' })
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await rateLimiter(2000);
|
await rateLimiter(10000);
|
||||||
return octokit.pullRequests.update({ owner, repo , number, state: 'open', base: 'master' })
|
return octokit.pullRequests.update({ owner, repo , number, state: 'open', base: 'master' })
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await rateLimiter(1000);
|
await rateLimiter(2000);
|
||||||
await addComment(number, 'Closed and Reopened this PR to attempt to resolve a specific Travis build failure.');
|
await addComment(number, 'Closed and Reopened this PR to attempt to resolve a specific Travis build failure.');
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(async (err) => {
|
||||||
console.log(err)
|
const { errors } = JSON.parse(err.message); // Octokit stores message as a stringified object
|
||||||
|
const errorMg = errors[0].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 {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user