diff --git a/.github/workflows/dependabot-alert.yml b/.github/workflows/dependabot-alert.yml index 9c88c47..e2ff04f 100644 --- a/.github/workflows/dependabot-alert.yml +++ b/.github/workflows/dependabot-alert.yml @@ -23,8 +23,11 @@ jobs: GH_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} run: | - ALERTS=$(gh api "/repos/${REPO}/dependabot/alerts" \ - --jq '[.[] | select(.state == "open") | select(.security_vulnerability.severity | test("^(high|critical)$"))]') + ALERTS=$(curl -s \ + -H "Authorization: Bearer ${GH_TOKEN}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${REPO}/dependabot/alerts?per_page=100" | \ + jq '[.[] | select(.state == "open") | select(.security_vulnerability.severity | test("^(high|critical)$"))]') COUNT=$(echo "$ALERTS" | jq 'length') echo "Found ${COUNT} high/critical open alert(s)" diff --git a/.github/workflows/dependabot-management.yml b/.github/workflows/dependabot-management.yml index 2bbb656..b03e566 100644 --- a/.github/workflows/dependabot-management.yml +++ b/.github/workflows/dependabot-management.yml @@ -194,12 +194,11 @@ jobs: GHSA_ID: ${{ inputs.ghsa_id }} REPO: ${{ github.repository }} run: | - COUNT=$(gh pr list \ - --repo "$REPO" \ - --search "${GHSA_ID} in:title" \ - --state open \ - --json number \ - --jq '. | length') + COUNT=$(curl -s \ + -H "Authorization: Bearer ${GH_TOKEN}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/search/issues?q=${GHSA_ID}+in:title+repo:${REPO}+is:pr+is:open" | \ + jq '.total_count') echo "exists=$([ "${COUNT}" -gt "0" ] && echo 'true' || echo 'false')" >> "$GITHUB_OUTPUT" - uses: actions/checkout@v6 @@ -290,12 +289,31 @@ jobs: run: | NL=$'\n' PR_BODY="## Security Vulnerability Fix${NL}${NL}Addresses Dependabot alert #${ALERT_NUMBER}: **${SUMMARY}**${NL}${NL}| Field | Value |${NL}|-------|-------|${NL}| Package | \`${PACKAGE_NAME}\` (${PACKAGE_ECOSYSTEM}) |${NL}| Severity | ${SEVERITY} |${NL}| GHSA | [${GHSA_ID}](https://github.com/advisories/${GHSA_ID}) |${NL}| CVE | ${CVE_ID:-N/A} |${NL}| Vulnerable range | ${VULN_RANGE} |${NL}| Fixed in | ${PATCHED_VERSION:-latest} |${NL}${NL}**Linear:** [${TICKET_ID}](${TICKET_URL})${NL}${NL}> 🤖 Generated by [Claude Code](https://claude.ai/claude-code) via [dependabot-management](https://github.com/pgmac-net/pg-actions)" - gh pr create \ - --draft \ - --repo "$REPO" \ - --head "$BRANCH" \ - --title "fix(${PACKAGE_NAME}): address ${GHSA_ID}" \ - --body "$PR_BODY" + + BASE=$(curl -s \ + -H "Authorization: Bearer ${GH_TOKEN}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${REPO}" | \ + jq -r '.default_branch') + + RESPONSE=$(curl -s -X POST \ + -H "Authorization: Bearer ${GH_TOKEN}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${REPO}/pulls" \ + -d "$(jq -n \ + --arg title "fix(${PACKAGE_NAME}): address ${GHSA_ID}" \ + --arg body "$PR_BODY" \ + --arg head "$BRANCH" \ + --arg base "$BASE" \ + '{title: $title, body: $body, head: $head, base: $base, draft: true}')") + + PR_URL=$(echo "$RESPONSE" | jq -r '.html_url') + if [ "$PR_URL" = "null" ] || [ -z "$PR_URL" ]; then + echo "Error creating PR:" + echo "$RESPONSE" | jq . + exit 1 + fi + echo "Created PR: $PR_URL" - name: No automatic fix available if: >-