Skip to content

Commit 8eb7054

Browse files
authored
Fix broken documentation link in issue footer (#10075)
1 parent b149d67 commit 8eb7054

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

actions/setup/js/generate_footer.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22
/// <reference types="@actions/github-script" />
33

4+
const fs = require("fs");
45
const { getMissingInfoSections } = require("./missing_messages_helper.cjs");
56

67
/**
@@ -80,7 +81,12 @@ function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL,
8081
}
8182

8283
if (workflowSource && workflowSourceURL) {
83-
footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`;
84+
// Load workflow install note template
85+
const promptsDir = process.env.GH_AW_PROMPTS_DIR || "/opt/gh-aw/prompts";
86+
const installNoteTemplatePath = `${promptsDir}/workflow_install_note.md`;
87+
const installNoteTemplate = fs.readFileSync(installNoteTemplatePath, "utf8");
88+
const installNote = installNoteTemplate.replace("{workflow_source}", workflowSource);
89+
footer += `\n>\n> ${installNote}`;
8490
}
8591

8692
// Add missing tools and data sections if available

actions/setup/js/generate_footer.test.cjs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { describe, it, expect, beforeEach, vi } from "vitest";
1+
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
2+
import fs from "fs";
3+
import path from "path";
4+
import os from "os";
25

36
// Mock the global objects that GitHub Actions provides
47
const mockCore = {
@@ -34,8 +37,27 @@ global.context = mockContext;
3437
describe("generate_footer.cjs", () => {
3538
let generateFooter;
3639
let generateXMLMarker;
40+
let testPromptsDir;
41+
let originalEnv;
3742

3843
beforeEach(async () => {
44+
// Save original environment
45+
originalEnv = process.env.GH_AW_PROMPTS_DIR;
46+
47+
// Set up test prompts directory
48+
testPromptsDir = path.join(os.tmpdir(), "gh-aw-test-footer", "prompts");
49+
if (!fs.existsSync(testPromptsDir)) {
50+
fs.mkdirSync(testPromptsDir, { recursive: true });
51+
}
52+
53+
// Create the workflow install note template
54+
const templatePath = path.join(testPromptsDir, "workflow_install_note.md");
55+
const templateContent = "To add this workflow in your repository, run `gh aw add {workflow_source}`. See [usage guide](https://githubnext.github.io/gh-aw/guides/packaging-imports/).";
56+
fs.writeFileSync(templatePath, templateContent, "utf8");
57+
58+
// Set environment to use test directory
59+
process.env.GH_AW_PROMPTS_DIR = testPromptsDir;
60+
3961
// Reset mocks
4062
vi.clearAllMocks();
4163
// Clear env vars
@@ -50,6 +72,20 @@ describe("generate_footer.cjs", () => {
5072
generateXMLMarker = module.generateXMLMarker;
5173
});
5274

75+
afterEach(() => {
76+
// Restore original environment
77+
if (originalEnv !== undefined) {
78+
process.env.GH_AW_PROMPTS_DIR = originalEnv;
79+
} else {
80+
delete process.env.GH_AW_PROMPTS_DIR;
81+
}
82+
83+
// Clean up test directory
84+
if (testPromptsDir && fs.existsSync(testPromptsDir)) {
85+
fs.rmSync(testPromptsDir, { recursive: true, force: true });
86+
}
87+
});
88+
5389
describe("generateFooter", () => {
5490
it("should generate basic footer with workflow name and run URL", () => {
5591
const result = generateFooter("Test Workflow", "https://github.com/test/repo/actions/runs/123", "", "", undefined, undefined, undefined);
@@ -95,7 +131,7 @@ describe("generate_footer.cjs", () => {
95131
const result = generateFooter("Test Workflow", "https://github.com/test/repo/actions/runs/123", "owner/repo/workflow.md@main", "https://github.com/owner/repo/blob/main/workflow.md", undefined, undefined, undefined);
96132

97133
expect(result).toContain("gh aw add owner/repo/workflow.md@main");
98-
expect(result).toContain("See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/)");
134+
expect(result).toContain("See [usage guide](https://githubnext.github.io/gh-aw/guides/packaging-imports/)");
99135
});
100136

101137
it("should not include installation instructions when source is empty", () => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
To add this workflow in your repository, run `gh aw add {workflow_source}`. See [usage guide](https://githubnext.github.io/gh-aw/guides/packaging-imports/).

0 commit comments

Comments
 (0)