Skip to content

Commit a0fa919

Browse files
authored
Merge branch 'main' into l-monninger/ci-fix
2 parents 0134626 + 4e2d452 commit a0fa919

File tree

39 files changed

+1639
-138
lines changed

39 files changed

+1639
-138
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 }}"

.github/workflows/target-comment.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Comment Trigger Workflow
2+
3+
on:
4+
issue_comment:
5+
types: [created, edited]
6+
7+
jobs:
8+
dispatch-workflow:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check if comment is on a PR
12+
id: check_pr
13+
run: |
14+
if [ "${{ github.event.issue.pull_request }}" == "" ]; then
15+
echo "This comment is not on a pull request."
16+
echo "::set-output name=is_pr::false"
17+
else
18+
echo "PR URL: ${{ github.event.issue.pull_request.url }}"
19+
echo "::set-output name=is_pr::true"
20+
fi
21+
22+
- name: Fetch PR Details
23+
if: steps.check_pr.outputs.is_pr == 'true'
24+
id: get_pr
25+
uses: octokit/request-action@v2.x
26+
with:
27+
route: GET ${{ github.event.issue.pull_request.url }}
28+
mediaType: '{"previews": ["shadow-cat"]}'
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Dispatch Target Workflow
33+
if: steps.check_pr.outputs.is_pr == 'true'
34+
uses: benc-uk/workflow-dispatch@v1
35+
with:
36+
workflow: Handle Target Comment
37+
token: ${{ secrets.GH_PAT }}
38+
inputs: >
39+
{
40+
"comment": "${{ github.event.comment.body }}",
41+
"issue_number": "${{ github.event.issue.number }}",
42+
"html_url" : "${{ github.event.issue.html_url }}"
43+
}
44+
ref: ${{ fromJson(steps.get_pr.outputs.data).head.ref }}
45+
repo: ${{ fromJson(steps.get_pr.outputs.data).head.repo.full_name }}

0 commit comments

Comments
 (0)