-
Notifications
You must be signed in to change notification settings - Fork 87
75 lines (67 loc) · 2.94 KB
/
infra.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Infra
on:
push:
workflow_dispatch:
issue_comment:
types: [created, edited, deleted]
jobs:
manage-infra-pr:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, 'infra')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Extract repository name
id: repo-name
run: echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d '/' -f2)" >> $GITHUB_ENV
- name: Search for existing PRs
id: search-prs
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const title = `${process.env.REPO_NAME}/${{ github.event.issue.title }}`;
const prs = await github.rest.pulls.list({
owner: 'movementlabsxyz',
repo: 'infra',
state: 'open',
head: 'main'
});
const existingPr = prs.data.find(pr => pr.title === title);
if (existingPr) {
return existingPr.html_url;
}
return '';
- name: Create PR in Infra Repo if not exist
if: steps.search-prs.outputs.result == ''
id: create-pr
uses: repo-sync/pull-request@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: "auto-update-refs"
destination_branch: "main"
pr_title: "${{ steps.repo-name.outputs.REPO_NAME }}/${{ github.event.issue.title }}"
pr_body: "Automated PR for changes related to ${{ github.event.issue.html_url }}. \n\n Original comment: ${{ github.event.comment.body }}"
destination_repo: "movementlabsxyz/infra"
- name: Comment on the Original PR with new PR link
if: steps.search-prs.outputs.result == ''
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.issue.number }}
body: ${{ steps.create-pr.outputs.pr_url }}
- name: Comment on Original PR with PR link if PR already exists
if: steps.search-prs.outputs.result != ''
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.issue.number }}
body: "A related PR already exists and you can follow it here: ${{ steps.search-prs.outputs.result }}"
- name: Comment on the Infra PR if created
if: steps.search-prs.outputs.result == ''
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: "movementlabsxyz/infra"
issue_number: ${{ steps.create-pr.outputs.pr_number }}
body: "This PR relates to changes triggered by an issue in another repository. Original PR: ${{ github.event.issue.html_url }} \n\n Details: ${{ github.event.comment.body }}"