80 lines
2.3 KiB
JavaScript
80 lines
2.3 KiB
JavaScript
import createRepo from './lib/create_repo.mjs';
|
|
import getComments from './lib/get_comments.mjs';
|
|
import getPull from './lib/get_pull.mjs';
|
|
import getCommits from './lib/get_commits.mjs';
|
|
import getCommitStatus from './lib/get_commit_status.mjs';
|
|
import History from './lib/history.mjs';
|
|
|
|
export default async function() {
|
|
// parse repo name from cli and create repo instance
|
|
const repo = createRepo(process.argv.splice(2)[0]);
|
|
|
|
// load the history module
|
|
const history = new History();
|
|
|
|
// fetch comment info from event stream, filter for only new comments
|
|
const comments = (await getComments(repo, {
|
|
body: /build failed/i,
|
|
actor: 'elasticmachine',
|
|
})).filter(comment => true /*!history.get(comment.id)*/);
|
|
|
|
console.log(
|
|
comments
|
|
.map(comment => {
|
|
history.add(comment); // temp
|
|
return comment.number;
|
|
})
|
|
.join(',')
|
|
);
|
|
|
|
// read pull data, filter out any closed pulls
|
|
const pulls = (await Promise.all(
|
|
comments.map(async comment => {
|
|
const pull = await getPull(repo, comment.number);
|
|
if (pull.state !== 'open') return false;
|
|
return { comment, pull };
|
|
})
|
|
)).filter(Boolean);
|
|
|
|
const commits = await Promise.all(pulls.map(pull => getCommits(repo, pull.number, true)));
|
|
|
|
const buildStatus = await getCommitStatus(repo, commits[1].sha);
|
|
|
|
console.log(buildStatus);
|
|
process.exit();
|
|
|
|
Promise.resolve()
|
|
|
|
.then(commit =>
|
|
// get the status of the commit
|
|
repo.commits(commit.sha).statuses.fetch()
|
|
)
|
|
.then(statuses => {
|
|
if (statuses.lastPage) return statuses.lastPage.fetch();
|
|
return statuses;
|
|
})
|
|
.then(({ items }) => {
|
|
const buildStatus = items.find(item => item.context === 'kibana-ci');
|
|
// status will be one of: error, failure, pending, success
|
|
// we should skip the retest if the state is pending or success
|
|
console.log(`PR state: ${buildStatus.state}`);
|
|
return buildStatus;
|
|
})
|
|
.catch(err => console.error(err));
|
|
|
|
/*
|
|
|
|
TODO:
|
|
|
|
- [ ] keep track of seen comment ids, only process new ones
|
|
- [x] check the pr's status and only retest if no longer "Pending"
|
|
- [ ] add a retest comment
|
|
- POST /repos/:owner/:repo/issues/:number/comments
|
|
- [ ] delete the build comment
|
|
- DELETE /repos/:owner/:repo/issues/comments/:comment_id
|
|
- [ ] delete ALL build failure comments
|
|
- [ ] delete the retest comment
|
|
|
|
*/
|
|
}
|