From 1018742d3c719e041af461cffe6b1f5de2840660 Mon Sep 17 00:00:00 2001 From: asyncapi-bot <61865014+asyncapi-bot@users.noreply.github.com> Date: Mon, 10 Jan 2022 14:43:41 +0100 Subject: [PATCH] ci: update global workflows --- .../workflows/add-good-first-issue-labels.yml | 68 +++++++++++++++++++ .github/workflows/help-command.yml | 23 +++++-- 2 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/add-good-first-issue-labels.yml diff --git a/.github/workflows/add-good-first-issue-labels.yml b/.github/workflows/add-good-first-issue-labels.yml new file mode 100644 index 00000000..3b816b63 --- /dev/null +++ b/.github/workflows/add-good-first-issue-labels.yml @@ -0,0 +1,68 @@ +#This workflow is centrally managed in https://github.com/asyncapi/.github/ +#Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo + +#Purpose of this workflow is to enable anyone to label issue with 'Good First Issue' and 'area/*' with a single command. +name: Add 'Good First Issue' and 'area/*' labels # if proper comment added + +on: + issue_comment: + types: + - created + +jobs: + add-labels: + if: github.event.issue && github.event.issue.state != 'closed' + runs-on: ubuntu-latest + steps: + - name: Add label + if: contains(github.event.comment.body, '/good-first-issue') || contains(github.event.comment.body, '/gfi' ) + uses: actions/github-script@v5 + with: + github-token: ${{ secrets.GH_TOKEN }} + script: | + const areas = ['javascript', 'typescript', 'java' , 'go', 'docs', 'ci-cd', 'design']; + const values = context.payload.comment.body.split(" "); + switch(values[1]){ + case 'ts': + values[1] = 'typescript'; + break; + case 'js': + values[1] = 'javascript'; + case 'markdown': + values[1] = 'docs'; + } + if(values.length != 2 || !areas.includes(values[1])){ + const message = `Hey @${context.payload.sender.login}, something is wrong with your command please use \`/help\` for help.` + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: message + }) + } else { + + //remove complexity and areas if there are any before adding new labels; + const currentLabels = (await github.rest.issues.listLabelsOnIssue({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + })).data.map(label => label.name); + + const shouldBeRemoved = currentLabels.filter(label => (label.startsWith('area/') && !label.endsWith(values[1]))); + shouldBeRemoved.forEach(label => { + github.rest.issues.deleteLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: label, + }); + }); + + //add new labels + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['good first issue', `area/${values[1]}`] + }); + } diff --git a/.github/workflows/help-command.yml b/.github/workflows/help-command.yml index 0fac866f..eee77301 100644 --- a/.github/workflows/help-command.yml +++ b/.github/workflows/help-command.yml @@ -9,12 +9,11 @@ on: - created jobs: - create_help_comment: - if: github.event.issue.pull_request + create_help_comment_pr: + if: github.event.issue.pull_request && contains(github.event.comment.body, '/help') runs-on: ubuntu-latest steps: - uses: actions-ecosystem/action-create-comment@v1 - if: contains(github.event.comment.body, '/help') with: github_token: ${{ secrets.GH_TOKEN }} body: | @@ -25,4 +24,20 @@ jobs: At the moment the following comments are supported in pull requests: - `/ready-to-merge` or `/rtm` - This comment will trigger automerge of PR in case all required checks are green, approvals in place and do-not-merge label is not added - - `/do-not-merge` or `/dnm` - This comment will block automerging even if all conditions are met and ready-to-merge label is added \ No newline at end of file + - `/do-not-merge` or `/dnm` - This comment will block automerging even if all conditions are met and ready-to-merge label is added + create_help_comment_issue: + if: ${{ !github.event.issue.pull_request && contains(github.event.comment.body, '/help') }} + runs-on: ubuntu-latest + steps: + - uses: actions-ecosystem/action-create-comment@v1 + with: + github_token: ${{ secrets.GH_TOKEN }} + body: | + Hello, @${{ github.actor }}! 👋🏼 + + I'm Genie from the magic lamp. Looks like somebody needs a hand! 🆘 + + At the moment the following comments are supported in issues: + + - `/good-first-issue {js | ts | java | go | docs | design | ci-cd} ` or `/gfi {js | ts | java | go | docs | design | ci-cd} ` - label an issue as a `good first issue`. + example: `/gfi js` or `/good-first-issue ci-cd`