-
Notifications
You must be signed in to change notification settings - Fork 88
55 lines (48 loc) · 1.87 KB
/
auto-merge-pr.yml
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
name: Combine and Automerge PRs
on:
workflow_dispatch: # Allows manual triggering of the workflow
permissions:
contents: write
pull-requests: write
checks: read
jobs:
combine-and-automerge:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: List Pull Requests Ready for Batch Merge
id: pr_list
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }} # Using GH_TOKEN instead of GITHUB_TOKEN
script: |
const { data: pullRequests } = await github.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'desc',
});
console.log("data is ",pr);
// Filter PRs that add a single .txt file in the /cdn directory
const validPRs = pullRequests.filter(pr => {
return pr.files_url && pr.files.length === 1 && pr.files[0].filename.match(/^cdn\/.*\.txt$/);
});
return { pr_numbers: validPRs.map(pr => pr.number) };
- name: Combine PRs
if: steps.pr_list.outputs.pr_numbers
uses: github/[email protected]
with:
base: 'main' # Specify the base branch for the combined PR
head: 'combined-prs' # The new branch for the combined PR
title: 'Combined PRs adding .txt files to /cdn'
body: 'This PR combines all PRs that add .txt files to the /cdn directory.'
- name: Automerge Combined PR
if: success()
uses: pascalgn/[email protected]
env:
GH_TOKEN: "${{ secrets.GH_TOKEN }}" # Using GH_TOKEN here as well
with:
merge_method: squash
merge_commit_message: "Automatically merged combined PR adding new .txt files to /cdn"