Skip to content

Commit e6b22aa

Browse files
committed
don't create duplicate issues
1 parent 5a2eefb commit e6b22aa

File tree

1 file changed

+86
-28
lines changed

1 file changed

+86
-28
lines changed

project_name/.github/workflows/weekly-ci.yml.jinja

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,54 @@ jobs:
3939
uses: actions/github-script@v7
4040
with:
4141
script: |
42-
const issue = await github.rest.issues.create({
42+
// Check for existing test failure issues
43+
const existingIssues = await github.rest.issues.listForRepo({
4344
owner: context.repo.owner,
4445
repo: context.repo.repo,
45-
title: `Scheduled CI Tests Failed - ${new Date().toISOString().split('T')[0]}`,
46-
body: `The scheduled CI tests failed on ${context.sha.substring(0, 7)}.
46+
state: 'open',
47+
labels: 'scheduled-ci-tests',
48+
per_page: 10
49+
});
4750

48-
**Failed Jobs:**
49-
- Check the [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId})
51+
if (existingIssues.data.length > 0) {
52+
// Update existing issue
53+
const existingIssue = existingIssues.data[0];
54+
await github.rest.issues.createComment({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
issue_number: existingIssue.number,
58+
body: `Another test failure occurred on ${context.sha.substring(0, 7)}.
5059

51-
**Likely Causes:**
52-
- New dependency versions with breaking changes
60+
**Failed Jobs:**
61+
- Check the [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId})
5362

54-
**Next Steps:**
55-
- Review the logs above
56-
- Update code for new dependencies or limit package versions
57-
- Re-run the workflow to verify fixes`,
58-
assignees: [context.repo.owner],
59-
});
60-
await core.notice(`Created issue ${issue.data.html_url}`);
63+
**Date:** ${new Date().toISOString().split('T')[0]}`
64+
});
65+
await core.notice(`Updated existing issue ${existingIssue.html_url}`);
66+
67+
} else {
68+
// Create new issue
69+
const issue = await github.rest.issues.create({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
title: `Scheduled CI Tests Failed - ${new Date().toISOString().split('T')[0]}`,
73+
body: `The scheduled CI tests failed on ${context.sha.substring(0, 7)}.
74+
75+
**Failed Jobs:**
76+
- Check the [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId})
77+
78+
**Likely Causes:**
79+
- New dependency versions with breaking changes
80+
81+
**Next Steps:**
82+
- Review the logs above
83+
- Update code for new dependencies or limit package versions
84+
- Re-run the workflow to verify fixes`,
85+
labels: ['scheduled-ci-tests'],
86+
assignees: [context.repo.owner],
87+
});
88+
await core.notice(`Created issue ${issue.data.html_url}`);
89+
}
6190

6291
pip-audit:
6392
runs-on: ubuntu-latest
@@ -83,22 +112,51 @@ jobs:
83112
uses: actions/github-script@v7
84113
with:
85114
script: |
86-
const issue = await github.rest.issues.create({
115+
// Check for existing audit failure issues
116+
const existingIssues = await github.rest.issues.listForRepo({
87117
owner: context.repo.owner,
88118
repo: context.repo.repo,
89-
title: `Scheduled CI Audit Failed - ${new Date().toISOString().split('T')[0]}`,
90-
body: `The scheduled CI audit check failed on ${context.sha.substring(0, 7)}.
119+
state: 'open',
120+
labels: 'scheduled-ci-audit',
121+
per_page: 10
122+
});
91123

92-
**Failed Jobs:**
93-
- Check the [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId})
124+
if (existingIssues.data.length > 0) {
125+
// Update existing issue instead of creating new one
126+
const existingIssue = existingIssues.data[0];
127+
await github.rest.issues.createComment({
128+
owner: context.repo.owner,
129+
repo: context.repo.repo,
130+
issue_number: existingIssue.number,
131+
body: `Another audit failure occurred on ${context.sha.substring(0, 7)}.
94132

95-
**Likely Causes:**
96-
- New security vulnerabilities detected by pip-audit
133+
**Failed Jobs:**
134+
- Check the [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId})
97135

98-
**Next Steps:**
99-
- Review the logs above
100-
- Update locked dependencies
101-
- Re-run the workflow to verify fixes`,
102-
assignees: [context.repo.owner],
103-
});
104-
await core.notice(`Created issue ${issue.data.html_url}`);
136+
**Date:** ${new Date().toISOString().split('T')[0]}`
137+
});
138+
await core.notice(`Updated existing issue ${existingIssue.html_url}`);
139+
140+
} else {
141+
// Create new issue
142+
const issue = await github.rest.issues.create({
143+
owner: context.repo.owner,
144+
repo: context.repo.repo,
145+
title: `Scheduled CI Audit Failed - ${new Date().toISOString().split('T')[0]}`,
146+
body: `The scheduled CI audit check failed on ${context.sha.substring(0, 7)}.
147+
148+
**Failed Jobs:**
149+
- Check the [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId})
150+
151+
**Likely Causes:**
152+
- New security vulnerabilities detected by pip-audit
153+
154+
**Next Steps:**
155+
- Review the logs above
156+
- Update locked dependencies
157+
- Re-run the workflow to verify fixes`,
158+
labels: ['scheduled-ci-audit'],
159+
assignees: [context.repo.owner],
160+
});
161+
await core.notice(`Created issue ${issue.data.html_url}`);
162+
}

0 commit comments

Comments
 (0)