From c50ea2a61b22675ce7e918432fb9b8c5efe6e117 Mon Sep 17 00:00:00 2001 From: Fabio Turizo Date: Tue, 12 Sep 2023 14:34:45 -0500 Subject: [PATCH 1/2] Initial commit of GH action for community PR assignment. --- .github/workflows/assign-community-prs.yaml | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/assign-community-prs.yaml diff --git a/.github/workflows/assign-community-prs.yaml b/.github/workflows/assign-community-prs.yaml new file mode 100644 index 00000000000..a5b78bf4d37 --- /dev/null +++ b/.github/workflows/assign-community-prs.yaml @@ -0,0 +1,29 @@ +name: Agent Assignment +on: + pull_request: + types: + - opened +jobs: + assign-frontline-engineer: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Get Team Members + id: team-members + env: + frontLine: ${{ vars.FRONT_LINE_USERS_LIST }} + #TODO - Temporary solution - team member configuration should be dynamic + run: | + echo "::set-output name=members::$frontLine" + - name: Get Next Team Member + id: next-member + run: | + members=($(echo "${{ steps.team-members.outputs.members }}" | tr ',' '\n')) + index=$(( (${GITHUB_RUN_NUMBER}-1) % ${#members[@]} )) + next_member=${members[$index]} + echo "::set-output name=next_member::$next_member" + - env: + EVENT_CONTEXT: ${{ toJSON(github.event) }} + run: | + echo $EVENT_CONTEXT From 87696152a2e0333151650e984b58e6fbc55d335d Mon Sep 17 00:00:00 2001 From: Fabio Turizo Date: Fri, 15 Sep 2023 14:16:51 -0500 Subject: [PATCH 2/2] Complete workflow file for community PRs assignment job --- .github/workflows/assign-community-prs.yaml | 52 ++++++++++++++------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/.github/workflows/assign-community-prs.yaml b/.github/workflows/assign-community-prs.yaml index a5b78bf4d37..b9e9a2fb418 100644 --- a/.github/workflows/assign-community-prs.yaml +++ b/.github/workflows/assign-community-prs.yaml @@ -1,29 +1,49 @@ -name: Agent Assignment +name: Agent Assignment to Community Contributions on: - pull_request: + pull_request_target: types: - opened + - reopened jobs: - assign-frontline-engineer: + assign-front-line-engineer: runs-on: ubuntu-latest + #Conditionally runs the job if the author of the PR is not an owner or member of the organisation + #See https://docs.github.com/en/graphql/reference/enums#commentauthorassociation + if: github.event.pull_request.author_association != 'OWNER' && github.event.pull_request.author_association != 'MEMBER' permissions: pull-requests: write + env: + PR_URL: ${{ github.event.pull_request.html_url }} + PR_TITLE: ${{ github.event.pull_request.title }} steps: - - name: Get Team Members - id: team-members + - name: Get Next Assignee + id: get-next-assignee env: - frontLine: ${{ vars.FRONT_LINE_USERS_LIST }} - #TODO - Temporary solution - team member configuration should be dynamic + FRONT_LINE: ${{ vars.FRONT_LINE_USERS_LIST }} run: | - echo "::set-output name=members::$frontLine" - - name: Get Next Team Member - id: next-member - run: | - members=($(echo "${{ steps.team-members.outputs.members }}" | tr ',' '\n')) + if [ -z $FRONT_LINE ]; then + echo "::error::'FRONT_LINE_USERS_LIST' environment variable is not set" + exit 1 + fi + members=($(echo $FRONT_LINE | tr ',' '\n')) index=$(( (${GITHUB_RUN_NUMBER}-1) % ${#members[@]} )) next_member=${members[$index]} - echo "::set-output name=next_member::$next_member" - - env: - EVENT_CONTEXT: ${{ toJSON(github.event) }} + echo "SELECTED_ASSIGNEE=$next_member" >> "$GITHUB_ENV" + - name: Assign selected member + id: assign-selected-member + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: success() run: | - echo $EVENT_CONTEXT + echo "::debug::Selected assignee: $SELECTED_ASSIGNEE" + gh pr edit $PR_URL --add-assignee $SELECTED_ASSIGNEE + - name: Notify MS Teams channel + id: notify-ms-teams + if: success() + uses: simbo/msteams-message-card-action@latest + with: + webhook: ${{ secrets.COMMUNITY_EVENTS_WEBHOOK_URL }} + title: A new Community Contribution has been raised (or re-opened)! + message: ${{ env.PR_TITLE }} assigned to ${{ env.SELECTED_ASSIGNEE }} + buttons: | + View PR on GitHub ${{ env.PR_URL }}