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 <emilyrohrbough@users.noreply.github.com>
Co-authored-by: Matt Schile <mschile@cypress.io>
This commit is contained in:
Ben M
2023-04-03 13:39:44 -04:00
committed by GitHub
parent 1c385e0d42
commit b34897241e
3 changed files with 32 additions and 127 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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);