1
+ name : Handle Target Comment
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ comment :
7
+ description : ' Comment from issue_comment event'
8
+ required : true
9
+ type : string
10
+
11
+ jobs :
12
+ handle-comment :
13
+ runs-on : ubuntu-latest
14
+ steps :
15
+ - name : Output the comment
16
+ run : |
17
+ echo "Comment was: ${{ github.event.inputs.comment }}"
18
+
19
+ manage-infra-pr :
20
+ if : startsWith(github.event.inputs.comment, 'infra')
21
+ runs-on : ubuntu-latest
22
+ steps :
23
+ - name : Checkout code
24
+ uses : actions/checkout@v3
25
+
26
+ - name : Extract repository name
27
+ id : repo-name
28
+ run : echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d '/' -f2)" >> $GITHUB_ENV
29
+
30
+ - name : Search for existing PRs
31
+ id : search-prs
32
+ uses : actions/github-script@v6
33
+ with :
34
+ github-token : ${{ secrets.GITHUB_TOKEN }}
35
+ script : |
36
+ const title = `${process.env.REPO_NAME}/${{ github.event.issue.title }}`;
37
+ const prs = await github.rest.pulls.list({
38
+ owner: 'movementlabsxyz',
39
+ repo: 'infra',
40
+ state: 'open',
41
+ head: 'main'
42
+ });
43
+ const existingPr = prs.data.find(pr => pr.title === title);
44
+ if (existingPr) {
45
+ return existingPr.html_url;
46
+ }
47
+ return '';
48
+
49
+ - name : Create PR in Infra Repo if not exist
50
+ if : steps.search-prs.outputs.result == ''
51
+ run : |
52
+ gh_pr_up() { gh pr create $* || gh pr edit $* }
53
+ gh_pr_up --title "${{ steps.repo-name.outputs.REPO_NAME }}/${{ github.event.issue.title }}" --body "**Infrastructure requested:** ${{ github.event.issue.html_url }}\n\n${{ github.event.comment.body }} --repo movementlabsxyz/infra"
54
+
55
+ - name : Comment on the Original PR with new PR link
56
+ if : steps.search-prs.outputs.result == ''
57
+ uses : peter-evans/create-or-update-comment@v2
58
+ with :
59
+ token : ${{ secrets.GITHUB_TOKEN }}
60
+ issue_number : ${{ github.event.issue.number }}
61
+ body : ${{ steps.create-pr.outputs.pr_url }}
62
+
63
+ - name : Comment on Original PR with PR link if PR already exists
64
+ if : steps.search-prs.outputs.result != ''
65
+ uses : peter-evans/create-or-update-comment@v2
66
+ with :
67
+ token : ${{ secrets.GITHUB_TOKEN }}
68
+ issue_number : ${{ github.event.issue.number }}
69
+ body : " A related PR already exists and you can follow it here: ${{ steps.search-prs.outputs.result }}"
70
+
71
+ - name : Comment on the Infra PR if created
72
+ if : steps.search-prs.outputs.result == ''
73
+ uses : peter-evans/create-or-update-comment@v2
74
+ with :
75
+ token : ${{ secrets.GITHUB_TOKEN }}
76
+ repository : " movementlabsxyz/infra"
77
+ issue_number : ${{ steps.create-pr.outputs.pr_number }}
78
+ 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 }}"
0 commit comments