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

v5.1 #6

Merged
merged 8 commits into from
Nov 22, 2022
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
25 changes: 13 additions & 12 deletions dist/check-group/core/generate_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.commentOnPr = exports.generateProgressDetailsMarkdown = exports.generateProgressDetailsCLI = void 0;
var satisfy_expected_checks_1 = require("./satisfy_expected_checks");
var statusToMark = function (check, postedChecks) {
if (check in postedChecks) {
if (postedChecks[check].conclusion === "success") {
Expand Down Expand Up @@ -106,26 +107,26 @@ exports.generateProgressDetailsCLI = generateProgressDetailsCLI;
var generateProgressDetailsMarkdown = function (subprojects, postedChecks) {
var progress = "## Groups summary\n";
subprojects.forEach(function (subproject) {
// create a map of the relevant checks with their status
var subprojectCheckStatus = {};
subproject.checks.forEach(function (check) {
var status = (check in postedChecks) ? postedChecks[check].conclusion : 'no_status';
subprojectCheckStatus[check] = status;
});
// get the aggregated status of all statuses in the subproject
var subprojectEmoji = Object.values(subprojectCheckStatus).every(function (v) { return v === "success"; }) ? "🟢" : "🔴";
var checkResult = (0, satisfy_expected_checks_1.getChecksResult)(subproject.checks, postedChecks);
var subprojectEmoji = "🟡";
if (checkResult === "all_passing") {
subprojectEmoji = "🟢";
}
else if (checkResult === "has_failure") {
subprojectEmoji = "🔴";
}
// generate the markdown table
progress += "<details>\n\n";
progress += "<summary><b>".concat(subprojectEmoji, " ").concat(subproject.id, "</b></summary>\n\n");
progress += "| Check ID | Status | |\n";
progress += "| -------- | ------ | --- |\n";
for (var _i = 0, _a = Object.entries(subprojectCheckStatus); _i < _a.length; _i++) {
var _b = _a[_i], check = _b[0], status_2 = _b[1];
subproject.checks.forEach(function (check) {
var link = statusToLink(check, postedChecks);
var status_3 = parseStatus(check, postedChecks);
var status = parseStatus(check, postedChecks);
var mark = statusToMark(check, postedChecks);
progress += "| ".concat(link, " | ").concat(status_3, " | ").concat(mark, " |\n");
}
progress += "| ".concat(link, " | ").concat(status, " | ").concat(mark, " |\n");
});
progress += "\n</details>\n\n";
});
return progress;
Expand Down
2 changes: 1 addition & 1 deletion dist/check-group/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var CheckGroup = /** @class */ (function () {
case 1:
postedChecks = _a.sent();
core.debug("postedChecks: ".concat(JSON.stringify(postedChecks)));
result = (0, satisfy_expected_checks_1.satisfyExpectedChecks)(subprojs, postedChecks);
result = (0, satisfy_expected_checks_1.getSubProjResult)(subprojs, postedChecks);
this.notifyProgress(subprojs, postedChecks, result);
core.endGroup();
if (result === "all_passing") {
Expand Down
80 changes: 47 additions & 33 deletions dist/check-group/core/satisfy_expected_checks.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.satisfyExpectedChecks = void 0;
/* eslint-enable @typescript-eslint/no-unused-vars */
/**
* Checks if all the sub-project requirements are satisfied.
*
* @param subProjs The sub-projects a certain pull request
* matches.
*
* @param checksStatusLookup The checks that has already
* posted progresses. The key is the check ID and the value
* is the current check status.
*
* @returns The current result of checks fulfillment.
* * "all_passing" means all required checks post
* success conclusion.
* * "has_failure" means at least one of the required
* checks failed.
* * "pending" means there is no failure but some
* checks are pending or missing.
*/
var satisfyExpectedChecks = function (subProjs, postedChecks) {
exports.getSubProjResult = exports.getChecksResult = void 0;
var getChecksResult = function (checks, postedChecks) {
var result = "all_passing";
subProjs.forEach(function (subProj) {
subProj.checks.forEach(function (check) {
if (check in postedChecks &&
postedChecks[check].conclusion !== "success" &&
postedChecks[check].conclusion !== null) {
result = "has_failure";
for (var _i = 0, checks_1 = checks; _i < checks_1.length; _i++) {
var check = checks_1[_i];
if (check in postedChecks) {
var conclusion = postedChecks[check].conclusion;
if (conclusion === null) {
// the check is in progress
result = "pending";
}
else if (conclusion !== "success") {
// the check already failed
return "has_failure";
}
}
else {
// the check is missing, hopefully queued
result = "pending";
}
}
;
return result;
};
exports.getChecksResult = getChecksResult;
var getSubProjResult = function (subProjs, postedChecks) {
var result = "all_passing";
for (var _i = 0, subProjs_1 = subProjs; _i < subProjs_1.length; _i++) {
var subProj = subProjs_1[_i];
for (var _a = 0, _b = subProj.checks; _a < _b.length; _a++) {
var check = _b[_a];
if (check in postedChecks) {
var conclusion = postedChecks[check].conclusion;
if (conclusion === null) {
// the check is in progress
result = "pending";
}
else if (conclusion !== "success") {
// the check already failed
return "has_failure";
}
}
if ((!(check in postedChecks) ||
postedChecks[check].conclusion === null) &&
result !== "has_failure") {
else {
// the check is missing, hopefully queued
result = "pending";
}
});
});
}
;
}
;
return result;
};
exports.satisfyExpectedChecks = satisfyExpectedChecks;
exports.getSubProjResult = getSubProjResult;
19 changes: 10 additions & 9 deletions src/check-group/core/generate_progress.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CheckResult, CheckRunData, SubProjConfig } from "../types";
import { Context } from "probot";
import { getChecksResult } from "./satisfy_expected_checks";


const statusToMark = (
Expand Down Expand Up @@ -90,25 +91,25 @@ export const generateProgressDetailsMarkdown = (
): string => {
let progress = "## Groups summary\n";
subprojects.forEach((subproject) => {
// create a map of the relevant checks with their status
let subprojectCheckStatus: Record<string, string> = {}
subproject.checks.forEach((check) => {
let status = (check in postedChecks) ? postedChecks[check].conclusion : 'no_status'
subprojectCheckStatus[check] = status
});
// get the aggregated status of all statuses in the subproject
const subprojectEmoji: string = Object.values(subprojectCheckStatus).every(v => v === "success") ? "🟢" : "🔴"
const checkResult = getChecksResult(subproject.checks, postedChecks)
let subprojectEmoji = "🟡";
if (checkResult === "all_passing") {
subprojectEmoji = "🟢";
} else if (checkResult === "has_failure") {
subprojectEmoji = "🔴";
}
// generate the markdown table
progress += "<details>\n\n"
progress += `<summary><b>${subprojectEmoji} ${subproject.id}</b></summary>\n\n`;
progress += "| Check ID | Status | |\n";
progress += "| -------- | ------ | --- |\n";
for (const [check, status] of Object.entries(subprojectCheckStatus)) {
subproject.checks.forEach((check) => {
const link = statusToLink(check, postedChecks);
const status = parseStatus(check, postedChecks);
const mark = statusToMark(check, postedChecks);
progress += `| ${link} | ${status} | ${mark} |\n`;
}
})
progress += "\n</details>\n\n";
});
return progress;
Expand Down
4 changes: 2 additions & 2 deletions src/check-group/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
} from "./generate_progress";
import { CheckRunData } from '../types';
import { matchFilenamesToSubprojects } from "./subproj_matching";
import { satisfyExpectedChecks } from "./satisfy_expected_checks";
import { getSubProjResult } from "./satisfy_expected_checks";
import { fetchConfig } from "./config_getter";
import type { CheckGroupConfig, CheckResult, SubProjConfig } from "../types";
import type { Context } from "probot";
Expand Down Expand Up @@ -84,7 +84,7 @@ export class CheckGroup {
core.startGroup(`Check ${tries}`);
const postedChecks = await getPostedChecks(this.context, this.sha);
core.debug(`postedChecks: ${JSON.stringify(postedChecks)}`);
const result = satisfyExpectedChecks(subprojs, postedChecks);
const result = getSubProjResult(subprojs, postedChecks);
this.notifyProgress(subprojs, postedChecks, result)
core.endGroup();

Expand Down
76 changes: 39 additions & 37 deletions src/check-group/core/satisfy_expected_checks.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { CheckResult, CheckRunData, SubProjConfig } from "../types";
/* eslint-enable @typescript-eslint/no-unused-vars */

/**
* Checks if all the sub-project requirements are satisfied.
*
* @param subProjs The sub-projects a certain pull request
* matches.
*
* @param checksStatusLookup The checks that has already
* posted progresses. The key is the check ID and the value
* is the current check status.
*
* @returns The current result of checks fulfillment.
* * "all_passing" means all required checks post
* success conclusion.
* * "has_failure" means at least one of the required
* checks failed.
* * "pending" means there is no failure but some
* checks are pending or missing.
*/
export const satisfyExpectedChecks = (
subProjs: SubProjConfig[],
export const getChecksResult = (
checks: string[],
postedChecks: Record<string, CheckRunData>,
): CheckResult => {
let result: CheckResult = "all_passing";
subProjs.forEach((subProj) => {
subProj.checks.forEach((check) => {
if (
check in postedChecks &&
postedChecks[check].conclusion !== "success" &&
postedChecks[check].conclusion !== null
) {
result = "has_failure";
for (const check of checks) {
if (check in postedChecks) {
const conclusion = postedChecks[check].conclusion;
if (conclusion === null) {
// the check is in progress
result = "pending";
} else if (conclusion !== "success") {
// the check already failed
return "has_failure";
}
if (
(!(check in postedChecks) ||
postedChecks[check].conclusion === null) &&
result !== "has_failure"
) {
} else {
// the check is missing, hopefully queued
result = "pending";
}
};
return result;
}

export const getSubProjResult = (
subProjs: SubProjConfig[],
postedChecks: Record<string, CheckRunData>,
): CheckResult => {
let result: CheckResult = "all_passing";
for (const subProj of subProjs) {
for (const check of subProj.checks) {
if (check in postedChecks) {
const conclusion = postedChecks[check].conclusion;
if (conclusion === null) {
// the check is in progress
result = "pending";
} else if (conclusion !== "success") {
// the check already failed
return "has_failure";
}
} else {
// the check is missing, hopefully queued
result = "pending";
}
});
});
};
};
return result;
};