Skip to content

Commit e4ab607

Browse files
committed
[Feature] Dependabot send out issue if package upgrade failure
1 parent 5318a73 commit e4ab607

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Dependabot Upgrade Monitor
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
monitor-dependabot:
9+
if: github.actor == 'dependabot[bot]'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Wait for checks to complete
13+
uses: WyriHaximus/github-action-wait-for-status@v1.8.0
14+
with:
15+
ignoreActions: monitor-dependabot
16+
checkInterval: 60
17+
env:
18+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
19+
20+
- name: Check if PR is failing
21+
id: check
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
const sha = context.payload.pull_request.head.sha;
26+
const owner = context.repo.owner;
27+
const repo = context.repo.repo;
28+
const { data: checkRunsData } = await github.rest.checks.listForRef({
29+
owner,
30+
repo,
31+
ref: sha,
32+
});
33+
const checkRuns = checkRunsData.check_runs;
34+
if (checkRuns.length === 0) {
35+
core.setFailed("No status checks found for this PR.");
36+
return;
37+
}
38+
const failedChecks = checkRuns.filter(
39+
check => check.status === 'completed' && check.conclusion !== 'success'
40+
);
41+
if (failedChecks.length > 0) {
42+
console.log("Some checks failed:");
43+
failedChecks.forEach(check => {
44+
console.log(`- ${check.name}: ${check.conclusion}`);
45+
});
46+
core.setFailed("Some required checks did not pass.");
47+
} else {
48+
console.log("All checks passed.");
49+
}
50+
- name: Create issue on failure
51+
if: failure() && github.event.action == 'opened'
52+
uses: actions/github-script@v7
53+
with:
54+
script: |
55+
await github.rest.issues.create({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
title: `Dependabot upgrade failed: #${context.issue.number} - ${context.payload.pull_request.title}`,
59+
body: `
60+
🚨 **Dependabot Upgrade Failed**
61+
62+
The following Dependabot pull request could not be merged automatically due to failed or incomplete status checks:
63+
64+
- **PR:** [#${context.issue.number}](${context.payload.pull_request.html_url})
65+
- **Status:** Not mergeable
66+
67+
Please review the PR and resolve any conflicts or CI issues to proceed with the upgrade.`,
68+
labels: ["dependencies", "enhancement", "go"],
69+
});
70+
71+
- name: Assign maintainers on success
72+
if: success()
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
// Step 1: Get collaborators
77+
const collaborators = await github.paginate(
78+
github.rest.repos.listCollaborators,
79+
{
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
affiliation: 'direct',
83+
per_page: 100
84+
}
85+
);
86+
87+
// Step 2: Filter maintainers
88+
const maintainers = collaborators
89+
.filter(user => user.permissions.admin)
90+
.map(user => user.login);
91+
92+
// Step 3: Assign to the PR
93+
if (maintainers.length > 0) {
94+
await github.rest.issues.addAssignees({
95+
owner: context.repo.owner,
96+
repo: context.repo.repo,
97+
issue_number: context.issue.number,
98+
assignees: maintainers,
99+
});
100+
} else {
101+
console.warn("No maintainers found to assign.");
102+
}

0 commit comments

Comments
 (0)