feat: add retest comment, delete it
This commit is contained in:
@@ -4,6 +4,7 @@ import getComments from './lib/get_comments.mjs';
|
|||||||
import getPull from './lib/get_pull.mjs';
|
import getPull from './lib/get_pull.mjs';
|
||||||
import getCommits from './lib/get_commits.mjs';
|
import getCommits from './lib/get_commits.mjs';
|
||||||
import getCommitStatus from './lib/get_commit_status.mjs';
|
import getCommitStatus from './lib/get_commit_status.mjs';
|
||||||
|
import { createComment, deleteComment } from './lib/comments.mjs';
|
||||||
import History from './lib/history.mjs';
|
import History from './lib/history.mjs';
|
||||||
|
|
||||||
// load env vars from .env file
|
// load env vars from .env file
|
||||||
@@ -12,7 +13,13 @@ dotenv.config();
|
|||||||
export default async function() {
|
export default async function() {
|
||||||
// parse repo name from cli and create repo instance
|
// parse repo name from cli and create repo instance
|
||||||
const repo = createRepo(process.argv.splice(2)[0]);
|
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
|
// load the history module
|
||||||
const history = new History();
|
const history = new History();
|
||||||
@@ -23,11 +30,14 @@ export default async function() {
|
|||||||
actor: COMMENT_ACTOR,
|
actor: COMMENT_ACTOR,
|
||||||
})).filter(comment => !history.get(comment.id));
|
})).filter(comment => !history.get(comment.id));
|
||||||
|
|
||||||
// read pull data, filter out any closed pulls
|
// read pull data
|
||||||
const pulls = (await Promise.all(
|
const pulls = (await Promise.all(
|
||||||
comments.map(async comment => {
|
comments.map(async comment => {
|
||||||
const pull = await getPull(repo, comment.number);
|
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 };
|
return { comment, pull };
|
||||||
})
|
})
|
||||||
)).filter(Boolean);
|
)).filter(Boolean);
|
||||||
@@ -43,8 +53,15 @@ export default async function() {
|
|||||||
})
|
})
|
||||||
)).filter(Boolean);
|
)).filter(Boolean);
|
||||||
|
|
||||||
console.log(records);
|
console.log(`Found ${records.length} outstanding failures`);
|
||||||
process.exit();
|
|
||||||
|
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] keep track of seen comment ids, only process new ones
|
||||||
- [x] check the pr's status and only retest if no longer "Pending"
|
- [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
|
- POST /repos/:owner/:repo/issues/:number/comments
|
||||||
|
- [x] delete the retest comment
|
||||||
- [ ] delete the build comment
|
- [ ] delete the build comment
|
||||||
- DELETE /repos/:owner/:repo/issues/comments/:comment_id
|
|
||||||
- [ ] delete ALL build failure comments
|
- [ ] delete ALL build failure comments
|
||||||
- [ ] delete the retest comment
|
- DELETE /repos/:owner/:repo/issues/comments/:comment_id
|
||||||
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/lib/comments.mjs
Normal file
7
src/lib/comments.mjs
Normal 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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user