Skip to content

Commit b71da9f

Browse files
committed
detect CI links in reviews
1 parent 3b8fd48 commit b71da9f

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

bin/metadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async function main(prid, owner, repo) {
5555
const metadata = new MetadataGenerator(repo, pr, reviewers).getMetadata();
5656
logger.info({ raw: metadata }, 'Generated metadata:');
5757

58-
const checker = new PRChecker(pr, reviewers, comments);
58+
const checker = new PRChecker(pr, reviewers, comments, reviews);
5959
checker.checkReviewers();
6060
checker.checkReviews();
6161
checker.checkPRWait();

lib/ci.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,23 @@ const CI_TYPES = new Map([
2424
]);
2525

2626
class CIParser {
27-
constructor(comments) {
28-
this.comments = comments;
27+
/**
28+
* @param {{bodyText: string, publishedAt: string}[]} thread
29+
*/
30+
constructor(thread) {
31+
this.thread = thread;
2932
}
3033

34+
/**
35+
* @returns {Map<string, {link: string, date: string}>}
36+
*/
3137
parse() {
32-
const comments = this.comments;
33-
/**
34-
* @type {Map<string, {link: string, date: string}>}
35-
*/
38+
const thread = this.thread;
3639
const result = new Map();
37-
for (const c of comments) {
38-
if (!c.bodyText.includes(CI_DOMAIN)) continue;
39-
const cis = this.parseText(c.bodyText);
40+
for (const c of thread) {
41+
const text = c.bodyText;
42+
if (!text.includes(CI_DOMAIN)) continue;
43+
const cis = this.parseText(text);
4044
for (const ci of cis) {
4145
const entry = result.get(ci.type);
4246
if (!entry || entry.date < c.publishedAt) {

lib/pr_checker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const CI_TYPES = CIParser.TYPES;
1717
const { FULL } = CIParser.constants;
1818

1919
class PRChecker {
20-
constructor(pr, reviewers, comments) {
20+
constructor(pr, reviewers, comments, reviews) {
2121
this.reviewers = reviewers;
2222
this.pr = pr;
2323
this.comments = comments;
24+
this.reviews = reviews;
2425
}
2526

2627
checkReviews() {
@@ -110,11 +111,13 @@ class PRChecker {
110111
// TODO: not all PR requires CI...labels?
111112
checkCI() {
112113
const comments = this.comments;
114+
const reviews = this.reviews;
113115
const prNode = {
114116
publishedAt: this.pr.createdAt,
115117
bodyText: this.pr.bodyText
116118
};
117-
const ciMap = new CIParser(comments.concat([prNode])).parse();
119+
const thread = comments.concat([prNode]).concat(reviews);
120+
const ciMap = new CIParser(thread).parse();
118121
if (!ciMap.size) {
119122
logger.warn('No CI runs detected');
120123
} else if (!ciMap.get(FULL)) {

queries/Reviews.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ query Reviews($prid: Int!, $owner: String!, $repo: String!, $after: String) {
88
endCursor
99
}
1010
nodes {
11+
bodyText
1112
state
1213
author {
1314
login

0 commit comments

Comments
 (0)