Skip to content

Commit

Permalink
v5.2 (#7)
Browse files Browse the repository at this point in the history
* Neater comment format
* Mention the modified paths
* Ignore 403 errors
  • Loading branch information
carmocca authored Nov 26, 2022
1 parent bcf2d88 commit b71e37c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ default_permissions:

# Organization members and teams.
# https://developer.github.com/v3/apps/permissions/#permission-on-members
members: read
# members: read

# View and manage users blocked by the organization.
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-user-blocking
Expand Down
22 changes: 11 additions & 11 deletions dist/check-group/core/generate_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var generateProgressDetailsCLI = function (subprojects, postedChecks) {
};
exports.generateProgressDetailsCLI = generateProgressDetailsCLI;
var generateProgressDetailsMarkdown = function (subprojects, postedChecks) {
var progress = "## Groups summary\n";
var progress = "## Groups summary\n\n";
subprojects.forEach(function (subproject) {
// get the aggregated status of all statuses in the subproject
var checkResult = (0, satisfy_expected_checks_1.getChecksResult)(subproject.checks, postedChecks);
Expand All @@ -127,6 +127,7 @@ var generateProgressDetailsMarkdown = function (subprojects, postedChecks) {
var mark = statusToMark(check, postedChecks);
progress += "| ".concat(link, " | ").concat(status, " | ").concat(mark, " |\n");
});
progress += "\nThese checks are required after the changes to `".concat(subproject.paths.join("`, `"), "`.\n");
progress += "\n</details>\n\n";
});
return progress;
Expand All @@ -140,19 +141,18 @@ function formPrComment(result, inputs, subprojects, postedChecks) {
var hasFailed = result === "has_failure";
var conclusionEmoji = (result === "all_passing") ? "🟢" : (hasFailed) ? "🔴" : "🟡";
var lightning = (result === "all_passing") ? "⚡" : (hasFailed) ? "⛈️" : "🌩️";
var failedMesage = ("\n**\u26A0\uFE0F This job will need to be re-run to merge your PR."
+ " If you do not have write access to the repository you can ask `".concat(inputs.maintainers, "` to re-run it for you.")
+ " If you push a new commit, all of CI will re-trigger ⚠️**"
+ " If you have any other questions, you can reach out to `".concat(inputs.owner, "` for help."));
var failedMesage = ("> **Warning**\n> This job will need to be re-run to merge your PR."
+ " If you do not have write access to the repository, you can ask `".concat(inputs.maintainers, "` to re-run it.")
+ " If you push a new commit, all of CI will re-trigger.\n\n");
var progressDetails = (0, exports.generateProgressDetailsMarkdown)(subprojects, postedChecks);
return (PR_COMMENT_START
+ "\n# ".concat(lightning, " Required checks status: ").concat(parsedConclusion, " ").concat(conclusionEmoji)
+ "\n# ".concat(lightning, " Required checks status: ").concat(parsedConclusion, " ").concat(conclusionEmoji, "\n\n")
+ ((hasFailed) ? failedMesage : "")
+ ((subprojects.length) ? "\n".concat(progressDetails) : "\nNo groups match the files changed in this PR.")
+ "\n\n---"
+ "\nThis comment was automatically generated and updates for ".concat(inputs.timeout, " minutes ")
+ "every ".concat(inputs.interval, " seconds.")
+ "\n\nThank you for your contribution! 💜");
+ ((subprojects.length) ? progressDetails : "No groups match the files changed in this PR.\n\n")
+ "---\n\n"
+ "Thank you for your contribution! 💜\n\n"
+ "> **Note**\n> This comment is automatically generated and updates for ".concat(inputs.timeout, " minutes every ").concat(inputs.interval, " seconds.")
+ " If you have any other questions, contact `".concat(inputs.owner, "` for help."));
}
function getPrComment(context) {
return __awaiter(this, void 0, void 0, function () {
Expand Down
30 changes: 25 additions & 5 deletions dist/check-group/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var subproj_matching_1 = require("./subproj_matching");
var satisfy_expected_checks_1 = require("./satisfy_expected_checks");
var config_getter_1 = require("./config_getter");
Object.defineProperty(exports, "fetchConfig", { enumerable: true, get: function () { return config_getter_1.fetchConfig; } });
var request_error_1 = require("@octokit/request-error");
/**
* The orchestration class.
*/
Expand Down Expand Up @@ -162,12 +163,31 @@ var CheckGroup = /** @class */ (function () {
};
CheckGroup.prototype.notifyProgress = function (subprojs, postedChecks, result) {
return __awaiter(this, void 0, void 0, function () {
var details;
var details, e_1;
return __generator(this, function (_a) {
details = (0, generate_progress_1.generateProgressDetailsCLI)(subprojs, postedChecks);
core.info("".concat(this.config.customServiceName, " result: '").concat(result, "':\n").concat(details));
(0, generate_progress_1.commentOnPr)(this.context, result, this.inputs, subprojs, postedChecks);
return [2 /*return*/];
switch (_a.label) {
case 0:
details = (0, generate_progress_1.generateProgressDetailsCLI)(subprojs, postedChecks);
core.info("".concat(this.config.customServiceName, " result: '").concat(result, "':\n").concat(details));
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, generate_progress_1.commentOnPr)(this.context, result, this.inputs, subprojs, postedChecks)];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
if (e_1 instanceof request_error_1.RequestError && e_1.status === 403) {
// Forbidden: Resource not accessible by integration
core.info("Failed to comment on the PR: ".concat(JSON.stringify(e_1)));
}
else {
throw e_1;
}
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
};
Expand Down
22 changes: 11 additions & 11 deletions src/check-group/core/generate_progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const generateProgressDetailsMarkdown = (
subprojects: SubProjConfig[],
postedChecks: Record<string, CheckRunData>,
): string => {
let progress = "## Groups summary\n";
let progress = "## Groups summary\n\n";
subprojects.forEach((subproject) => {
// get the aggregated status of all statuses in the subproject
const checkResult = getChecksResult(subproject.checks, postedChecks)
Expand All @@ -110,6 +110,7 @@ export const generateProgressDetailsMarkdown = (
const mark = statusToMark(check, postedChecks);
progress += `| ${link} | ${status} | ${mark} |\n`;
})
progress += `\nThese checks are required after the changes to \`${subproject.paths.join("`, `")}\`.\n`
progress += "\n</details>\n\n";
});
return progress;
Expand All @@ -130,21 +131,20 @@ function formPrComment(
const conclusionEmoji = (result === "all_passing") ? "🟢": (hasFailed) ? "🔴" : "🟡"
const lightning = (result === "all_passing") ? "⚡": (hasFailed) ? "⛈️" : "🌩️"
const failedMesage = (
`\n**⚠️ This job will need to be re-run to merge your PR.`
+ ` If you do not have write access to the repository you can ask \`${inputs.maintainers}\` to re-run it for you.`
+ " If you push a new commit, all of CI will re-trigger ⚠️**"
+ ` If you have any other questions, you can reach out to \`${inputs.owner}\` for help.`
`> **Warning**\n> This job will need to be re-run to merge your PR.`
+ ` If you do not have write access to the repository, you can ask \`${inputs.maintainers}\` to re-run it.`
+ " If you push a new commit, all of CI will re-trigger.\n\n"
)
const progressDetails = generateProgressDetailsMarkdown(subprojects, postedChecks)
return (
PR_COMMENT_START
+ `\n# ${lightning} Required checks status: ${parsedConclusion} ${conclusionEmoji}`
+ `\n# ${lightning} Required checks status: ${parsedConclusion} ${conclusionEmoji}\n\n`
+ ((hasFailed) ? failedMesage : "")
+ ((subprojects.length) ? `\n${progressDetails}` : "\nNo groups match the files changed in this PR.")
+ "\n\n---"
+ `\nThis comment was automatically generated and updates for ${inputs.timeout} minutes `
+ `every ${inputs.interval} seconds.`
+ "\n\nThank you for your contribution! 💜"
+ ((subprojects.length) ? progressDetails : "No groups match the files changed in this PR.\n\n")
+ "---\n\n"
+ "Thank you for your contribution! 💜\n\n"
+ `> **Note**\n> This comment is automatically generated and updates for ${inputs.timeout} minutes every ${inputs.interval} seconds.`
+ ` If you have any other questions, contact \`${inputs.owner}\` for help.`
)
}

Expand Down
12 changes: 11 additions & 1 deletion src/check-group/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getSubProjResult } from "./satisfy_expected_checks";
import { fetchConfig } from "./config_getter";
import type { CheckGroupConfig, CheckResult, SubProjConfig } from "../types";
import type { Context } from "probot";
import { RequestError } from "@octokit/request-error";

/**
* The orchestration class.
Expand Down Expand Up @@ -113,7 +114,16 @@ export class CheckGroup {
core.info(
`${this.config.customServiceName} result: '${result}':\n${details}`
)
commentOnPr(this.context, result, this.inputs, subprojs, postedChecks)
try {
await commentOnPr(this.context, result, this.inputs, subprojs, postedChecks)
} catch (e) {
if (e instanceof RequestError && e.status === 403) {
// Forbidden: Resource not accessible by integration
core.info(`Failed to comment on the PR: ${JSON.stringify(e)}`)
} else {
throw e
}
}
}

/**
Expand Down

0 comments on commit b71e37c

Please sign in to comment.