Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect CI links in reviews #15

Merged
merged 1 commit into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function main(prid, owner, repo) {
const metadata = new MetadataGenerator(repo, pr, reviewers).getMetadata();
logger.info({ raw: metadata }, 'Generated metadata:');

const checker = new PRChecker(pr, reviewers, comments);
const checker = new PRChecker(pr, reviewers, comments, reviews);
checker.checkReviewers();
checker.checkReviews();
checker.checkPRWait();
Expand Down
24 changes: 14 additions & 10 deletions lib/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@ const CI_TYPES = new Map([
]);

class CIParser {
constructor(comments) {
this.comments = comments;
/**
* @param {{bodyText: string, publishedAt: string}[]} thread
*/
constructor(thread) {
this.thread = thread;
}

/**
* @returns {Map<string, {link: string, date: string}>}
*/
parse() {
const comments = this.comments;
/**
* @type {Map<string, {link: string, date: string}>}
*/
const thread = this.thread;
const result = new Map();
for (const c of comments) {
if (!c.bodyText.includes(CI_DOMAIN)) continue;
const cis = this.parseText(c.bodyText);
for (const c of thread) {
const text = c.bodyText;
if (!text.includes(CI_DOMAIN)) continue;
const cis = this.parseText(text);
for (const ci of cis) {
const entry = result.get(ci.type);
if (!entry || entry.date < c.publishedAt) {
Expand All @@ -48,7 +52,7 @@ class CIParser {
}

/**
* @param {string} text
* @param {string} text
*/
parseText(text) {
const m = text.match(CI_RE);
Expand Down
7 changes: 5 additions & 2 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const CI_TYPES = CIParser.TYPES;
const { FULL } = CIParser.constants;

class PRChecker {
constructor(pr, reviewers, comments) {
constructor(pr, reviewers, comments, reviews) {
this.reviewers = reviewers;
this.pr = pr;
this.comments = comments;
this.reviews = reviews;
}

checkReviews() {
Expand Down Expand Up @@ -110,11 +111,13 @@ class PRChecker {
// TODO: not all PR requires CI...labels?
checkCI() {
const comments = this.comments;
const reviews = this.reviews;
const prNode = {
publishedAt: this.pr.createdAt,
bodyText: this.pr.bodyText
};
const ciMap = new CIParser(comments.concat([prNode])).parse();
const thread = comments.concat([prNode]).concat(reviews);
const ciMap = new CIParser(thread).parse();
if (!ciMap.size) {
logger.warn('No CI runs detected');
} else if (!ciMap.get(FULL)) {
Expand Down
13 changes: 6 additions & 7 deletions lib/reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ const FROM_COMMENT = 'comment';

class Review {
/**
*
* @param {string} state
* @param {string} state
* @param {string} date // ISO date string
* @param {string} ref
* @param {string} source
* @param {string} ref
* @param {string} source
*/
constructor(state, date, ref, source) {
this.state = state;
Expand All @@ -27,8 +26,8 @@ class Review {

class ReviewAnalyzer {
/**
* @param {{}[]} reviewes
* @param {{}[]} comments
* @param {{}[]} reviewes
* @param {{}[]} comments
* @param {Map<string, Collaborator>} collaborators
*/
constructor(reviews, comments, collaborators) {
Expand Down Expand Up @@ -78,7 +77,7 @@ class ReviewAnalyzer {

// TODO: count -1 ...? But they should just make it explicit
/**
* @param {Map<string, Review>} oldMap
* @param {Map<string, Review>} oldMap
* @returns {Map<string, Review>}
*/
updateMapByRawReviews(oldMap) {
Expand Down
1 change: 1 addition & 0 deletions queries/Reviews.gql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ query Reviews($prid: Int!, $owner: String!, $repo: String!, $after: String) {
endCursor
}
nodes {
bodyText
state
author {
login
Expand Down