From 9991978d40c6a8d57862639513067fc497f87223 Mon Sep 17 00:00:00 2001 From: Snailedlt <43886029+Snailedlt@users.noreply.github.com> Date: Sun, 2 Oct 2022 16:17:16 +0200 Subject: [PATCH 1/3] fix issue not being labeled with in-develop --- .github/scripts/build_assets/api_handler.py | 16 +++++++++ .github/scripts/build_assets/arg_getters.py | 4 +-- .github/scripts/in_develop_labeler.py | 6 +++- .github/workflows/in_develop_labeler.yml | 29 ++++++++++++---- .../in_develop_labeler_preflight.yml | 33 +++++++++++++++++++ 5 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/in_develop_labeler_preflight.yml diff --git a/.github/scripts/build_assets/api_handler.py b/.github/scripts/build_assets/api_handler.py index 042edb5ee..b11c2dc67 100644 --- a/.github/scripts/build_assets/api_handler.py +++ b/.github/scripts/build_assets/api_handler.py @@ -180,3 +180,19 @@ def get_issues_by_labels(token: str, labels: List[str]): issues.extend(issues_only) return issues + + +def get_pr_by_number(token: str, pr_num: str): + url = base_url + "pulls/" + pr_num + headers = { + "Authorization": f"token {token}" + } + + print(f"Querying the GitHub API for requests") + response = requests.get(url, headers=headers) + if not response: + print(f"Can't query the GitHub API. Status code is {response.status_code}. Message is {response.text}") + sys.exit(1) + + pr = response.json() + return pr diff --git a/.github/scripts/build_assets/arg_getters.py b/.github/scripts/build_assets/arg_getters.py index d086bd331..66733c227 100644 --- a/.github/scripts/build_assets/arg_getters.py +++ b/.github/scripts/build_assets/arg_getters.py @@ -82,7 +82,7 @@ def get_in_develop_labeler_args(): 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.", + parser.add_argument("pr_num", + help="The PR's number", type=str) return parser.parse_args() diff --git a/.github/scripts/in_develop_labeler.py b/.github/scripts/in_develop_labeler.py index c065b9667..3d329c994 100644 --- a/.github/scripts/in_develop_labeler.py +++ b/.github/scripts/in_develop_labeler.py @@ -4,8 +4,12 @@ def main(): args = arg_getters.get_in_develop_labeler_args() try: + #get pr body + pr_body = api_handler.get_pr_by_number(args.token, args.pr_num)["body"] + # find the issue closing line - issue_line = [line for line in args.body.split("\n") if line.startswith("**This PR closes")][0] + print(pr_body.split("\n")) + issue_line = [line for line in pr_body.split("\n") if line.startswith("**This PR closes")][0] print("Issue Line is " + issue_line) issue_pattern = re.compile(r"\d+") diff --git a/.github/workflows/in_develop_labeler.yml b/.github/workflows/in_develop_labeler.yml index 61b7b4335..a0309979c 100644 --- a/.github/workflows/in_develop_labeler.yml +++ b/.github/workflows/in_develop_labeler.yml @@ -1,12 +1,14 @@ name: Label Issue In Develop -on: - pull_request: - types: [closed] +on: + workflow_run: + workflows: ['On PR Merge'] + types: + - completed jobs: - label: + label_preflight: name: Label Issue In Develop runs-on: ubuntu-18.04 - if: github.event.pull_request.merged == true + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - uses: actions/checkout@v2 @@ -19,9 +21,22 @@ jobs: run: | python -m pip install --upgrade pip pip install -r ./.github/scripts/requirements.txt + + - name: Download workflow artifact + uses: dawidd6/action-download-artifact@v2.11.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workflow: peek_icons.yml + run_id: ${{ github.event.workflow_run.id }} + + - name: Read the pr_num file + id: pr_num_reader + uses: juliangruber/read-file-action@v1.0.0 + with: + path: ./pr_num/pr_num.txt - 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" + PR_NUM: ${{ steps.pr_num_reader.outputs.content }} + run: python ./.github/scripts/in_develop_labeler.py $TOKEN "$PR_NUM" diff --git a/.github/workflows/in_develop_labeler_preflight.yml b/.github/workflows/in_develop_labeler_preflight.yml new file mode 100644 index 000000000..f4c574297 --- /dev/null +++ b/.github/workflows/in_develop_labeler_preflight.yml @@ -0,0 +1,33 @@ +name: On PR Merge +on: + pull_request: + types: [closed] +jobs: + save_pr_num_in_artifact: + name: Preflight 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: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r ./.github/scripts/requirements.txt + + - name: Save the PR number in an artifact + shell: bash + env: + PR_NUM: ${{ github.event.number }} + run: echo $PR_NUM > pr_num.txt + + - name: Upload the PR number + uses: actions/upload-artifact@v2.2.4 + with: + name: pr_num + path: ./pr_num.txt From 013e4b47abdaac647f1ebf7d667900fc3950162b Mon Sep 17 00:00:00 2001 From: Snailedlt <43886029+Snailedlt@users.noreply.github.com> Date: Sun, 2 Oct 2022 16:18:38 +0200 Subject: [PATCH 2/3] restrict to only run on merge to develop --- .github/workflows/in_develop_labeler.yml | 2 +- .github/workflows/in_develop_labeler_preflight.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/in_develop_labeler.yml b/.github/workflows/in_develop_labeler.yml index a0309979c..d212091bc 100644 --- a/.github/workflows/in_develop_labeler.yml +++ b/.github/workflows/in_develop_labeler.yml @@ -1,7 +1,7 @@ name: Label Issue In Develop on: workflow_run: - workflows: ['On PR Merge'] + workflows: ['On Develop PR Merge'] types: - completed jobs: diff --git a/.github/workflows/in_develop_labeler_preflight.yml b/.github/workflows/in_develop_labeler_preflight.yml index f4c574297..bee5aa257 100644 --- a/.github/workflows/in_develop_labeler_preflight.yml +++ b/.github/workflows/in_develop_labeler_preflight.yml @@ -1,7 +1,8 @@ -name: On PR Merge +name: On Develop PR Merge on: pull_request: types: [closed] + branches: [develop] jobs: save_pr_num_in_artifact: name: Preflight Label Issue In Develop From 01123ccfa108e1418d7a69417ac4314d243eba50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kalsnes=20Hagen?= <43886029+Snailedlt@users.noreply.github.com> Date: Sat, 18 Feb 2023 17:40:14 +0100 Subject: [PATCH 3/3] Remove Python setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josélio Júnior <76992016+lunatic-fox@users.noreply.github.com> --- .github/workflows/in_develop_labeler_preflight.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/in_develop_labeler_preflight.yml b/.github/workflows/in_develop_labeler_preflight.yml index bee5aa257..21a5430c5 100644 --- a/.github/workflows/in_develop_labeler_preflight.yml +++ b/.github/workflows/in_develop_labeler_preflight.yml @@ -11,16 +11,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Setup Python v3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r ./.github/scripts/requirements.txt - - name: Save the PR number in an artifact shell: bash env: