diff --git a/.github/workflows/issue-regression-labeler.yml b/.github/workflows/issue-regression-labeler.yml index adecdbc6283..000d1076631 100644 --- a/.github/workflows/issue-regression-labeler.yml +++ b/.github/workflows/issue-regression-labeler.yml @@ -9,24 +9,29 @@ jobs: permissions: issues: write steps: - - name: Fetch template body - id: check_regression - uses: actions/github-script@v7 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TEMPLATE_BODY: ${{ github.event.issue.body }} + - name: Check and manage regression label + uses: actions/github-script@v9 with: script: | + const body = context.payload.issue.body || ''; const regressionPattern = /\[x\] Select this option if this issue appears to be a regression\./i; - const template = `${process.env.TEMPLATE_BODY}` - const match = regressionPattern.test(template); - core.setOutput('is_regression', match); - - name: Manage regression label - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - if [ "${{ steps.check_regression.outputs.is_regression }}" == "true" ]; then - gh issue edit ${{ github.event.issue.number }} --add-label "potential-regression" -R ${{ github.repository }} - else - gh issue edit ${{ github.event.issue.number }} --remove-label "potential-regression" -R ${{ github.repository }} - fi \ No newline at end of file + const isRegression = regressionPattern.test(body); + const issueNumber = context.payload.issue.number; + + if (isRegression) { + await github.rest.issues.addLabels({ + ...context.repo, + issue_number: issueNumber, + labels: ['potential-regression'], + }); + } else { + try { + await github.rest.issues.removeLabel({ + ...context.repo, + issue_number: issueNumber, + name: 'potential-regression', + }); + } catch (e) { + if (e.status !== 404) throw e; + } + } diff --git a/.github/workflows/slack.yml b/.github/workflows/slack.yml index f0a8287c6d3..f912fe304b6 100644 --- a/.github/workflows/slack.yml +++ b/.github/workflows/slack.yml @@ -19,53 +19,81 @@ jobs: if: github.event_name == 'issues' && github.event.action == 'opened' steps: - name: notify + uses: actions/github-script@v9 env: - ISSUE_TITLE: ${{ github.event.issue.title }} - run: | - curl \ - -X POST \ - -H 'Content-Type: application/json' \ - -d '{"type": "issues_opened", "id": "${{ github.event.issue.number }}", "title": "'"$ISSUE_TITLE"'"}' \ - ${{ secrets.CI_SLACK_WEBHOOK_URL }} + WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }} + with: + script: | + const resp = await fetch(process.env.WEBHOOK_URL, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + type: 'issues_opened', + id: String(context.payload.issue.number), + title: context.payload.issue.title, + }), + }); + if (!resp.ok) core.setFailed(`Slack webhook returned ${resp.status}`); on-issue-closed: runs-on: ubuntu-latest if: github.event_name == 'issues' && github.event.action == 'closed' steps: - name: notify + uses: actions/github-script@v9 env: - ISSUE_TITLE: ${{ github.event.issue.title }} - run: | - curl \ - -X POST \ - -H 'Content-Type: application/json' \ - -d '{"type": "issues_closed", "id": "${{ github.event.issue.number }}", "title": "'"$ISSUE_TITLE"'"}' \ - ${{ secrets.CI_SLACK_WEBHOOK_URL }} + WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }} + with: + script: | + const resp = await fetch(process.env.WEBHOOK_URL, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + type: 'issues_closed', + id: String(context.payload.issue.number), + title: context.payload.issue.title, + }), + }); + if (!resp.ok) core.setFailed(`Slack webhook returned ${resp.status}`); on-pr-opened: runs-on: ubuntu-latest if: github.event_name == 'pull_request' && github.event.action == 'opened' steps: - name: notify + uses: actions/github-script@v9 env: - PR_TITLE: ${{ github.event.pull_request.title }} - run: | - curl \ - -X POST \ - -H 'Content-Type: application/json' \ - -d '{"type": "pullrequest_opened", "id": "${{ github.event.pull_request.number }}", "title": "'"$PR_TITLE"'"}' \ - ${{ secrets.CI_SLACK_WEBHOOK_URL }} + WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }} + with: + script: | + const resp = await fetch(process.env.WEBHOOK_URL, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + type: 'pullrequest_opened', + id: String(context.payload.pull_request.number), + title: context.payload.pull_request.title, + }), + }); + if (!resp.ok) core.setFailed(`Slack webhook returned ${resp.status}`); on-pr-closed: runs-on: ubuntu-latest if: github.event_name == 'pull_request' && github.event.action == 'closed' steps: - name: notify + uses: actions/github-script@v9 env: - PR_TITLE: ${{ github.event.pull_request.title }} - run: | - curl \ - -X POST \ - -H 'Content-Type: application/json' \ - -d '{"type": "pullrequest_closed", "id": "${{ github.event.pull_request.number }}", "title": "'"$PR_TITLE"'"}' \ - ${{ secrets.CI_SLACK_WEBHOOK_URL }} + WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }} + with: + script: | + const resp = await fetch(process.env.WEBHOOK_URL, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + type: 'pullrequest_closed', + id: String(context.payload.pull_request.number), + title: context.payload.pull_request.title, + }), + }); + if (!resp.ok) core.setFailed(`Slack webhook returned ${resp.status}`);