|
| 1 | +name: First responder docs-content |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [reopened, opened, ready_for_review, unlabeled] |
| 5 | + |
| 6 | +jobs: |
| 7 | + first-responder-triage: |
| 8 | + if: github.repository == 'github/docs-internal' && github.event.pull_request.draft == false && github.event.action != 'unlabeled' |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Check if the event originated from a team member |
| 13 | + uses: actions/github-script@v2.0.0 |
| 14 | + id: set-result |
| 15 | + with: |
| 16 | + github-token: ${{secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES}} |
| 17 | + result-encoding: string |
| 18 | + script: | |
| 19 | + const repoName = context.payload.repository.name |
| 20 | + const ownerName = context.payload.repository.owner.login |
| 21 | + const issueNumber = (context.eventName === "issues") ? context.payload.issue.number : context.payload.number |
| 22 | + const updatedIssueInformation = await github.issues.get({ |
| 23 | + owner: ownerName, |
| 24 | + repo: repoName, |
| 25 | + issue_number: issueNumber |
| 26 | + }) |
| 27 | + const teamMembers = await github.request( |
| 28 | + `/orgs/github/teams/docs/members` |
| 29 | + ) |
| 30 | + const logins = teamMembers.data.map(member => member.login) |
| 31 | + if (logins.some(login => login === updatedIssueInformation.data.user.login)) { |
| 32 | + console.log(`This issue or pull request was authored by a member of the github/docs team.`) |
| 33 | + return 'true' |
| 34 | + } |
| 35 | + console.log(`This issue or pull request was authored by an external contributor.`) |
| 36 | + return 'false' |
| 37 | + - name: Label external contributor pull requests with docs-content-fr |
| 38 | + uses: rachmari/labeler@v1.0.4 |
| 39 | + if: steps.set-result.outputs.result == 'false' |
| 40 | + with: |
| 41 | + repo-token: "${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}" |
| 42 | + add-labels: "docs-content-fr" |
| 43 | + - name: Triage to FR PR project column |
| 44 | + uses: rachmari/actions-add-new-issue-to-column@v1.1.1 |
| 45 | + if: steps.set-result.outputs.result == 'false' |
| 46 | + with: |
| 47 | + action-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }} |
| 48 | + project-url: "https://github.com/orgs/github/projects/1367" |
| 49 | + column-name: "Docs-internal external contributor PRs" |
| 50 | + |
| 51 | + first-responder-label-removed: |
| 52 | + if: github.event.label.name == 'docs-content-fr' && github.event.action == 'unlabeled' |
| 53 | + runs-on: ubuntu-latest |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Dump GitHub context |
| 57 | + env: |
| 58 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 59 | + run: echo "$GITHUB_CONTEXT" |
| 60 | + - name: Remove card from project |
| 61 | + uses: actions/github-script@v2.0.0 |
| 62 | + with: |
| 63 | + github-token: ${{secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES}} |
| 64 | + result-encoding: string |
| 65 | + script: | |
| 66 | + const issueToRemove = context.payload.number |
| 67 | + const cards = await github.projects.listCards({ |
| 68 | + column_id: 11130889 |
| 69 | + }) |
| 70 | + cards.data.forEach(card => { |
| 71 | + if (card.content_url) { |
| 72 | + const cardIssueNumber = parseInt(card.content_url.split('/').pop(), 10) |
| 73 | + if (cardIssueNumber === issueToRemove) { |
| 74 | + const cards = github.projects.deleteCard({ |
| 75 | + card_id: card.id |
| 76 | + }) |
| 77 | + } |
| 78 | + } |
| 79 | + }) |
0 commit comments