diff --git a/.formatter.exs b/.formatter.exs index cce53f36f..9cf8cc2e6 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -10,8 +10,7 @@ locals_without_parens = [ inputs: [ - "{lib,test,config,benchmark}/**/*.{ex,exs}", - "scripts/*.exs", + "{lib,test,config,benchmark,scripts}/**/*.{ex,exs}", "*.exs" ], locals_without_parens: locals_without_parens, diff --git a/.github/actions/add_pr_to_smackore_board/action.yml b/.github/actions/add_pr_to_smackore_board/action.yml new file mode 100644 index 000000000..f5a676067 --- /dev/null +++ b/.github/actions/add_pr_to_smackore_board/action.yml @@ -0,0 +1,42 @@ +name: 'Add PR to Smackore board, if author is from community' +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' + required: true + AUTHOR_LOGIN: + description: 'PR author login' + required: true + PR_URL: + description: 'PR URL' + required: true +runs: + using: 'composite' + steps: + - name: Checkout membrane_core code + uses: actions/checkout@v3 + with: + repository: membraneframework/membrane_core + - name: Maybe add PR to board and set ticket status + run: | + 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=$(curl --request GET --url "https://api.github.com/orgs/membraneframework/members" --header "Authorization: Bearer $GH_TOKEN" -s | python scripts/python/get_author_origin.py $AUTHOR_LOGIN) + + 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 + + env: + GH_TOKEN: ${{ inputs.GITHUB_TOKEN }} + AUTHOR_LOGIN: ${{ inputs.AUTHOR_LOGIN }} + PR_URL: ${{ inputs.PR_URL }} + shell: bash diff --git a/.github/actions/close_issue/action.yml b/.github/actions/close_issue/action.yml index 8672d55cf..0367e199b 100644 --- a/.github/actions/close_issue/action.yml +++ b/.github/actions/close_issue/action.yml @@ -37,7 +37,7 @@ runs: gh issue edit $ISSUE_URL --add-project "Smackore" sleep 10 - export TICKET_ID=$(gh project item-list $PROJECT_NUMBER --owner membraneframework --format json --limit 10000000 | elixir ./scripts/get_ticket_id.exs "$ISSUE_URL" | awk '/TICKET_ID/{print $2}') + export TICKET_ID=$(gh project item-list $PROJECT_NUMBER --owner membraneframework --format json --limit 10000000 | python ./scripts/python/get_ticket_id.py "$ISSUE_URL") gh issue close $ISSUE_URL --comment "$ISSUE_CLOSE_COMMENT" --reason "not planned" sleep 10 diff --git a/.github/workflows/update-packages-list.yml b/.github/workflows/update-packages-list.yml index bbbb0bf7a..37ceb52a6 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 scripts/update_packages_list.exs + elixir scripts/elixir/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/README.md b/README.md index 4f9c445e3..10478d109 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ If you have any questions regarding Membrane Framework or need consulting, feel ## All packages - + ### General diff --git a/scripts/update_packages_list.exs b/scripts/elixir/update_packages_list.exs similarity index 98% rename from scripts/update_packages_list.exs rename to scripts/elixir/update_packages_list.exs index 31c532bfa..1f957d702 100644 --- a/scripts/update_packages_list.exs +++ b/scripts/elixir/update_packages_list.exs @@ -270,7 +270,7 @@ packages_md = packages_md = """ - + #{packages_md} diff --git a/scripts/get_ticket_id.exs b/scripts/get_ticket_id.exs deleted file mode 100644 index 5acc0ea61..000000000 --- a/scripts/get_ticket_id.exs +++ /dev/null @@ -1,23 +0,0 @@ -# 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() - -: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/scripts/python/get_author_origin.py b/scripts/python/get_author_origin.py new file mode 100644 index 000000000..2f8eb6bd7 --- /dev/null +++ b/scripts/python/get_author_origin.py @@ -0,0 +1,12 @@ +import sys, json; + +membrane_team = json.load(sys.stdin) +pr_author = sys.argv[1] + +for person in membrane_team: + if person["login"] == pr_author: + print("MEMBRANE") + sys.exit(0) + +print("COMMUNITY") + diff --git a/scripts/python/get_ticket_id.py b/scripts/python/get_ticket_id.py new file mode 100644 index 000000000..e9660ed6b --- /dev/null +++ b/scripts/python/get_ticket_id.py @@ -0,0 +1,6 @@ +import sys, json; + +project_items = json.load(sys.stdin)["items"] +pr_url = sys.argv[1] +[id] = [item["id"] for item in project_items if item["content"]["url"] == pr_url] +print(id)