From 6f81d3fe1d9d42591fe113749ce2d4e0abf936e0 Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Thu, 12 Oct 2023 16:07:07 +0200 Subject: [PATCH 1/3] Write github actions necessary for auto closing issues beyond core --- .formatter.exs | 1 + .github/actions/close_issue/action.yml | 39 +++++++++++++++++++ .github/actions/create_label/action.yml | 14 +++++++ .github/workflows/update-packages-list.yml | 2 +- scripts/get_ticket_id.exs | 14 +++++++ .../update_packages_list.exs | 0 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .github/actions/close_issue/action.yml create mode 100644 .github/actions/create_label/action.yml create mode 100644 scripts/get_ticket_id.exs rename update_packages_list.exs => scripts/update_packages_list.exs (100%) diff --git a/.formatter.exs b/.formatter.exs index 56ab8c4db..cce53f36f 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -11,6 +11,7 @@ locals_without_parens = [ inputs: [ "{lib,test,config,benchmark}/**/*.{ex,exs}", + "scripts/*.exs", "*.exs" ], locals_without_parens: locals_without_parens, diff --git a/.github/actions/close_issue/action.yml b/.github/actions/close_issue/action.yml new file mode 100644 index 000000000..8a25447b2 --- /dev/null +++ b/.github/actions/close_issue/action.yml @@ -0,0 +1,39 @@ +name: 'Close issue when opened' +description: 'Closes a newly opened issue, tags it and puts it in the proper column in Smackore project board.' +inputs: + GITHUB_TOKEN: + description: 'GitHub token' + required: true + ISSUE_URL: + description: 'Issue URL' + required: true + ISSUE_NUMBER: + description: 'Issue number' + required: true + REPOSITORY: + description: 'Repository' + required: true +runs: + using: 'composite' + steps: + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: '26.1' + elixir-version: '1.15.6' + - name: Checkout code + uses: actions/checkout@v3 + - name: Create ticket and close issue + run: | + gh issue edit $ISSUE_URL --add-project "Smackore" --add-label closed-by-membrane-bot + sleep 10 + export TICKET_ID=$(gh project item-list 19 --owner membraneframework --format json --limit 10000000 | elixir get_ticket_id.exs "$ISSUE_URL" | awk '/TICKET_ID/{print $2}') + gh issue close $ISSUE_URL --comment "Only PRs welcome ;)" --reason "not planned" + sleep 10 + gh project item-edit --id "$TICKET_ID" --field-id PVTSSF_lADOAYE_z84AWEIBzgOGd1k --project-id PVT_kwDOAYE_z84AWEIB --single-select-option-id "fa223107" + env: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + ISSUE_URL: ${{ inputs.ISSUE_URL }} + ISSUE_NUMBER: ${{ inputs.ISSUE_NUMBER }} + REPOSITORY: ${{ inputs.REPOSITORY }} + shell: bash diff --git a/.github/actions/create_label/action.yml b/.github/actions/create_label/action.yml new file mode 100644 index 000000000..2bbc19cca --- /dev/null +++ b/.github/actions/create_label/action.yml @@ -0,0 +1,14 @@ +name: 'Create label' +description: 'Creates a label closed-by-membrane-bot, if it does not exist.' +inputs: + GITHUB_TOKEN: + description: 'GitHub token' + required: true +runs: + using: 'composite' + steps: + - run: | + gh label create closed-by-membrane-bot --description "Automatically closed by Membrane bot" --color EB3467 || true + env: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + shell: bash diff --git a/.github/workflows/update-packages-list.yml b/.github/workflows/update-packages-list.yml index 728c9a42c..bbbb0bf7a 100644 --- a/.github/workflows/update-packages-list.yml +++ b/.github/workflows/update-packages-list.yml @@ -18,7 +18,7 @@ jobs: env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} run: | - elixir update_packages_list.exs + elixir scripts/update_packages_list.exs git config user.name 'Membrane Bot' git config user.email 'bot@membrane.stream' git checkout -B auto-update-packages-list diff --git a/scripts/get_ticket_id.exs b/scripts/get_ticket_id.exs new file mode 100644 index 000000000..4172d5b0f --- /dev/null +++ b/scripts/get_ticket_id.exs @@ -0,0 +1,14 @@ +# This script is used by .github/actions/close_issue/action.yml and it shouldn't be used in any other places. + +Mix.install(json: "~> 1.4.1") + +[issue_url] = System.argv() + +:ok = + IO.read(:stdio, :eof) + |> JSON.decode!() + |> Map.get("items") + |> Enum.find(&(&1["content"]["url"] == issue_url)) + |> Map.get("id") + |> then(&"\nTICKET_ID #{&1}\n") + |> IO.puts() diff --git a/update_packages_list.exs b/scripts/update_packages_list.exs similarity index 100% rename from update_packages_list.exs rename to scripts/update_packages_list.exs From 35fec8bba2d653e681cfb1bd0f33a903290d8b10 Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Sat, 14 Oct 2023 15:19:04 +0200 Subject: [PATCH 2/3] Add more descritpion, what get_ticket_id.exs does --- scripts/get_ticket_id.exs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/get_ticket_id.exs b/scripts/get_ticket_id.exs index 4172d5b0f..5acc0ea61 100644 --- a/scripts/get_ticket_id.exs +++ b/scripts/get_ticket_id.exs @@ -1,5 +1,14 @@ # This script is used by .github/actions/close_issue/action.yml and it shouldn't be used in any other places. +# It expects: +# - output from `$ gh project item-list --owner --format json --limit ` command +# on standard input +# - URL of issue, that corresponds to one of the tickets included in the JSON data returned from the command +# above. This URL should be passed as an argument in argv +# And prints `TICKET_ID ` on standard output, where `` is id of a project item corresponding to the +# issue with the specified URL. Note, that beyond this, stdout can also contain some logs from `Mix.install/1`, +# e.g. `Resolving Hex dependencies...`. + Mix.install(json: "~> 1.4.1") [issue_url] = System.argv() From c0e29a35e532fc010befbfc86c92fa04f8c77167 Mon Sep 17 00:00:00 2001 From: "feliks.pobiedzinski@swmansion.com" Date: Mon, 16 Oct 2023 12:13:51 +0200 Subject: [PATCH 3/3] Refactor GH action due to CR comment --- .github/actions/close_issue/action.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/actions/close_issue/action.yml b/.github/actions/close_issue/action.yml index 8a25447b2..da6d03036 100644 --- a/.github/actions/close_issue/action.yml +++ b/.github/actions/close_issue/action.yml @@ -25,12 +25,21 @@ runs: uses: actions/checkout@v3 - name: Create ticket and close issue run: | + export PROJECT_NUMBER=19 + export PROJECT_ID=PVT_kwDOAYE_z84AWEIB + export STATUS_FIELD_ID=PVTSSF_lADOAYE_z84AWEIBzgOGd1k + export TARGET_COLUMN_ID=fa223107 + export CORE_URL=https://github.com/membraneframework/membrane_core + export ISSUE_CLOSE_COMMENT="Issues related to $REPOSITORY are stored in [membrane_core]($CORE_URL), so we close this issue here and we encourage you to open it [there]($CORE_URL) with labels describing, which repositories relate to the issue." + gh issue edit $ISSUE_URL --add-project "Smackore" --add-label closed-by-membrane-bot sleep 10 - export TICKET_ID=$(gh project item-list 19 --owner membraneframework --format json --limit 10000000 | elixir get_ticket_id.exs "$ISSUE_URL" | awk '/TICKET_ID/{print $2}') - gh issue close $ISSUE_URL --comment "Only PRs welcome ;)" --reason "not planned" + + export TICKET_ID=$(gh project item-list $PROJECT_NUMBER --owner membraneframework --format json --limit 10000000 | elixir get_ticket_id.exs "$ISSUE_URL" | awk '/TICKET_ID/{print $2}') + gh issue close $ISSUE_URL --comment "$ISSUE_CLOSE_COMMENT" --reason "not planned" sleep 10 - gh project item-edit --id "$TICKET_ID" --field-id PVTSSF_lADOAYE_z84AWEIBzgOGd1k --project-id PVT_kwDOAYE_z84AWEIB --single-select-option-id "fa223107" + + gh project item-edit --id $TICKET_ID --field-id $STATUS_FIELD_ID --project-id $PROJECT_ID --single-select-option-id $TARGET_COLUMN_ID env: GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} ISSUE_URL: ${{ inputs.ISSUE_URL }}