Skip to content

Commit 70df11e

Browse files
Snailedltlunatic-foxPanquesito7
authored
Bugfix/fix in-develop labeler (#1410)
* fix issue not being labeled with in-develop * restrict to only run on merge to develop * Remove Python setup Co-authored-by: Josélio Júnior <[email protected]> --------- Co-authored-by: Josélio Júnior <[email protected]> Co-authored-by: David Leal <[email protected]>
1 parent ed17988 commit 70df11e

File tree

5 files changed

+69
-10
lines changed

5 files changed

+69
-10
lines changed

.github/scripts/build_assets/api_handler.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,19 @@ def get_issues_by_labels(token: str, labels: List[str]):
180180
issues.extend(issues_only)
181181

182182
return issues
183+
184+
185+
def get_pr_by_number(token: str, pr_num: str):
186+
url = base_url + "pulls/" + pr_num
187+
headers = {
188+
"Authorization": f"token {token}"
189+
}
190+
191+
print(f"Querying the GitHub API for requests")
192+
response = requests.get(url, headers=headers)
193+
if not response:
194+
print(f"Can't query the GitHub API. Status code is {response.status_code}. Message is {response.text}")
195+
sys.exit(1)
196+
197+
pr = response.json()
198+
return pr

.github/scripts/build_assets/arg_getters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def get_in_develop_labeler_args():
8282
help="The GitHub token to access the GitHub REST API.",
8383
type=str)
8484

85-
parser.add_argument("body",
86-
help="The PR's initial comment by the author AKA the `body` attribute of the `pull_request` API object.",
85+
parser.add_argument("pr_num",
86+
help="The PR's number",
8787
type=str)
8888
return parser.parse_args()

.github/scripts/in_develop_labeler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
def main():
55
args = arg_getters.get_in_develop_labeler_args()
66
try:
7+
#get pr body
8+
pr_body = api_handler.get_pr_by_number(args.token, args.pr_num)["body"]
9+
710
# find the issue closing line
8-
issue_line = [line for line in args.body.split("\n") if line.startswith("**This PR closes")][0]
11+
print(pr_body.split("\n"))
12+
issue_line = [line for line in pr_body.split("\n") if line.startswith("**This PR closes")][0]
913

1014
print("Issue Line is " + issue_line)
1115
issue_pattern = re.compile(r"\d+")
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name: Label Issue In Develop
2-
on:
3-
pull_request:
4-
types: [closed]
2+
on:
3+
workflow_run:
4+
workflows: ['On Develop PR Merge']
5+
types:
6+
- completed
57
jobs:
6-
label:
8+
label_preflight:
79
name: Label Issue In Develop
810
runs-on: ubuntu-18.04
9-
if: github.event.pull_request.merged == true
11+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1012
steps:
1113
- uses: actions/checkout@v2
1214

@@ -19,9 +21,22 @@ jobs:
1921
run: |
2022
python -m pip install --upgrade pip
2123
pip install -r ./.github/scripts/requirements.txt
24+
25+
- name: Download workflow artifact
26+
uses: dawidd6/[email protected]
27+
with:
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
workflow: peek_icons.yml
30+
run_id: ${{ github.event.workflow_run.id }}
31+
32+
- name: Read the pr_num file
33+
id: pr_num_reader
34+
uses: juliangruber/[email protected]
35+
with:
36+
path: ./pr_num/pr_num.txt
2237

2338
- name: Run in_develop_labeler.py
2439
env:
2540
TOKEN: ${{ secrets.GITHUB_TOKEN }}
26-
BODY: ${{ github.event.pull_request.body }}
27-
run: python ./.github/scripts/in_develop_labeler.py $TOKEN "$BODY"
41+
PR_NUM: ${{ steps.pr_num_reader.outputs.content }}
42+
run: python ./.github/scripts/in_develop_labeler.py $TOKEN "$PR_NUM"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: On Develop PR Merge
2+
on:
3+
pull_request:
4+
types: [closed]
5+
branches: [develop]
6+
jobs:
7+
save_pr_num_in_artifact:
8+
name: Preflight Label Issue In Develop
9+
runs-on: ubuntu-18.04
10+
if: github.event.pull_request.merged == true
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Save the PR number in an artifact
15+
shell: bash
16+
env:
17+
PR_NUM: ${{ github.event.number }}
18+
run: echo $PR_NUM > pr_num.txt
19+
20+
- name: Upload the PR number
21+
uses: actions/[email protected]
22+
with:
23+
name: pr_num
24+
path: ./pr_num.txt

0 commit comments

Comments
 (0)