1414 name : Check all links
1515 if : github.repository == 'github/docs-internal'
1616 runs-on : ubuntu-latest
17+ env :
18+ GITHUB_TOKEN : ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
19+ REPORT_AUTHOR : docubot
20+ REPORT_LABEL : broken link report
21+ REPORT_REPOSITORY : github/docs-content
1722 steps :
1823 - uses : actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
1924 - name : npm ci
@@ -27,27 +32,58 @@ jobs:
2732 name : Get title for issue
2833 id : check
2934 run : echo "::set-output name=title::$(head -1 broken_links.md)"
30- - if : ${{ failure() }}
31- name : Close previous report
32- uses : lee-dohm/close-matching-issues@22002609b2555fe18f52b8e2e7c07cbf5529e8a8
33- with :
34- query : ' label:"broken link report"'
35- token : ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
3635 - if : ${{ failure() }}
3736 name : Create issue from file
3837 id : broken-link-report
3938 uses : peter-evans/create-issue-from-file@b4f9ee0a9d4abbfc6986601d9b1a4f8f8e74c77e
4039 with :
41- token : ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
40+ token : ${{ env.GITHUB_TOKEN }}
41+
4242 title : ${{ steps.check.outputs.title }}
4343 content-filepath : ./broken_links.md
44- repository : github/docs-content
45- labels : broken link report
44+ repository : ${{ env.REPORT_REPOSITORY }}
45+ labels : ${{ env.REPORT_LABEL }}
4646 - if : ${{ failure() }}
47- name : Add comment to issue
48- uses : peter-evans/create-or-update-comment@5221bf4aa615e5c6e95bb142f9673a9c791be2cd
49- with :
50- body : |
51- cc @github/docs-content
52- issue-number : ${{ steps.broken-link-report.outputs.issue-number }}
53- token : ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
47+ name : Close and/or comment on old issues
48+ env :
49+ NEW_REPORT_URL : ' https://github.com/${{ env.REPORT_REPOSITORY }}/issues/${{ steps.broken-link-report.outputs.issue-number }}'
50+ run : |
51+ gh alias set list-reports "issue list \
52+ --repo ${{ env.REPORT_REPOSITORY }} \
53+ --author ${{ env.REPORT_AUTHOR }} \
54+ --label '${{ env.REPORT_LABEL }}'"
55+
56+ # Link to the previous report from the new report that triggered this
57+ # workflow run.
58+
59+ for issue_url in $(gh list-reports \
60+ --state all \
61+ --limit 2 \
62+ --json url \
63+ --jq '.[].url' | grep -v ${{ env.NEW_REPORT_URL }}); do
64+ gh issue comment ${{ env.NEW_REPORT_URL }} --body "⬅️ [Previous report]($issue_url)"
65+ done
66+
67+ # Link to the newer report from any older report that is still open,
68+ # then close the older report.
69+
70+ for issue_url in $(gh list-reports \
71+ --search 'no:assignee' \
72+ --json url \
73+ --jq '.[].url'); do
74+ if [ "$issue_url" != "${{ env.NEW_REPORT_URL }}" ]; then
75+ gh issue comment $issue_url --body "➡️ [Newer report](${{ env.NEW_REPORT_URL }})"
76+ gh issue close $issue_url
77+ fi
78+ done
79+
80+ # If an old report is open and assigned to someone, link to the newer
81+ # report without closing the old report.
82+
83+ for issue_url in $(gh list-reports \
84+ --json assignees,url \
85+ --jq '.[] | select (.assignees != []) | .url'); do
86+ if [ "$issue_url" != "${{ env.NEW_REPORT_URL }}" ]; then
87+ gh issue comment $issue_url --body "➡️ [Newer report](${{ env.NEW_REPORT_URL }})"
88+ fi
89+ done
0 commit comments