-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (63 loc) · 2.13 KB
/
Copy pathauto-merge-on-release.yml
File metadata and controls
75 lines (63 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Auto-merge reusable workflow
on:
workflow_call:
inputs:
head_branch:
description: 'Branch name to find PR for'
required: false
type: string
permissions:
contents: write
pull-requests: write
jobs:
auto-merge:
runs-on: ubuntu-latest
steps:
- name: Auto-merge matching PR
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Use the provided input; caller should supply `head_branch` when invoking.
const head_branch = "${{ inputs.head_branch }}";
const owner = context.repo.owner;
const repo = context.repo.repo;
if (!head_branch) {
core.info('No head_branch provided; nothing to do.');
return;
}
core.info(`Auto-merge triggered for branch: ${head_branch}`);
const prs = await github.rest.pulls.list({
owner,
repo,
head: `${owner}:${head_branch}`,
state: 'open',
});
if (!prs.data || prs.data.length === 0) {
core.info(`No open pull request found for branch ${head_branch}`);
return;
}
const pr = prs.data[0];
if (pr.draft) {
core.info(`Pull request #${pr.number} is a draft; skipping merge.`);
return;
}
try {
const res = await github.rest.pulls.merge({
owner,
repo,
pull_number: pr.number,
merge_method: 'merge',
commit_title: head_branch,
commit_message: '',
});
if (res.data.merged) {
core.info(`Successfully merged PR #${pr.number} (branch ${head_branch}).`);
} else {
core.info(`Merge attempt returned: ${JSON.stringify(res.data)}`);
}
} catch (err) {
core.setFailed(`Failed to merge PR #${pr.number}: ${err}`);
}
- name: Done
run: echo "auto-merge finished"