|
| 1 | +name: fix-dependabot-alert |
| 2 | +description: >- |
| 3 | + Picks the highest-severity open Dependabot alert, upgrades the |
| 4 | + vulnerable dependency, verifies tests pass, and opens a pull request. |
| 5 | +triggers: |
| 6 | + - context: |
| 7 | + projects: {} |
| 8 | + manual: {} |
| 9 | +action: |
| 10 | + limits: |
| 11 | + maxParallel: 1 |
| 12 | + maxTotal: 10 |
| 13 | + steps: |
| 14 | + # Step 1: Install gh CLI if not present |
| 15 | + - task: |
| 16 | + command: | |
| 17 | + command -v gh && exit 0 |
| 18 | + curl -sL https://github.com/cli/cli/releases/latest/download/gh_2.74.0_linux_amd64.tar.gz | tar xz -C /tmp |
| 19 | + sudo mv /tmp/gh_2.74.0_linux_amd64/bin/gh /usr/local/bin/gh |
| 20 | + # Step 2: Fetch the highest-severity open Dependabot alert |
| 21 | + - task: |
| 22 | + command: | |
| 23 | + export GITHUB_TOKEN=$(printf 'protocol=https\nhost=github.com\n\n' | git credential fill | awk -F= '/password/{print $2}') |
| 24 | + gh api repos/{owner}/{repo}/dependabot/alerts \ |
| 25 | + --jq '[.[] | select(.state=="open")] | sort_by(.security_advisory.cvss.score) | reverse | .[0]' \ |
| 26 | + > /tmp/dependabot-alert.json |
| 27 | + cat /tmp/dependabot-alert.json |
| 28 | + - agent: |
| 29 | + prompt: | |
| 30 | + Read /tmp/dependabot-alert.json which contains the highest-severity open |
| 31 | + Dependabot alert. Extract the alert number, package name, vulnerable and |
| 32 | + patched versions, CVE ID, CVSS score, and manifest file path. |
| 33 | +
|
| 34 | + If the file is empty, null, or contains no alert, output |
| 35 | + "NO_ALERT: No open Dependabot alerts found." and stop. |
| 36 | +
|
| 37 | + Check whether the dependency is already at or above the patched version. |
| 38 | + If so, output "ALREADY_FIXED: <package> is already at <version>." and stop. |
| 39 | +
|
| 40 | + Otherwise, apply the fix: |
| 41 | + 1. Read the manifest file to understand how the dependency is declared. |
| 42 | + 2. Upgrade the vulnerable dependency to the patched version (or newer). |
| 43 | + - If the version is in `pom.xml` properties or directly, update it there. |
| 44 | + - If inherited from a parent BOM, add an explicit version override. |
| 45 | + 3. Follow the project's existing conventions. |
| 46 | +
|
| 47 | + Do NOT commit or run tests yet. |
| 48 | +
|
| 49 | + - agent: |
| 50 | + prompt: | |
| 51 | + Verify the fix from the previous step: |
| 52 | +
|
| 53 | + 1. Identify the project's build tool, test runner, and linter from the |
| 54 | + repo config files. |
| 55 | + 2. Compile the project. If it fails, read the errors, fix them, and retry. |
| 56 | + 3. Find all test suites and verification commands that could exercise the |
| 57 | + modified code. Run them. |
| 58 | + 4. If any check fails, determine whether the failure is caused by your |
| 59 | + change or is pre-existing. Fix what you broke and rerun. |
| 60 | + 5. Repeat until all checks pass. |
| 61 | + 6. For dependency upgrades, confirm the vulnerable version is no longer |
| 62 | + in the resolved dependency tree. |
| 63 | +
|
| 64 | + - pullRequest: |
| 65 | + branch: dependabot-fix/ |
| 66 | + title: 'Dependabot-Fix: ' |
| 67 | + description: | |
| 68 | + ## Dependabot Alert |
| 69 | +
|
| 70 | + | Field | Value | |
| 71 | + |-------|-------| |
| 72 | + | **Alert** | [View alert](https://github.com/ona-samples/github-security/security/dependabot/<alert-number>) | |
| 73 | + | **CVE** | `<cve-id>` | |
| 74 | + | **CVSS** | <cvss-score> | |
| 75 | + | **Package** | `<package-name>` | |
| 76 | + | **Vulnerable** | `<vulnerable-version>` | |
| 77 | + | **Fixed** | `<patched-version>` | |
| 78 | + | **Advisory** | <advisory-summary> | |
| 79 | +
|
| 80 | + ## What changed |
| 81 | +
|
| 82 | + <one-or-two-sentence explanation of the dependency upgrade and why it resolves the vulnerability> |
| 83 | +
|
| 84 | + ## Verification |
| 85 | +
|
| 86 | + <List each build, test, and lint command that was run and its outcome. |
| 87 | + For dependency upgrades, state how you confirmed the vulnerable version |
| 88 | + is no longer in the resolved dependency tree.> |
0 commit comments