mirror of
https://github.com/konpa/devicon.git
synced 2025-01-16 21:18:13 +01:00
Separate in develop labeler into two workflows
This commit is contained in:
parent
5b4e917d3b
commit
c1b507f9ca
24
.github/scripts/build_assets/arg_getters.py
vendored
24
.github/scripts/build_assets/arg_getters.py
vendored
@ -73,16 +73,30 @@ def get_release_message_args():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def get_in_develop_labeler_args():
|
||||
def get_issue_finder_in_pr():
|
||||
"""
|
||||
Get the commandline arguments for in_develop_labeler.py.
|
||||
Get the commandline arguments for issue_finder_in_pr.py.
|
||||
"""
|
||||
parser = ArgumentParser(description="Parse the PR body to find the issue(s) we are labelling.")
|
||||
parser.add_argument("token",
|
||||
help="The GitHub token to access the GitHub REST API.",
|
||||
type=str)
|
||||
|
||||
parser.add_argument("body",
|
||||
help="The PR's initial comment by the author AKA the `body` attribute of the `pull_request` API object.",
|
||||
type=str)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def get_in_develop_labeler_args():
|
||||
"""
|
||||
Get the commandline arguments for in_develop_labeler.py.
|
||||
"""
|
||||
parser = ArgumentParser(description="Find the issue numbers from the line passed in and label the issues.")
|
||||
parser.add_argument("token",
|
||||
help="The GitHub token to access the GitHub REST API.",
|
||||
type=str)
|
||||
|
||||
parser.add_argument("issues",
|
||||
help="The issues as a ' ' delimited string. Can also be NONE if there's nothing.",
|
||||
type=str)
|
||||
|
||||
return parser.parse_args()
|
||||
|
22
.github/scripts/in_develop_labeler.py
vendored
22
.github/scripts/in_develop_labeler.py
vendored
@ -1,20 +1,8 @@
|
||||
import re
|
||||
from build_assets import arg_getters, api_handler
|
||||
|
||||
def main():
|
||||
args = arg_getters.get_in_develop_labeler_args()
|
||||
try:
|
||||
# find the issue closing line
|
||||
issue_line = [line for line in args.body.split("\n") if line.startswith("**This PR closes")][0]
|
||||
|
||||
print("Issue Line is " + issue_line)
|
||||
issue_pattern = re.compile(r"\d+")
|
||||
issues_numbers = issue_pattern.findall(issue_line)
|
||||
print("Labelling issues: " + str(issues_numbers))
|
||||
api_handler.label_issues(args.token, issues_numbers, ["in-develop"])
|
||||
except IndexError: # if can't find the issue line
|
||||
print("The PR body doesn't contain `**This PR closes` keywords. Ending workflow.")
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
args = arg_getters.get_in_develop_labeler_args()
|
||||
# find the issue closing line
|
||||
issues = args.issues
|
||||
if issues != "NONE":
|
||||
api_handler.label_issues(args.token, issues.split(" "), ["in-develop"])
|
||||
|
18
.github/scripts/issue_finder_in_pr.py
vendored
Normal file
18
.github/scripts/issue_finder_in_pr.py
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
import re
|
||||
from build_assets import arg_getters, filehandler
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = arg_getters.get_issue_finder_in_pr()
|
||||
try:
|
||||
# find the issue closing line
|
||||
issue_line = [line for line in args.body.split("\n") if line.startswith("**This PR closes")][0]
|
||||
|
||||
print("Issue Line is " + issue_line)
|
||||
issue_pattern = re.compile(r"\d+")
|
||||
issues_numbers = issue_pattern.findall(issue_line)
|
||||
print("Labelling issues: " + str(issues_numbers))
|
||||
|
||||
filehandler.write_to_file("issue_nums.txt", " ".join(issues_numbers) if len(issues_numbers) > 0 else "NONE")
|
||||
except IndexError: # if can't find the issue line
|
||||
print("The PR body doesn't contain `**This PR closes` keywords. Ending workflow.")
|
||||
filehandler.write_to_file("issue_nums.txt", "NONE")
|
33
.github/workflows/in_develop_labeler.yml
vendored
33
.github/workflows/in_develop_labeler.yml
vendored
@ -2,17 +2,34 @@ name: Label Issue In Develop
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
# solution taken from https://github.com/actions/first-interaction/issues/10#issuecomment-1041402989
|
||||
# this allows this workflow to label the PRs to have the `in-develop` label
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
jobs:
|
||||
label:
|
||||
name: Label Issue In Develop
|
||||
runs-on: ubuntu-18.04
|
||||
if: github.event.pull_request.merged == true
|
||||
if: github.event.action == 'completed' && github.event.workflow_run.conclusion != 'skipped'
|
||||
env:
|
||||
# three possible values: 'skipped', 'success', 'failure'
|
||||
# have to print github.event to console to see these values
|
||||
# note: can't use this env variable up in the if statement above for some reason.
|
||||
# I don't think it's an ordering issue cause it seems 'if' is auto evaluate first
|
||||
PREV_STATUS: ${{ github.event.workflow_run.conclusion }}
|
||||
steps:
|
||||
- name: Check state of last run
|
||||
run: echo $PREV_STATUS
|
||||
|
||||
- name: Download workflow artifact
|
||||
uses: dawidd6/action-download-artifact@v2.11.0
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
workflow: issue_finder_in_pr.yml
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
|
||||
- name: Read the issue_nums file
|
||||
id: issues_num_reader
|
||||
uses: juliangruber/read-file-action@v1.0.0
|
||||
with:
|
||||
path: ./issue_nums/issue_nums.txt
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Python v3.8
|
||||
@ -28,5 +45,5 @@ jobs:
|
||||
- name: Run in_develop_labeler.py
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BODY: ${{ github.event.pull_request.body }}
|
||||
run: python ./.github/scripts/in_develop_labeler.py $TOKEN "$BODY"
|
||||
ISSUES: ${{ steps.issues_num_reader.outputs.content }}
|
||||
run: python ./.github/scripts/in_develop_labeler.py $TOKEN "$ISSUES"
|
||||
|
28
.github/workflows/issue_finder_in_pr.yml
vendored
Normal file
28
.github/workflows/issue_finder_in_pr.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
name: Find the issues we want to close in a merged PR
|
||||
on:
|
||||
pull_request:
|
||||
types: [closed]
|
||||
jobs:
|
||||
label:
|
||||
name: Label Issue In Develop
|
||||
runs-on: ubuntu-18.04
|
||||
if: github.event.pull_request.merged == true
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Python v3.8
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.8
|
||||
|
||||
- name: Run issue_finder_in_pr.py
|
||||
env:
|
||||
BODY: ${{ github.event.pull_request.body }}
|
||||
run: python ./.github/scripts/issue_finder_in_pr.py "$BODY"
|
||||
|
||||
- name: Upload the issues found created by issue_finder_in_pr.py
|
||||
uses: actions/upload-artifact@v2
|
||||
if: success()
|
||||
with:
|
||||
name: issue_nums
|
||||
path: ./issue_nums.txt
|
Loading…
x
Reference in New Issue
Block a user