|
| 1 | +name: Move pull requests asking for review to the relevant project |
| 2 | +on: |
| 3 | + pull_request_target: |
| 4 | + types: [review_requested] |
| 5 | + |
| 6 | +jobs: |
| 7 | + add_design_pr_to_project: |
| 8 | + name: Move PRs asking for design review to the design board |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + |
| 12 | + id: find_team_members |
| 13 | + with: |
| 14 | + headers: '{"GraphQL-Features": "projects_next_graphql"}' |
| 15 | + query: | |
| 16 | + query find_team_members($team: String!) { |
| 17 | + organization(login: "vector-im") { |
| 18 | + team(slug: $team) { |
| 19 | + members { |
| 20 | + nodes { |
| 21 | + login |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + } |
| 27 | + team: ${{ env.TEAM }} |
| 28 | + env: |
| 29 | + TEAM: "design" |
| 30 | + GITHUB_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }} |
| 31 | + - id: any_matching_reviewers |
| 32 | + run: | |
| 33 | + # Fetch requested reviewers, and people who are on the team |
| 34 | + echo '${{ tojson(fromjson(steps.find_team_members.outputs.data).organization.team.members.nodes[*].login) }}' | tee /tmp/team_members.json |
| 35 | + echo '${{ tojson(github.event.pull_request.requested_reviewers[*].login) }}' | tee /tmp/reviewers.json |
| 36 | + jq --raw-output .[] < /tmp/team_members.json | sort | tee /tmp/team_members.txt |
| 37 | + jq --raw-output .[] < /tmp/reviewers.json | sort | tee /tmp/reviewers.txt |
| 38 | +
|
| 39 | + # Fetch requested team reviewers, and the name of the team |
| 40 | + echo '${{ tojson(github.event.pull_request.requested_teams[*].slug) }}' | tee /tmp/team_reviewers.json |
| 41 | + jq --raw-output .[] < /tmp/team_reviewers.json | sort | tee /tmp/team_reviewers.txt |
| 42 | + echo '${{ env.TEAM }}' | tee /tmp/team.txt |
| 43 | +
|
| 44 | + # If either a reviewer matches a team member, or a team matches our team, say "true" |
| 45 | + if [ $(join /tmp/team_members.txt /tmp/reviewers.txt | wc -l) != 0 ]; then |
| 46 | + echo "::set-output name=match::true" |
| 47 | + elif [ $(join /tmp/team.txt /tmp/team_reviewers.txt | wc -l) != 0 ]; then |
| 48 | + echo "::set-output name=match::true" |
| 49 | + else |
| 50 | + echo "::set-output name=match::false" |
| 51 | + fi |
| 52 | + env: |
| 53 | + TEAM: "design" |
| 54 | + |
| 55 | + id: add_to_project |
| 56 | + if: steps.any_matching_reviewers.outputs.match == 'true' |
| 57 | + with: |
| 58 | + headers: '{"GraphQL-Features": "projects_next_graphql"}' |
| 59 | + query: | |
| 60 | + mutation add_to_project($projectid:ID!, $contentid:ID!) { |
| 61 | + addProjectNextItem(input:{projectId:$projectid contentId:$contentid}) { |
| 62 | + projectNextItem { |
| 63 | + id |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + projectid: ${{ env.PROJECT_ID }} |
| 68 | + contentid: ${{ github.event.pull_request.node_id }} |
| 69 | + env: |
| 70 | + PROJECT_ID: "PN_kwDOAM0swc0sUA" |
| 71 | + TEAM: "design" |
| 72 | + GITHUB_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }} |
| 73 | + |
| 74 | + add_product_pr_to_project: |
| 75 | + name: Move PRs asking for product review to the product board |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + |
| 79 | + id: find_team_members |
| 80 | + with: |
| 81 | + headers: '{"GraphQL-Features": "projects_next_graphql"}' |
| 82 | + query: | |
| 83 | + query find_team_members($team: String!) { |
| 84 | + organization(login: "vector-im") { |
| 85 | + team(slug: $team) { |
| 86 | + members { |
| 87 | + nodes { |
| 88 | + login |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + team: ${{ env.TEAM }} |
| 95 | + env: |
| 96 | + TEAM: "product" |
| 97 | + GITHUB_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }} |
| 98 | + - id: any_matching_reviewers |
| 99 | + run: | |
| 100 | + # Fetch requested reviewers, and people who are on the team |
| 101 | + echo '${{ tojson(fromjson(steps.find_team_members.outputs.data).organization.team.members.nodes[*].login) }}' | tee /tmp/team_members.json |
| 102 | + echo '${{ tojson(github.event.pull_request.requested_reviewers[*].login) }}' | tee /tmp/reviewers.json |
| 103 | + jq --raw-output .[] < /tmp/team_members.json | sort | tee /tmp/team_members.txt |
| 104 | + jq --raw-output .[] < /tmp/reviewers.json | sort | tee /tmp/reviewers.txt |
| 105 | +
|
| 106 | + # Fetch requested team reviewers, and the name of the team |
| 107 | + echo '${{ tojson(github.event.pull_request.requested_teams[*].slug) }}' | tee /tmp/team_reviewers.json |
| 108 | + jq --raw-output .[] < /tmp/team_reviewers.json | sort | tee /tmp/team_reviewers.txt |
| 109 | + echo '${{ env.TEAM }}' | tee /tmp/team.txt |
| 110 | +
|
| 111 | + # If either a reviewer matches a team member, or a team matches our team, say "true" |
| 112 | + if [ $(join /tmp/team_members.txt /tmp/reviewers.txt | wc -l) != 0 ]; then |
| 113 | + echo "::set-output name=match::true" |
| 114 | + elif [ $(join /tmp/team.txt /tmp/team_reviewers.txt | wc -l) != 0 ]; then |
| 115 | + echo "::set-output name=match::true" |
| 116 | + else |
| 117 | + echo "::set-output name=match::false" |
| 118 | + fi |
| 119 | + env: |
| 120 | + TEAM: "product" |
| 121 | + |
| 122 | + id: add_to_project |
| 123 | + if: steps.any_matching_reviewers.outputs.match == 'true' |
| 124 | + with: |
| 125 | + headers: '{"GraphQL-Features": "projects_next_graphql"}' |
| 126 | + query: | |
| 127 | + mutation add_to_project($projectid:ID!, $contentid:ID!) { |
| 128 | + addProjectNextItem(input:{projectId:$projectid contentId:$contentid}) { |
| 129 | + projectNextItem { |
| 130 | + id |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + projectid: ${{ env.PROJECT_ID }} |
| 135 | + contentid: ${{ github.event.pull_request.node_id }} |
| 136 | + env: |
| 137 | + PROJECT_ID: "PN_kwDOAM0swc4AAg6N" |
| 138 | + TEAM: "product" |
| 139 | + GITHUB_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }} |
0 commit comments