Skip to content

Commit 177c6ae

Browse files
committed
ci: fix auto assign for forked repos
1 parent e6fbf5b commit 177c6ae

File tree

2 files changed

+111
-30
lines changed

2 files changed

+111
-30
lines changed
Lines changed: 87 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,95 @@
11
name: 'Auto Assign PR'
2+
23
on:
3-
workflow_call:
4-
pull_request:
5-
types: [opened, reopened]
4+
workflow_run:
5+
workflows: ["Pull Request Opened"]
6+
types:
7+
- completed
68

79
jobs:
10+
log-info:
11+
name: "Add reviewers to PR"
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: "echo variables"
15+
run: |
16+
echo \"${{ github.event.workflow_run.event }}\"
17+
echo \"${{ github.event.pull_request.types }}\"
18+
echo \"${{ github.actor }}\"
19+
820
add-reviewers:
921
name: "Add reviewers to PR"
10-
if: ${{ github.actor != 'dependabot[bot]' }}
22+
if: >
23+
github.event.workflow_run.event == 'pull_request' &&
24+
github.actor != 'dependabot[bot]'
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.MP_SEMANTIC_RELEASE_BOT }}
27+
GIT_AUTHOR_NAME: mparticle-automation
28+
GIT_AUTHOR_EMAIL: [email protected]
29+
GIT_COMMITTER_NAME: mparticle-automation
30+
GIT_COMMITTER_EMAIL: [email protected]
1131
runs-on: ubuntu-latest
1232
steps:
13-
- name: "Check PR title"
14-
id: is-docs
15-
if: >
16-
startsWith(github.event.pull_request.title, 'docs:')
17-
run: |
18-
OUTPUT=true
19-
echo "::set-output name=isDocs::$OUTPUT"
20-
- name: "echo isDocs"
21-
run: |
22-
echo ${{ steps.is-docs.outputs.isDocs }}
23-
- name: "PR title is docs"
24-
if: ${{steps.is-docs.outputs.isDocs == 'true'}}
25-
uses: pozil/auto-assign-issue@v1
26-
with:
27-
teams: docs-admin
28-
numOfAssignee: 1
29-
allowSelfAssign: false
30-
repo-token: ${{ secrets.MP_SEMANTIC_RELEASE_BOT}}
31-
- name: "PR title is invalid"
32-
if: ${{ steps.is-docs.outputs.isDocs != 'true'}}
33-
uses: pozil/auto-assign-issue@v1
34-
with:
35-
teams: android-triage
36-
numOfAssignee: 1
37-
allowSelfAssign: false
38-
repo-token: ${{ secrets.MP_SEMANTIC_RELEASE_BOT}}
33+
- name: 'Print Event'
34+
run: |
35+
echo ${{ github.event.workflow_run.event }}
36+
- name: 'Download artifact'
37+
uses: actions/[email protected]
38+
with:
39+
script: |
40+
var artifacts = await github.actions.listWorkflowRunArtifacts({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
run_id: ${{ github.event.workflow_run.id }},
44+
});
45+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
46+
return artifact.name == "pr"
47+
})[0];
48+
var download = await github.actions.downloadArtifact({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
artifact_id: matchArtifact.id,
52+
archive_format: 'zip',
53+
});
54+
var fs = require('fs');
55+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
56+
- run: unzip pr.zip
57+
- name: 'Find PR Title'
58+
id: find-pr
59+
uses: actions/github-script@v3
60+
with:
61+
github-token: ${{ secrets.GITHUB_TOKEN }}
62+
script: |
63+
var fs = require('fs');
64+
var titleString = String(fs.readFileSync('./NR'));
65+
echo "::set-output name=title::titleString"
66+
- name: "Log PR Title"
67+
run: |
68+
echo \"${{ steps.find-pr.outputs.title }}\"
69+
70+
- name: "Check PR title"
71+
id: is-docs
72+
if: >
73+
startsWith(${{ steps.find-pr.outputs.title }}, 'docs:')
74+
run: |
75+
OUTPUT=true
76+
echo "::set-output name=isDocs::$OUTPUT"
77+
- name: "echo isDocs"
78+
run: |
79+
echo ${{ steps.is-docs.outputs.isDocs }}
80+
- name: "PR title is docs"
81+
if: ${{steps.is-docs.outputs.isDocs == 'true'}}
82+
uses: pozil/auto-assign-issue@v1
83+
with:
84+
teams: docs-triage
85+
numOfAssignee: 1
86+
allowSelfAssign: false
87+
repo-token: ${{ secrets.MP_SEMANTIC_RELEASE_BOT}}
88+
- name: "PR title is not docs"
89+
if: ${{ steps.is-docs.outputs.isDocs != 'true'}}
90+
uses: pozil/auto-assign-issue@v1
91+
with:
92+
teams: android-triage
93+
numOfAssignee: 1
94+
allowSelfAssign: false
95+
repo-token: ${{ secrets.MP_SEMANTIC_RELEASE_BOT}}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Pull Request Opened"
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened]
6+
7+
jobs:
8+
pull-request-opened:
9+
name: "Opened Pull Request"
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: "Checkout PR branch"
13+
uses: actions/checkout@v2
14+
with:
15+
submodules: recursive
16+
fetch-depth: 0
17+
- name: "Save Pull Request Number"
18+
run: |
19+
mkdir -p ./pr
20+
echo ${{ github.event.pull_request.title }} > ./pr/NR
21+
- uses: actions/upload-artifact@v2
22+
with:
23+
name: pr
24+
path: pr/

0 commit comments

Comments
 (0)