Skip to content

Commit ad417ba

Browse files
Pigbibicodex
andcommitted
enable Dependabot automation
Co-Authored-By: Codex <noreply@openai.com>
1 parent c0f3209 commit ad417ba

3 files changed

Lines changed: 162 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 5
8+
ignore:
9+
- dependency-name: "*"
10+
update-types:
11+
- "version-update:semver-major"
12+
- package-ecosystem: "github-actions"
13+
directory: "/"
14+
schedule:
15+
interval: "weekly"
16+
open-pull-requests-limit: 5
17+
ignore:
18+
- dependency-name: "*"
19+
update-types:
20+
- "version-update:semver-major"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Auto Merge Dependabot PR
2+
3+
"on":
4+
workflow_run:
5+
workflows: ["CI"]
6+
types: [completed]
7+
8+
jobs:
9+
auto-merge:
10+
if: github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'dependabot/')
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
17+
steps:
18+
- name: Resolve Dependabot PR
19+
id: pr
20+
env:
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: |
23+
set -euo pipefail
24+
BRANCH_NAME="${{ github.event.workflow_run.head_branch }}"
25+
PR_PAYLOAD=$(gh pr list --repo "${GITHUB_REPOSITORY}" --state open --head "${BRANCH_NAME}" --json number,headRefOid --jq '.[0] // {}')
26+
PR_NUMBER=$(python3 -c 'import json,sys; print(json.load(sys.stdin).get("number", ""))' <<<"${PR_PAYLOAD}")
27+
PR_HEAD_SHA=$(python3 -c 'import json,sys; print(json.load(sys.stdin).get("headRefOid", ""))' <<<"${PR_PAYLOAD}")
28+
if [ -z "${PR_NUMBER}" ]; then
29+
echo "No open Dependabot PR found for ${BRANCH_NAME}." >> "$GITHUB_STEP_SUMMARY"
30+
exit 0
31+
fi
32+
if [ "${PR_HEAD_SHA}" != "${{ github.event.workflow_run.head_sha }}" ]; then
33+
echo "Skipping auto-merge: PR #${PR_NUMBER} head ${PR_HEAD_SHA} does not match completed CI head ${{ github.event.workflow_run.head_sha }}." >> "$GITHUB_STEP_SUMMARY"
34+
exit 0
35+
fi
36+
echo "pr_number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
37+
echo "head_sha=${PR_HEAD_SHA}" >> "$GITHUB_OUTPUT"
38+
39+
- name: Evaluate merge eligibility
40+
id: merge_guard
41+
if: steps.pr.outputs.pr_number != ''
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
set -euo pipefail
46+
gh pr view "${{ steps.pr.outputs.pr_number }}" --repo "${GITHUB_REPOSITORY}" --json number,isDraft,author,url,body,labels > pr.json
47+
python3 - <<'PY'
48+
import json
49+
import os
50+
from pathlib import Path
51+
52+
pr = json.loads(Path("pr.json").read_text(encoding="utf-8"))
53+
author = (pr.get("author") or {}).get("login")
54+
labels = {item.get("name", "") for item in pr.get("labels", [])}
55+
body = pr.get("body") or ""
56+
is_major = "update-type: version-update:semver-major" in body
57+
dependabot_authors = {"dependabot[bot]", "app/dependabot"}
58+
is_dependabot = author in dependabot_authors and "dependencies" in labels
59+
should_merge = is_dependabot and not pr.get("isDraft") and not is_major
60+
if should_merge:
61+
reason = "ready"
62+
elif is_major:
63+
reason = "major_update"
64+
else:
65+
reason = "not_eligible_dependabot_pr"
66+
67+
summary_lines = [
68+
"## Auto-Merge Gate",
69+
f"- PR: {pr['url']}",
70+
f"- Author: `{author or '<unknown>'}`",
71+
f"- Draft: `{'yes' if pr.get('isDraft') else 'no'}`",
72+
f"- Dependabot label: `{'yes' if 'dependencies' in labels else 'no'}`",
73+
f"- Major update: `{'yes' if is_major else 'no'}`",
74+
f"- Final merge decision: `{'merge' if should_merge else 'skip'}`",
75+
f"- Reason: `{reason}`",
76+
]
77+
Path("pr-summary.md").write_text("\n".join(summary_lines).strip() + "\n", encoding="utf-8")
78+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
79+
print(f"should_merge={'true' if should_merge else 'false'}", file=output)
80+
print(f"reason={reason}", file=output)
81+
PY
82+
83+
- name: Append merge summary
84+
if: steps.pr.outputs.pr_number != ''
85+
run: cat pr-summary.md >> "$GITHUB_STEP_SUMMARY"
86+
87+
- name: Merge Dependabot PR
88+
if: steps.merge_guard.outputs.should_merge == 'true'
89+
env:
90+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
run: gh pr merge "${{ steps.pr.outputs.pr_number }}" --repo "${GITHUB_REPOSITORY}" --rebase --delete-branch --match-head-commit "${{ steps.pr.outputs.head_sha }}"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Dismiss Dependabot Review Request
2+
3+
"on":
4+
pull_request_target:
5+
types: [review_requested]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
dismiss-review-request:
13+
if: >-
14+
(github.event.pull_request.user.login == 'dependabot[bot]' ||
15+
github.event.pull_request.user.login == 'app/dependabot') &&
16+
github.event.requested_reviewer.login == 'Pigbibi'
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 5
19+
steps:
20+
- name: Dismiss Pigbibi review request
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
PR_NUMBER: ${{ github.event.pull_request.number }}
24+
REVIEWER: Pigbibi
25+
run: |
26+
set -euo pipefail
27+
current_review_requests() {
28+
gh pr view "${PR_NUMBER}" \
29+
--repo "${GITHUB_REPOSITORY}" \
30+
--json reviewRequests \
31+
--jq '.reviewRequests[].login'
32+
}
33+
34+
review_requests="$(current_review_requests)"
35+
if ! grep -Fqx "${REVIEWER}" <<<"${review_requests}"; then
36+
echo "No review request for ${REVIEWER}; nothing to dismiss." >> "${GITHUB_STEP_SUMMARY}"
37+
exit 0
38+
fi
39+
40+
if ! gh api --method DELETE \
41+
"repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/requested_reviewers" \
42+
-f "reviewers[]=${REVIEWER}"; then
43+
review_requests="$(current_review_requests)"
44+
if ! grep -Fqx "${REVIEWER}" <<<"${review_requests}"; then
45+
echo "Review request was removed concurrently; nothing to dismiss." >> "${GITHUB_STEP_SUMMARY}"
46+
exit 0
47+
fi
48+
exit 1
49+
fi
50+
51+
echo "Dismissed Dependabot review request for ${REVIEWER}." >> "${GITHUB_STEP_SUMMARY}"

0 commit comments

Comments
 (0)