Skip to content

Commit 4a4cf4f

Browse files
authored
Populate link back to workflow that set next steps to merge (#36606)
* ensure that we populate a link back to the workflow that updated the comment * formatting application
1 parent 5e2f777 commit 4a4cf4f

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

.github/workflows/src/summarize-checks/summarize-checks.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ export async function summarizeChecksImpl(
441441
requiredCheckRuns,
442442
fyiCheckRuns,
443443
impactAssessment !== undefined,
444+
target_url,
444445
);
445446

446447
automatedChecksMet.target_url = target_url;
@@ -872,6 +873,7 @@ export function getCheckInfo(checkName) {
872873
* @param {CheckRunData[]} requiredRuns
873874
* @param {CheckRunData[]} fyiRuns
874875
* @param {boolean} assessmentCompleted
876+
* @param {string} target_url
875877
* @returns {Promise<[string, CheckRunResult]>}
876878
*/
877879
export async function createNextStepsComment(
@@ -882,6 +884,7 @@ export async function createNextStepsComment(
882884
requiredRuns,
883885
fyiRuns,
884886
assessmentCompleted,
887+
target_url,
885888
) {
886889
// select just the metadata that we need about the runs.
887890
const failingCheckInfos = requiredRuns
@@ -910,6 +913,7 @@ export async function createNextStepsComment(
910913
failingCheckInfos,
911914
fyiCheckInfos,
912915
assessmentCompleted,
916+
target_url,
913917
);
914918

915919
return [commentBody, automatedChecksMet];
@@ -923,6 +927,7 @@ export async function createNextStepsComment(
923927
* @param {CheckMetadata[]} failingReqChecksInfo
924928
* @param {CheckMetadata[]} failingFyiChecksInfo
925929
* @param {boolean} assessmentCompleted
930+
* @param {string} target_url
926931
* @returns {Promise<[string, CheckRunResult]>}
927932
*/
928933
async function buildNextStepsToMergeCommentBody(
@@ -933,6 +938,7 @@ async function buildNextStepsToMergeCommentBody(
933938
failingReqChecksInfo,
934939
failingFyiChecksInfo,
935940
assessmentCompleted,
941+
target_url,
936942
) {
937943
// Build the comment header
938944
const commentTitle = `<h2>Next Steps to Merge</h2>`;
@@ -958,6 +964,7 @@ async function buildNextStepsToMergeCommentBody(
958964
failingReqChecksInfo,
959965
failingFyiChecksInfo,
960966
violatedReqLabelsRules,
967+
target_url,
961968
);
962969

963970
return [commentTitle + commentBody, automatedChecksMet];
@@ -971,6 +978,7 @@ async function buildNextStepsToMergeCommentBody(
971978
* @param {CheckMetadata[]} failingReqChecksInfo - Failing required checks info
972979
* @param {CheckMetadata[]} failingFyiChecksInfo - Failing FYI checks info
973980
* @param {RequiredLabelRule[]} violatedRequiredLabelsRules - Violated required label rules
981+
* @param {string} target_url - The target URL for the automated checks met run which will be set at the outset of summarize-checks
974982
* @returns {[string, CheckRunResult]} The body content HTML and the CheckRunResult that automated checks met should be set to.
975983
*/
976984
function getCommentBody(
@@ -980,6 +988,7 @@ function getCommentBody(
980988
failingReqChecksInfo,
981989
failingFyiChecksInfo,
982990
violatedRequiredLabelsRules,
991+
target_url,
983992
) {
984993
/** @type {"pending" | keyof typeof CheckConclusion} */
985994
let status = "pending";
@@ -1029,6 +1038,8 @@ function getCommentBody(
10291038
// dont need to update the status of the check, as pending is the default state.
10301039
}
10311040

1041+
bodyProper += `<br /><br />Comment generated by <a href="${target_url}">summarize-checks</a> workflow run.`;
1042+
10321043
/** @type {CheckRunResult} */
10331044
const automatedChecksMet = {
10341045
name: AUTOMATED_CHECK_NAME,

.github/workflows/test/summarize-checks/summarize-checks.test.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { createMockCore } from "../mocks.js";
1111

1212
const mockCore = createMockCore();
13+
const WORKFLOW_URL = "http://github.com/a/fake/workflowrun/url";
1314

1415
/**
1516
* Find and extract the "Next Steps to Merge" existing comment on a PR.
@@ -40,9 +41,9 @@ describe("Summarize Checks Integration Tests", () => {
4041
it.skipIf(!process.env.GITHUB_TOKEN || !process.env.INTEGRATION_TEST)(
4142
"Should fetch real pr data and check the next steps to merge and final labels against what is actually there.",
4243
async () => {
43-
const issue_number = 36258;
44+
const issue_number = 24021;
4445
const owner = "Azure";
45-
const repo = "azure-rest-api-specs";
46+
const repo = "azure-rest-api-specs-pr";
4647

4748
const ignorableLabels = [
4849
"VersioningReviewRequired",
@@ -71,7 +72,7 @@ describe("Summarize Checks Integration Tests", () => {
7172
issue_number,
7273
);
7374

74-
const head_sha = pr.head.sha;
75+
const head_sha = "961faf0dd048e0b846026bc84fdd795f4b46e9e8";
7576
const expectedLabels = await getExistingLabels(github, owner, repo, issue_number);
7677

7778
const [requiredCheckRuns, fyiCheckRuns, impactAssessment] = await getCheckRunTuple(
@@ -104,6 +105,7 @@ describe("Summarize Checks Integration Tests", () => {
104105
requiredCheckRuns,
105106
fyiCheckRuns,
106107
impactAssessment !== undefined,
108+
WORKFLOW_URL,
107109
);
108110

109111
const actualLabels = [...labelContext.toAdd, ...labelContext.present];
@@ -125,7 +127,7 @@ describe("Summarize Checks Unit Tests", () => {
125127
const fyiCheckRuns = [];
126128
const requiredCheckRuns = [];
127129
const expectedOutput = [
128-
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.',
130+
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.',
129131
{
130132
name: "[TEST-IGNORE] Automated merging requirements met",
131133
result: "SUCCESS",
@@ -141,6 +143,7 @@ describe("Summarize Checks Unit Tests", () => {
141143
requiredCheckRuns,
142144
fyiCheckRuns,
143145
true, // assessmentCompleted
146+
WORKFLOW_URL,
144147
);
145148

146149
expect(output).toEqual(expectedOutput);
@@ -152,7 +155,7 @@ describe("Summarize Checks Unit Tests", () => {
152155
const labelNames = [];
153156
const fyiCheckRuns = [];
154157
const expectedOutput = [
155-
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.',
158+
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.',
156159
{
157160
name: "[TEST-IGNORE] Automated merging requirements met",
158161
result: "SUCCESS",
@@ -249,6 +252,7 @@ describe("Summarize Checks Unit Tests", () => {
249252
requiredCheckRuns,
250253
fyiCheckRuns,
251254
true, // assessmentCompleted
255+
WORKFLOW_URL,
252256
);
253257

254258
expect(output).toEqual(expectedOutput);
@@ -259,7 +263,7 @@ describe("Summarize Checks Unit Tests", () => {
259263
const targetBranch = "main";
260264
const labelNames = [];
261265
const expectedOutput = [
262-
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.',
266+
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.',
263267
{
264268
name: "[TEST-IGNORE] Automated merging requirements met",
265269
result: "SUCCESS",
@@ -317,6 +321,7 @@ describe("Summarize Checks Unit Tests", () => {
317321
requiredCheckRuns,
318322
fyiCheckRuns,
319323
true, // assessmentCompleted
324+
WORKFLOW_URL,
320325
);
321326

322327
expect(output).toEqual(expectedOutput);
@@ -330,7 +335,7 @@ describe("Summarize Checks Unit Tests", () => {
330335
const targetBranch = "main";
331336
const labelNames = [];
332337
const expectedOutput = [
333-
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.',
338+
'<h2>Next Steps to Merge</h2>✅ All automated merging requirements have been met! To get your PR merged, see <a href="https://aka.ms/azsdk/specreview/merge">aka.ms/azsdk/specreview/merge</a>.<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.',
334339
{
335340
name: "[TEST-IGNORE] Automated merging requirements met",
336341
result: "SUCCESS",
@@ -375,6 +380,7 @@ describe("Summarize Checks Unit Tests", () => {
375380
requiredCheckRuns,
376381
fyiCheckRuns,
377382
true, // assessmentCompleted
383+
WORKFLOW_URL,
378384
);
379385

380386
expect(output).toEqual(expectedOutput);
@@ -385,7 +391,7 @@ describe("Summarize Checks Unit Tests", () => {
385391
const targetBranch = "main";
386392
const labelNames = [];
387393
const expectedOutput = [
388-
`<h2>Next Steps to Merge</h2>Important checks have failed. As of today they are not blocking this PR, but in near future they may.<br/>Addressing the following failures is highly recommended:<br/><ul><li>⚠️ The check named <code>license/cla</code> has failed. Refer to the check in the PR's 'Checks' tab for details on how to fix it and consult the <a href="https://aka.ms/ci-fix">aka.ms/ci-fix</a> guide</li></ul>If you still want to proceed merging this PR without addressing the above failures, refer to step 4 in the <a href="https://aka.ms/azsdk/pr-diagram">PR workflow diagram</a>.`,
394+
`<h2>Next Steps to Merge</h2>Important checks have failed. As of today they are not blocking this PR, but in near future they may.<br/>Addressing the following failures is highly recommended:<br/><ul><li>⚠️ The check named <code>license/cla</code> has failed. Refer to the check in the PR's 'Checks' tab for details on how to fix it and consult the <a href="https://aka.ms/ci-fix">aka.ms/ci-fix</a> guide</li></ul>If you still want to proceed merging this PR without addressing the above failures, refer to step 4 in the <a href="https://aka.ms/azsdk/pr-diagram">PR workflow diagram</a>.<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.`,
389395
{
390396
name: "[TEST-IGNORE] Automated merging requirements met",
391397
result: "SUCCESS",
@@ -418,6 +424,7 @@ describe("Summarize Checks Unit Tests", () => {
418424
requiredCheckRuns,
419425
fyiCheckRuns,
420426
true, // assessmentCompleted
427+
WORKFLOW_URL,
421428
);
422429

423430
expect(output).toEqual(expectedOutput);
@@ -429,7 +436,7 @@ describe("Summarize Checks Unit Tests", () => {
429436
const labelNames = [];
430437
const fyiCheckRuns = [];
431438
const expectedOutput = [
432-
"<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛",
439+
`<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.`,
433440
{
434441
name: "[TEST-IGNORE] Automated merging requirements met",
435442
result: "pending",
@@ -466,6 +473,7 @@ describe("Summarize Checks Unit Tests", () => {
466473
requiredCheckRuns,
467474
fyiCheckRuns,
468475
true, // assessmentCompleted
476+
WORKFLOW_URL,
469477
);
470478

471479
expect(output).toEqual(expectedOutput);
@@ -477,7 +485,7 @@ describe("Summarize Checks Unit Tests", () => {
477485
const labelNames = [];
478486
const fyiCheckRuns = [];
479487
const expectedOutput = [
480-
"<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛",
488+
`<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.`,
481489
{
482490
name: "[TEST-IGNORE] Automated merging requirements met",
483491
result: "pending",
@@ -514,6 +522,7 @@ describe("Summarize Checks Unit Tests", () => {
514522
requiredCheckRuns,
515523
fyiCheckRuns,
516524
true, // assessmentCompleted
525+
WORKFLOW_URL,
517526
);
518527

519528
expect(output).toEqual(expectedOutput);
@@ -525,7 +534,7 @@ describe("Summarize Checks Unit Tests", () => {
525534
const labelNames = [];
526535
const fyiCheckRuns = [];
527536
const expectedOutput = [
528-
"<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛",
537+
`<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛<br /><br />Comment generated by <a href="${WORKFLOW_URL}">summarize-checks</a> workflow run.`,
529538
{
530539
name: "[TEST-IGNORE] Automated merging requirements met",
531540
result: "pending",
@@ -622,6 +631,7 @@ describe("Summarize Checks Unit Tests", () => {
622631
requiredCheckRuns,
623632
fyiCheckRuns,
624633
false, // assessmentCompleted
634+
WORKFLOW_URL,
625635
);
626636

627637
expect(output).toEqual(expectedOutput);
@@ -633,7 +643,7 @@ describe("Summarize Checks Unit Tests", () => {
633643
const labelNames = [];
634644
const fyiCheckRuns = [];
635645
const expectedOutput = [
636-
"<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛",
646+
`<h2>Next Steps to Merge</h2>⌛ Please wait. Next steps to merge this PR are being evaluated by automation. ⌛<br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.`,
637647
{
638648
name: "[TEST-IGNORE] Automated merging requirements met",
639649
result: "pending",
@@ -688,6 +698,7 @@ describe("Summarize Checks Unit Tests", () => {
688698
requiredCheckRuns,
689699
fyiCheckRuns,
690700
true, // assessmentCompleted
701+
WORKFLOW_URL,
691702
);
692703

693704
expect(output).toEqual(expectedOutput);
@@ -716,7 +727,7 @@ describe("Summarize Checks Unit Tests", () => {
716727
"<li>❌ This PR has at least one change violating Azure versioning policy (label: <code>VersioningReviewRequired</code>).<br/>To unblock this PR, either a) " +
717728
'introduce a new API version with these changes instead of modifying an existing API version, or b) follow the process at <a href="https://aka.ms/brch">aka.ms/brch</a>.' +
718729
"</li><li>❌ The required check named <code>TypeSpec Validation</code> has failed. Refer to the check in the PR's 'Checks' tab for details on how to fix it and consult " +
719-
'the <a href="https://aka.ms/ci-fix">aka.ms/ci-fix</a> guide</li></ul>';
730+
'the <a href="https://aka.ms/ci-fix">aka.ms/ci-fix</a> guide</li></ul><br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.';
720731
const expectedOutput = [
721732
expectedComment,
722733
{
@@ -816,6 +827,7 @@ describe("Summarize Checks Unit Tests", () => {
816827
requiredCheckRuns,
817828
fyiCheckRuns,
818829
true, // assessmentCompleted
830+
WORKFLOW_URL,
819831
);
820832

821833
expect(output).toEqual(expectedOutput);
@@ -831,7 +843,7 @@ describe("Summarize Checks Unit Tests", () => {
831843
summary:
832844
"❌ This PR cannot be merged because some requirements are not met. See the details.",
833845
};
834-
const expectedCommentOutput = `<h2>Next Steps to Merge</h2>Next steps that must be taken to merge this PR: <br/><ul><li>❌ The required check named <code>Swagger BreakingChange</code> has failed. To unblock this PR, follow the process at <a href="https://aka.ms/brch">aka.ms/brch</a>.</li></ul><br/>Important checks have failed. As of today they are not blocking this PR, but in near future they may.<br/>Addressing the following failures is highly recommended:<br/><ul><li>⚠️ The check named <code>TypeSpec Validation</code> has failed. Refer to the check in the PR's 'Checks' tab for details on how to fix it and consult the <a href="https://aka.ms/ci-fix">aka.ms/ci-fix</a> guide</li></ul>`;
846+
const expectedCommentOutput = `<h2>Next Steps to Merge</h2>Next steps that must be taken to merge this PR: <br/><ul><li>❌ The required check named <code>Swagger BreakingChange</code> has failed. To unblock this PR, follow the process at <a href="https://aka.ms/brch">aka.ms/brch</a>.</li></ul><br/>Important checks have failed. As of today they are not blocking this PR, but in near future they may.<br/>Addressing the following failures is highly recommended:<br/><ul><li>⚠️ The check named <code>TypeSpec Validation</code> has failed. Refer to the check in the PR's 'Checks' tab for details on how to fix it and consult the <a href="https://aka.ms/ci-fix">aka.ms/ci-fix</a> guide</li></ul><br /><br />Comment generated by <a href="http://github.com/a/fake/workflowrun/url">summarize-checks</a> workflow run.`;
835847

836848
const fyiCheckRuns = [
837849
{
@@ -859,6 +871,7 @@ describe("Summarize Checks Unit Tests", () => {
859871
requiredCheckRuns,
860872
fyiCheckRuns,
861873
true, // assessmentCompleted
874+
WORKFLOW_URL,
862875
);
863876

864877
expect(automatedCheckOutput).toEqual(expectedCheckOutput);

0 commit comments

Comments
 (0)