|
14 | 14 | type: string |
15 | 15 | required: true |
16 | 16 | default: 'en' |
| 17 | + create_copilot_issue: |
| 18 | + description: 'Create a Copilot-assigned issue with the top 10 redirects to fix' |
| 19 | + type: boolean |
| 20 | + required: false |
| 21 | + default: false |
| 22 | + create_report: |
| 23 | + description: 'Create the combined broken links report issue in docs-content' |
| 24 | + type: boolean |
| 25 | + required: false |
| 26 | + default: true |
17 | 27 |
|
18 | 28 | permissions: |
19 | 29 | contents: read |
@@ -101,6 +111,80 @@ jobs: |
101 | 111 | retention-days: 5 |
102 | 112 | if-no-files-found: ignore |
103 | 113 |
|
| 114 | + - name: Create Copilot redirect issue |
| 115 | + if: inputs.create_copilot_issue |
| 116 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 |
| 117 | + with: |
| 118 | + github-token: ${{ secrets.DOCS_BOT_PAT_BASE }} |
| 119 | + script: | |
| 120 | + const fs = require('fs') |
| 121 | + const reportFile = 'artifacts/link-report-${{ matrix.version }}-${{ matrix.language }}.json' |
| 122 | +
|
| 123 | + if (!fs.existsSync(reportFile)) { |
| 124 | + core.info('No JSON report found — all links valid, skipping Copilot issue.') |
| 125 | + return |
| 126 | + } |
| 127 | +
|
| 128 | + const report = JSON.parse(fs.readFileSync(reportFile, 'utf8')) |
| 129 | + const allRedirectGroups = report.groups.filter(g => g.isWarning) |
| 130 | + const redirectGroups = allRedirectGroups.slice(0, 10) |
| 131 | +
|
| 132 | + if (redirectGroups.length === 0) { |
| 133 | + core.info('No redirect groups found, skipping Copilot issue.') |
| 134 | + return |
| 135 | + } |
| 136 | +
|
| 137 | + const tableRows = redirectGroups.map(g => { |
| 138 | + const occ = g.occurrences[0] |
| 139 | + const redirectTarget = occ?.redirectTarget ?? 'unknown' |
| 140 | + const file = occ?.file ?? 'unknown' |
| 141 | + const lines = (occ?.lines ?? []).join(', ') |
| 142 | + return `| \`${g.target}\` | \`${redirectTarget}\` | \`${file}\` | ${lines} |` |
| 143 | + }).join('\n') |
| 144 | +
|
| 145 | + const artifactsUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts` |
| 146 | +
|
| 147 | + const bodyLines = [ |
| 148 | + 'Copilot please fix the redirected internal links listed in the table below. All changes should be made within the `github/docs-internal` repository. For each entry, open the source file and replace the **Current Link** with the **Update To** path.', |
| 149 | + 'When all changes are made, open a pull request in `github/docs-internal` with the fixes. The pull request description should reference this issue to create a link between them. When the pull request is open, leave a comment on this issue with a link to it.', |
| 150 | + '', |
| 151 | + `These are the first ${redirectGroups.length} of ${allRedirectGroups.length} redirects found.`, |
| 152 | + '', |
| 153 | + '## Redirects to fix', |
| 154 | + '', |
| 155 | + '| Current Link | Update To | File | Line(s) |', |
| 156 | + '|---|---|---|---|', |
| 157 | + tableRows, |
| 158 | + ] |
| 159 | +
|
| 160 | + const MAX_ISSUE_BODY_LENGTH = 65536 |
| 161 | + const artifactNote = `\n\n> [!NOTE]\n> The report was truncated because it exceeded the issue body length limit. [View the complete redirect report in the workflow artifacts](${artifactsUrl}).` |
| 162 | +
|
| 163 | + let body = bodyLines.join('\n') |
| 164 | + if (body.length > MAX_ISSUE_BODY_LENGTH) { |
| 165 | + const truncatedLength = MAX_ISSUE_BODY_LENGTH - artifactNote.length |
| 166 | + const lastNewline = body.lastIndexOf('\n', truncatedLength) |
| 167 | + body = body.slice(0, lastNewline > 0 ? lastNewline : truncatedLength) + artifactNote |
| 168 | + } |
| 169 | +
|
| 170 | + // Use the REST API with agent_assignment to properly trigger Copilot cloud agent. |
| 171 | + // See: https://docs.github.com/en/copilot/how-tos/use-copilot-agents/cloud-agent/start-copilot-sessions#using-the-rest-api |
| 172 | + const issue = await github.request('POST /repos/{owner}/{repo}/issues', { |
| 173 | + owner: 'github', |
| 174 | + repo: 'docs-content', |
| 175 | + title: '[Copilot Task] Fix top redirect links: ${{ matrix.version }}/${{ matrix.language }}', |
| 176 | + body, |
| 177 | + labels: ['broken link report'], |
| 178 | + assignees: ['copilot-swe-agent[bot]'], |
| 179 | + agent_assignment: { |
| 180 | + target_repo: 'github/docs-internal', |
| 181 | + base_branch: 'main', |
| 182 | + custom_instructions: 'For each entry in the table, open the source file in the github/docs-internal repository and replace the Current Link with the Update To path. When all changes are made, open a pull request in github/docs-internal with the fixes. When the pull request is open, leave a comment on this issue with a link to it.', |
| 183 | + }, |
| 184 | + }) |
| 185 | +
|
| 186 | + core.info(`Created Copilot redirect issue: ${issue.data.html_url}`) |
| 187 | +
|
104 | 188 | - uses: ./.github/actions/slack-alert |
105 | 189 | if: ${{ failure() && github.event_name != 'workflow_dispatch' }} |
106 | 190 | with: |
@@ -159,7 +243,7 @@ jobs: |
159 | 243 | fi |
160 | 244 |
|
161 | 245 | - name: Create issue if broken links found |
162 | | - if: steps.combine.outputs.has_reports == 'true' |
| 246 | + if: steps.combine.outputs.has_reports == 'true' && (github.event_name != 'workflow_dispatch' || inputs.create_report != false) |
163 | 247 | uses: peter-evans/create-issue-from-file@fca9117c27cdc29c6c4db3b86c48e4115a786710 # v5 |
164 | 248 | with: |
165 | 249 | token: ${{ secrets.DOCS_BOT_PAT_BASE }} |
|
0 commit comments