Skip to content

Commit ed068ba

Browse files
authored
Merge pull request #189 from internetee/auto_merge
Automated pull request merging
2 parents dcd927e + f6436c6 commit ed068ba

File tree

4 files changed

+146
-2
lines changed

4 files changed

+146
-2
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "bundler"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
day: "monday"
8+
time: "09:00"
9+
allow:
10+
- dependency-type: "direct"
11+
open-pull-requests-limit: 10
12+
reviewers:
13+
- "internetee"
14+
assignees:
15+
- "internetee"

.github/workflows/auto-merge.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Auto approve & merge Dependabot and Renovate PRs
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened, labeled]
6+
branches: [master]
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
auto-approve-merge:
14+
runs-on: ubuntu-latest
15+
if: (github.actor == 'dependabot[bot]' || github.actor == 'renovate[bot]') && github.repository == 'internetee/whois'
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v5
19+
20+
- name: Install GitHub CLI
21+
run: |
22+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
23+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
24+
sudo apt update
25+
sudo apt install gh
26+
- name: Auto approve PR
27+
uses: hmarr/auto-approve-action@v3
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Fetch Dependabot metadata
32+
if: github.actor == 'dependabot[bot]'
33+
id: metadata
34+
uses: dependabot/fetch-metadata@v1
35+
with:
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Check if PR should be auto-merged
39+
id: check_auto_merge
40+
run: |
41+
if [ "${{ github.actor }}" == "dependabot[bot]" ]; then
42+
if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-patch" ]]; then
43+
echo "auto_merge=true" >> $GITHUB_OUTPUT
44+
echo "Auto-merge: Dependabot patch update detected"
45+
else
46+
echo "auto_merge=false" >> $GITHUB_OUTPUT
47+
echo "Auto-merge: Dependabot non-patch update, skipping"
48+
fi
49+
elif [ "${{ github.actor }}" == "renovate[bot]" ]; then
50+
# Check if PR has patch label (set by renovate.json configuration)
51+
# Extract label names from the labels array
52+
LABEL_NAMES=$(echo '${{ toJson(github.event.pull_request.labels) }}' | jq -r '.[].name' | tr '\n' ' ')
53+
if [[ "$LABEL_NAMES" == *"patch"* ]] || [[ "$LABEL_NAMES" == *"bundler"* ]] || [[ "$LABEL_NAMES" == *"ruby-version"* ]] || [[ "$LABEL_NAMES" == *"github-actions"* ]]; then
54+
echo "auto_merge=true" >> $GITHUB_OUTPUT
55+
echo "Auto-merge: Renovate patch update detected (label-based): $LABEL_NAMES"
56+
else
57+
echo "auto_merge=false" >> $GITHUB_OUTPUT
58+
echo "Auto-merge: Renovate non-patch update, skipping. Labels: $LABEL_NAMES"
59+
fi
60+
else
61+
echo "auto_merge=false" >> $GITHUB_OUTPUT
62+
echo "Auto-merge: Unknown actor, skipping"
63+
fi
64+
shell: bash
65+
66+
- name: Wait for CI checks
67+
if: steps.check_auto_merge.outputs.auto_merge == 'true'
68+
uses: lewagon/wait-on-check-action@v1.3.4
69+
with:
70+
ref: ${{ github.event.pull_request.head.sha }}
71+
repo-token: ${{ secrets.GITHUB_TOKEN }}
72+
wait-interval: 30
73+
running-workflow-name: 'Test and Coverage'
74+
75+
- name: Auto-merge PR
76+
if: steps.check_auto_merge.outputs.auto_merge == 'true'
77+
run: |
78+
echo "Attempting to auto-merge PR #${{ github.event.pull_request.number }}"
79+
gh pr merge --auto --merge ${{ github.event.pull_request.number }} || {
80+
echo "Auto-merge failed, but continuing..."
81+
exit 0
82+
}
83+
env:
84+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
86+
- name: Send Mattermost notification
87+
if: steps.check_auto_merge.outputs.auto_merge == 'true'
88+
run: |
89+
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M UTC")
90+
curl -X POST -H "Authorization: Bearer ${{ secrets.MATTERMOST_BOT_TOKEN }}" \
91+
-H "Content-Type: application/json" \
92+
-d "{\"channel_id\":\"${{ secrets.MATTERMOST_CHANNEL_ID }}\",\"message\":\"[${{ github.repository }}] PR #${{ github.event.pull_request.number }}: \\\"${{ github.event.pull_request.title }}\\\" was auto-merged by ${{ github.actor }}.\nUpdate type: ${{ steps.metadata.outputs.update-type || 'patch' }}\nMerged at: $TIMESTAMP\nLink: ${{ github.event.pull_request.html_url }}\"}" \
93+
https://mattermost.example.com/api/v4/posts

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Test and Coverage
22

33
on:
44
push:
5+
pull_request:
56

67
permissions:
78
contents: read

renovate.json

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,53 @@
44
],
55
"packageRules": [
66
{
7-
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
7+
"matchUpdateTypes": ["patch", "pin", "digest"],
8+
"automerge": true,
9+
"automergeType": "pr",
10+
"addLabels": ["patch"]
11+
},
12+
{
13+
"matchUpdateTypes": ["minor"],
14+
"automerge": false,
15+
"addLabels": ["minor"]
16+
},
17+
{
18+
"matchUpdateTypes": ["major"],
819
"automerge": false,
20+
"addLabels": ["major"]
21+
},
22+
{
23+
"matchDepTypes": ["ruby", "bundler", "Gemfile", "Gemfile.lock"],
24+
"matchUpdateTypes": ["patch"],
25+
"addLabels": ["bundler"],
26+
"automerge": true,
927
"automergeType": "pr"
1028
},
1129
{
1230
"matchDepTypes": ["ruby", "bundler", "Gemfile", "Gemfile.lock"],
13-
"addLabels": ["bundler"]
31+
"matchUpdateTypes": ["minor", "major"],
32+
"addLabels": ["bundler"],
33+
"automerge": false
1434
},
1535
{
1636
"matchDepTypes": [".ruby-version"],
37+
"matchUpdateTypes": ["patch"],
38+
"addLabels": ["ruby-version"],
39+
"automerge": true,
40+
"automergeType": "pr"
41+
},
42+
{
43+
"matchDepTypes": [".ruby-version"],
44+
"matchUpdateTypes": ["minor", "major"],
1745
"addLabels": ["ruby-version"],
1846
"automerge": false
47+
},
48+
{
49+
"matchFileNames": [".github/workflows/ruby.yml"],
50+
"matchUpdateTypes": ["patch", "minor"],
51+
"addLabels": ["github-actions"],
52+
"automerge": true,
53+
"automergeType": "pr"
1954
}
2055
],
2156
"docker": {

0 commit comments

Comments
 (0)