2 Commits

Author SHA1 Message Date
ced41f4a49 feat: add retest comment, delete it 2018-10-18 16:31:28 -07:00
c117cb847d feat: process 2 pages of events 2018-10-18 16:30:21 -07:00
3 changed files with 44 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ 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 { createComment, deleteComment } from './lib/comments.mjs';
import History from './lib/history.mjs';
// load env vars from .env file
@@ -12,7 +13,13 @@ dotenv.config();
export default async function() {
// parse repo name from cli and create repo instance
const repo = createRepo(process.argv.splice(2)[0]);
const { COMMENT_BODY_REGEXP, COMMENT_BODY_REGEXP_FLAGS, COMMENT_ACTOR } = process.env;
const {
COMMENT_BODY_REGEXP,
COMMENT_BODY_REGEXP_FLAGS,
COMMENT_ACTOR,
PULL_LABEL_FILTER,
PULL_RETEST_BODY,
} = process.env;
// load the history module
const history = new History();
@@ -23,11 +30,14 @@ export default async function() {
actor: COMMENT_ACTOR,
})).filter(comment => !history.get(comment.id));
// read pull data, filter out any closed pulls
// read pull data
const pulls = (await Promise.all(
comments.map(async comment => {
const pull = await getPull(repo, comment.number);
if (pull.state !== 'open') return false;
if (pull.state !== 'open') return false; // filter out any closed pulls
if (PULL_LABEL_FILTER && !pull.labels.includes(PULL_LABEL_FILTER)) return false; // filter on label
return { comment, pull };
})
)).filter(Boolean);
@@ -43,8 +53,15 @@ export default async function() {
})
)).filter(Boolean);
console.log(records);
process.exit();
console.log(`Found ${records.length} outstanding failures`);
await Promise.all(
records.map(async record => {
console.log(`Re-testing PR #${record.pull.number}`);
const comment = await createComment(repo, records[0].pull.number, PULL_RETEST_BODY);
await deleteComment(repo, comment.id);
})
);
/*
@@ -52,12 +69,12 @@ export default async function() {
- [x] 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
- [x] add a retest comment
- POST /repos/:owner/:repo/issues/:number/comments
- [x] delete the retest comment
- [ ] delete the build comment
- DELETE /repos/:owner/:repo/issues/comments/:comment_id
- [ ] delete ALL build failure comments
- [ ] delete the retest comment
- DELETE /repos/:owner/:repo/issues/comments/:comment_id
*/
}

7
src/lib/comments.mjs Normal file
View File

@@ -0,0 +1,7 @@
export async function createComment(repo, issueId, body) {
return repo.issues(issueId).comments.create({ body });
}
export async function deleteComment(repo, commentId) {
return repo.issues.comments(commentId).remove();
}

View File

@@ -1,7 +1,17 @@
export default async function getEvents(repo, { body, actor } = {}) {
const { items: events } = await repo.events.fetch();
const events = await repo.events.fetch();
return events
const items = await (async () => {
// process 2 pages of events
if (events.nextPage) {
const moreEvents = await events.nextPage.fetch();
return [...events.items, ...moreEvents.items];
}
return events.items;
})();
return items
.map(comment => {
// only comments created by specific user
if (comment.type !== 'IssueCommentEvent') return false;