From ca34336eac79b0ae86a127c3b073a4c30393d837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Chali=C5=84ski?= Date: Tue, 28 May 2024 14:11:59 +0200 Subject: [PATCH] Test if GitHub Action add_pr_to_smackore_board works again (#806) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Feliks PobiedziƄski <38541925+FelonEkonom@users.noreply.github.com> --- .../add_pr_to_smackore_board/action.yml | 30 +++++++++---------- scripts/python/get_author_origin.py | 6 ++-- scripts/python/get_ticket_id.py | 23 +++++++++----- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/.github/actions/add_pr_to_smackore_board/action.yml b/.github/actions/add_pr_to_smackore_board/action.yml index 27ce92b46..e83d81b74 100644 --- a/.github/actions/add_pr_to_smackore_board/action.yml +++ b/.github/actions/add_pr_to_smackore_board/action.yml @@ -1,5 +1,5 @@ name: 'Add PR to Smackore board, if author is from community' -description: '(disabled due to github-side bug) Adds PR to "New issues by community" column in Smackore project board, if PR author is from outside Membrane Team.' +description: 'Adds PR to "New issues by community" column in Smackore project board, if PR author is from outside Membrane Team.' inputs: GITHUB_TOKEN: description: 'GitHub token' @@ -19,23 +19,23 @@ runs: repository: membraneframework/membrane_core - name: Maybe add PR to board and set ticket status run: | - # currently this causes github action crash, more info here: https://github.com/membraneframework/membrane_core/issues/749 - - # export PROJECT_NUMBER=19 - # export PROJECT_ID=PVT_kwDOAYE_z84AWEIB - # export STATUS_FIELD_ID=PVTSSF_lADOAYE_z84AWEIBzgOGd1k - # export TARGET_COLUMN_ID=e6b1ee10 + # currently this may cause github action crash, more info here: https://github.com/membraneframework/membrane_core/issues/749 + + export PROJECT_NUMBER=19 + export PROJECT_ID=PVT_kwDOAYE_z84AWEIB + export STATUS_FIELD_ID=PVTSSF_lADOAYE_z84AWEIBzgOGd1k + export TARGET_COLUMN_ID=e6b1ee10 - # export AUTHOR_ORIGIN=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/membraneframework/teams/membraneteam/members | python scripts/python/get_author_origin.py $AUTHOR_LOGIN) + export AUTHOR_ORIGIN=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /orgs/membraneframework/teams/membraneteam/members | python scripts/python/get_author_origin.py $AUTHOR_LOGIN) - # if [ "$AUTHOR_ORIGIN" == "COMMUNITY" ] - # then - # gh pr edit "$PR_URL" --add-project Smackore - # sleep 10 + if [ "$AUTHOR_ORIGIN" == "COMMUNITY" ] + then + gh pr edit "$PR_URL" --add-project Smackore + sleep 10 - # export TICKET_ID=$(gh project item-list $PROJECT_NUMBER --owner membraneframework --format json --limit 10000000 | python scripts/python/get_ticket_id.py "$PR_URL") - # gh project item-edit --id $TICKET_ID --field-id $STATUS_FIELD_ID --project-id $PROJECT_ID --single-select-option-id $TARGET_COLUMN_ID - # fi + export TICKET_ID=$(gh project item-list $PROJECT_NUMBER --owner membraneframework --format json --limit 10000000 | python scripts/python/get_ticket_id.py "$PR_URL") + gh project item-edit --id $TICKET_ID --field-id $STATUS_FIELD_ID --project-id $PROJECT_ID --single-select-option-id $TARGET_COLUMN_ID + fi env: GH_TOKEN: ${{ inputs.GITHUB_TOKEN }} diff --git a/scripts/python/get_author_origin.py b/scripts/python/get_author_origin.py index 7a6e7804a..50b3662cd 100644 --- a/scripts/python/get_author_origin.py +++ b/scripts/python/get_author_origin.py @@ -15,6 +15,6 @@ print("COMMUNITY") except: - print("An exception occurred, provided JSON:") - print(membrane_team) - print("provided PR_AUTHOR:", pr_author) \ No newline at end of file + print("An exception occurred in get_author_origin.py, provided JSON: ", membrane_team) + print("Provided PR_AUTHOR: ", pr_author) + sys.exit(1) diff --git a/scripts/python/get_ticket_id.py b/scripts/python/get_ticket_id.py index d0eb92104..55fdca630 100644 --- a/scripts/python/get_ticket_id.py +++ b/scripts/python/get_ticket_id.py @@ -3,11 +3,18 @@ full_json = json.load(sys.stdin) pr_url = sys.argv[1] -try: - project_items = full_json["items"] - [id] = [item["id"] for item in project_items if ("url" in item["content"] and item["content"]["url"] == pr_url)] - print(id) -except: - print("An exception occurred, provided JSON:") - print(full_json) - print("provided PR_URL:", pr_url) \ No newline at end of file +project_items = full_json["items"] + +item_id = None +for item in project_items: + if "content" in item and "url" in item["content"]: + if item["content"]["url"] == pr_url: + item_id = item["id"] + break + +if item_id == None: + print("Error occurred in get_ticket.py: ID of ticket related to PR", pr_url, "not found in the provided JSON") + print("Provided JSON:", full_json) + sys.exit(1) +else: + print(item_id)