From b34897241ea9255a73fed92905d1629ffbfe5540 Mon Sep 17 00:00:00 2001 From: Ben M Date: Mon, 3 Apr 2023 13:39:44 -0400 Subject: [PATCH] chore: created a new github action to handle new comments better (#26234) * chore: created a new github action to handle new comments better --------- Co-authored-by: Emily Rohrbough Co-authored-by: Matt Schile --- .../triage_add_stale_issue_to_board.yml | 23 ---- .../workflows/triage_closed_issue_comment.yml | 104 ------------------ .../workflows/triage_handle_new_comments.yml | 32 ++++++ 3 files changed, 32 insertions(+), 127 deletions(-) delete mode 100644 .github/workflows/triage_add_stale_issue_to_board.yml delete mode 100644 .github/workflows/triage_closed_issue_comment.yml create mode 100644 .github/workflows/triage_handle_new_comments.yml diff --git a/.github/workflows/triage_add_stale_issue_to_board.yml b/.github/workflows/triage_add_stale_issue_to_board.yml deleted file mode 100644 index 1d7e2a93cf71..000000000000 --- a/.github/workflows/triage_add_stale_issue_to_board.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: 'Add stale issue/PR to Triage Board' -on: - issues: - types: [labeled] - pull_request: - types: [labeled] - -jobs: - add-to-triage-project-board: - if: >- - ( - contains(github.event.pull_request.labels.*.name, 'stale') || - contains(github.event.issue.labels.*.name, 'stale') - ) - uses: cypress-io/cypress/.github/workflows/triage_add_to_project.yml@develop - secrets: inherit - update-status-to-awaiting-response: - needs: add-to-triage-project-board - uses: cypress-io/cypress/.github/workflows/triage_update_status.yml@develop - with: - status: 'Awaiting Response' - secrets: inherit - diff --git a/.github/workflows/triage_closed_issue_comment.yml b/.github/workflows/triage_closed_issue_comment.yml deleted file mode 100644 index fcc26b44118b..000000000000 --- a/.github/workflows/triage_closed_issue_comment.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: 'Triage: closed issue comment' -on: - # makes this workflow reusable - workflow_call: - secrets: - ADD_TO_TRIAGE_BOARD_TOKEN: - required: true - issue_comment: - types: [created] - issues: - types: [closed] -jobs: - move-to-new-issue-status: - runs-on: ubuntu-latest - steps: - - name: Make sure comment was added more than 20 seconds after issue closed - run: | - time_diff=$(($(date +%s -d "${{ github.event.comment.created_at }}" ) - $(date +%s -d "${{ github.event.issue.closed_at }}" ))) - echo 'COMMENT_ADDED_AFTER_CLOSE='$(($time_diff > 20)) >> $GITHUB_ENV - - - name: Get project data - env: - GITHUB_TOKEN: ${{ secrets.ADD_TO_TRIAGE_BOARD_TOKEN }} - ORGANIZATION: 'cypress-io' - REPOSITORY: ${{ github.event.repository.name }} - PROJECT_NUMBER: 9 - ISSUE_NUMBER: ${{ github.event.issue.number }} - if: | - env.COMMENT_ADDED_AFTER_CLOSE == '1' && - github.event.sender.login != 'cypress-bot[bot]' && - github.event.sender.login != 'github-actions[bot]' && - github.event.issue.pull_request == null - run: | - gh api graphql -f query=' - query($org: String!, $repo: String!, $project: Int!, $issue: Int!) { - organization(login: $org) { - repository(name: $repo) { - issue(number: $issue) { - projectItems(first: 10, includeArchived: false) { - nodes { - id - fieldValueByName(name: "Status") { - ... on ProjectV2ItemFieldSingleSelectValue { - name - field { - ... on ProjectV2SingleSelectField { - project { - ... on ProjectV2 { - id - number - } - } - } - } - } - } - } - } - } - } - projectV2(number: $project) { - field(name: "Status") { - ... on ProjectV2SingleSelectField { - id - options { - id - name - } - } - } - } - } - }' -f org=$ORGANIZATION -f repo=$REPOSITORY -F issue=$ISSUE_NUMBER -F project=$PROJECT_NUMBER > project_data.json - - echo 'PROJECT_ID='$(jq -r '.data.organization.repository.issue.projectItems.nodes[].fieldValueByName.field.project | select(.number == ${{ env.PROJECT_NUMBER }}) | .id' project_data.json) >> $GITHUB_ENV - echo 'PROJECT_ITEM_ID='$(jq -r '.data.organization.repository.issue.projectItems.nodes[] | select(.fieldValueByName.field.project.number == ${{ env.PROJECT_NUMBER }}) | .id' project_data.json) >> $GITHUB_ENV - echo 'STATUS_FIELD_ID='$(jq -r '.data.organization.projectV2.field | .id' project_data.json) >> $GITHUB_ENV - echo 'STATUS='$(jq -r '.data.organization.repository.issue.projectItems.nodes[].fieldValueByName | select(.field.project.number == ${{ env.PROJECT_NUMBER }}) | .name' project_data.json) >> $GITHUB_ENV - echo 'NEW_ISSUE_OPTION_ID='$(jq -r '.data.organization.projectV2.field.options[] | select(.name== "New Issue") | .id' project_data.json) >> $GITHUB_ENV - - name: Move issue to New Issue status - env: - GITHUB_TOKEN: ${{ secrets.ADD_TO_TRIAGE_BOARD_TOKEN }} - if: env.STATUS == 'Closed' - run: | - gh api graphql -f query=' - mutation ( - $project: ID! - $item: ID! - $status_field: ID! - $status_value: String! - ) { - updateProjectV2ItemFieldValue(input: { - projectId: $project - itemId: $item - fieldId: $status_field - value: { - singleSelectOptionId: $status_value - } - }) { - projectV2Item { - id - } - } - }' -f project=$PROJECT_ID -f item=$PROJECT_ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$NEW_ISSUE_OPTION_ID diff --git a/.github/workflows/triage_handle_new_comments.yml b/.github/workflows/triage_handle_new_comments.yml new file mode 100644 index 000000000000..f2b2dbce4ac9 --- /dev/null +++ b/.github/workflows/triage_handle_new_comments.yml @@ -0,0 +1,32 @@ +name: 'Handle Issue/PR Comment Workflow' +on: + # makes this workflow reusable + workflow_call: + secrets: + TRIAGE_BOARD_TOKEN: + required: true + + issue_comment: + types: [created] + +jobs: + handle-comment-scenarios: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + repository: 'cypress-io/release-automations' + ref: 'master' + ssh-key: ${{ secrets.WORKFLOW_DEPLOY_KEY }} + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' + - name: Run comment_workflow.js Script + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.TRIAGE_BOARD_TOKEN }} + script: | + const script = require('./scripts/triage/comment_workflow.js') + await script.handleComment(github, context);