feat: improved findFailures.js and closeOpen.js
This commit is contained in:
committed by
mrugesh mohapatra
parent
69d3b8cb84
commit
925a1d8a55
@ -1,5 +1,4 @@
|
||||
require('dotenv').config();
|
||||
// const formatDate = require('date-fns/format');
|
||||
|
||||
const { owner, repo, octokitConfig, octokitAuth } = require('../constants');
|
||||
|
||||
|
22
one-off-scripts/close-open-single-pr.js
Normal file
22
one-off-scripts/close-open-single-pr.js
Normal file
@ -0,0 +1,22 @@
|
||||
require('dotenv').config({ path: '../.env' });
|
||||
const { closeOpen } = require('../pr-tasks');
|
||||
|
||||
const getUserInput = async () => {
|
||||
let [ n, f, prNum ] = process.argv;
|
||||
|
||||
if (!Number(prNum)) {
|
||||
throw `Please specify a PR # to close and reopen.`;
|
||||
}
|
||||
return { prNum };
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const { prNum } = await getUserInput();
|
||||
return prNum;
|
||||
})()
|
||||
.then((prNum) => {
|
||||
closeOpen(prNum);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
});
|
51
one-off-scripts/close-open-specific-failures.js
Normal file
51
one-off-scripts/close-open-specific-failures.js
Normal file
@ -0,0 +1,51 @@
|
||||
require('dotenv').config({ path: '../.env' });
|
||||
const { closeOpen } = require('../pr-tasks');
|
||||
const { openJSONFile, ProcessingLog, rateLimiter } = require('../utils');
|
||||
|
||||
const log = new ProcessingLog('prs-closed-reopened');
|
||||
|
||||
log.start();
|
||||
const getUserInput = async () => {
|
||||
let [ n, f, filename ] = process.argv;
|
||||
|
||||
if (!filename) {
|
||||
throw `Please specify a file with PRs which needed to be closed and reopened.`;
|
||||
}
|
||||
|
||||
let fileObj = openJSONFile(filename);
|
||||
let { prs } = fileObj;
|
||||
if (!prs.length) {
|
||||
throw `Either no PRs found in file or there or an error occurred.`
|
||||
}
|
||||
return { prs };
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const { prs } = await getUserInput();
|
||||
return prs;
|
||||
})()
|
||||
.then(async (prs) => {
|
||||
const firstPR = prs[0].number;
|
||||
const lastPR = prs[prs.length - 1].number;
|
||||
log.setFirstLast({ firstPR, lastPR });
|
||||
for (let { number, data: { errorDesc } } of prs) {
|
||||
if (errorDesc !== "unknown error") {
|
||||
log.add(number, { closedOpened: true, errorDesc });
|
||||
if (process.env.PRODUCTION_RUN === 'true') {
|
||||
await closeOpen(number);
|
||||
await rateLimiter(30000);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log.add(number, { closedOpened: false, errorDesc });
|
||||
}
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
log.finish();
|
||||
console.log('closing/reopening of PRs complete');
|
||||
})
|
||||
.catch(err => {
|
||||
log.finish();
|
||||
console.log(err)
|
||||
})
|
@ -17,12 +17,13 @@ const { savePrData, ProcessingLog } = require('../utils');
|
||||
|
||||
octokit.authenticate(octokitAuth);
|
||||
|
||||
const log = new ProcessingLog();
|
||||
const log = new ProcessingLog('find-failures-script');
|
||||
|
||||
const errorsToFind = require(path.resolve(__dirname, '../input-files/failuresToFind.json'));
|
||||
|
||||
(async () => {
|
||||
const { firstPR, lastPR } = await getUserInput();
|
||||
log.setFirstLast({ firstPR, lastPR });
|
||||
const prPropsToGet = ['number', 'head'];
|
||||
const { openPRs } = await getPRs(firstPR, lastPR, prPropsToGet);
|
||||
|
||||
@ -32,15 +33,15 @@ const errorsToFind = require(path.resolve(__dirname, '../input-files/failuresToF
|
||||
console.log('Starting error finding process...');
|
||||
for (let count in openPRs) {
|
||||
let { number, head: { sha: ref } } = openPRs[count];
|
||||
log.add(number, 'error');
|
||||
const { data: statuses } = await octokit.repos.getStatuses({ owner, repo, ref });
|
||||
const { data: statuses } = await octokit.repos.listStatusesForRef({ owner, repo, ref });
|
||||
|
||||
if (statuses.length) {
|
||||
const { state, target_url } = statuses[0]; // first element contain most recent status
|
||||
const hasProblem = state === 'failure' || state === 'error';
|
||||
if (hasProblem) {
|
||||
let buildNum = Number(target_url.match(/\/builds\/(\d+)\?/i)[1]);'
|
||||
const logNumber = 'need to use Travis api to access the full log for the buildNum above'
|
||||
let buildNum = Number(target_url.match(/\/builds\/(\d+)\?/i)[1]);
|
||||
//const logNumber = 'need to use Travis api to access the full log for the buildNum above'
|
||||
const logNumber = ++buildNum;
|
||||
const travisLogUrl = `https://api.travis-ci.org/v3/job/${logNumber}/log.txt`;
|
||||
const response = await fetch(travisLogUrl)
|
||||
const logText = await response.text();
|
||||
@ -54,8 +55,8 @@ const errorsToFind = require(path.resolve(__dirname, '../input-files/failuresToF
|
||||
break;
|
||||
}
|
||||
}
|
||||
const errorDesc = error ? error : 'unkown error';
|
||||
log.update(number, 'error', { errorDesc, buildLog: travisLogUrl });
|
||||
const errorDesc = error ? error : 'unknown error';
|
||||
log.add(number, { errorDesc, buildLog: travisLogUrl });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,7 +64,7 @@ const errorsToFind = require(path.resolve(__dirname, '../input-files/failuresToF
|
||||
})()
|
||||
.then(() => {
|
||||
log.finish();
|
||||
console.log('Successfully finding all specified errors.');
|
||||
console.log('Successfully finished finding all specified errors.');
|
||||
})
|
||||
.catch(err => {
|
||||
log.finish();
|
||||
|
@ -2,14 +2,13 @@ require('dotenv').config();
|
||||
|
||||
const { owner, repo, octokitConfig, octokitAuth } = require('../constants');
|
||||
const octokit = require('@octokit/rest')(octokitConfig);
|
||||
|
||||
octokit.authenticate(octokitAuth);
|
||||
|
||||
const addComment = async (number, comment) => {
|
||||
const result = await octokit.issues.createComment({ owner, repo, number, body: comment })
|
||||
.catch((err) => {
|
||||
console.log(`PR #${number} had an error when trying to add a comment\n`);
|
||||
console.log(err)
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
if (result) {
|
||||
|
@ -1,22 +1,26 @@
|
||||
require('dotenv').config();
|
||||
|
||||
const { addComment } = require('./add-comment');
|
||||
const { rateLimiter } = require('../utils');
|
||||
const { owner, repo, octokitConfig, octokitAuth } = require('../constants');
|
||||
const octokit = require('@octokit/rest')(octokitConfig);
|
||||
|
||||
const octokit = require('@octokit/rest')(octokitConfig);
|
||||
octokit.authenticate(octokitAuth);
|
||||
|
||||
/* closes and reopens an open PR with applicable comment */
|
||||
const prOpenClose = async (number) => {
|
||||
const closeOpen = async (number) => {
|
||||
const result = await octokit.pullRequests.update({ owner, repo , number, state: 'closed', base: 'master' })
|
||||
.then(() => {
|
||||
.then(async () => {
|
||||
await rateLimiter(2000);
|
||||
return octokit.pullRequests.update({ owner, repo , number, state: 'open', base: 'master' })
|
||||
})
|
||||
.then(() => {
|
||||
addComment(number, 'Closed and Reopened this PR to attempt to resolve a specific Travis build failure.');
|
||||
.then(async () => {
|
||||
await rateLimiter(1000);
|
||||
await addComment(number, 'Closed and Reopened this PR to attempt to resolve a specific Travis build failure.');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
};
|
||||
|
||||
module.exports = prOpenClose;
|
||||
module.exports = { closeOpen };
|
||||
|
@ -2,7 +2,6 @@ const fs = require('fs');
|
||||
|
||||
const openJSONFile = fileName => {
|
||||
const data = JSON.parse(fs.readFileSync(fileName, 'utf8'));
|
||||
console.log('Opened JSON file')
|
||||
return data;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user