From ebb935a24b8aada40746ebdce880478ebac4e926 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 7 Oct 2024 22:56:19 +0200 Subject: [PATCH 1/5] migrate https://github.com/elastic/apm-pipeline-library/blob/main/.github/actions/comment-reaction/README.md --- github/comment-reaction/README.md | 39 ++++++++++++++++++++++++++++++ github/comment-reaction/action.yml | 31 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 github/comment-reaction/README.md create mode 100644 github/comment-reaction/action.yml diff --git a/github/comment-reaction/README.md b/github/comment-reaction/README.md new file mode 100644 index 00000000..4320cad8 --- /dev/null +++ b/github/comment-reaction/README.md @@ -0,0 +1,39 @@ +# github/comment-reaction + +[![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https://github.com/search?q=elastic%2Foblt-actions%2Fgithub%2Fcomment-reaction+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code) + + +React to the given comment with an emoji (default +1). + + +## Inputs + +| Name | Description | Required | Default | +|----------------|--------------------------------------------------------------------------------------------------------|----------|----------------------------------| +| `comment-id` | The GitHub commentId | `false` | `${{ github.event.comment.id }}` | +| `emoji` | The GitHub emoji (see https://docs.github.com/en/rest/reactions?apiVersion=2022-11-28#about-reactions) | `false` | `+1` | +| `github-token` | The GitHub access token. | `true` | ` ` | +| `repository` | The GitHub repository (format: ORG/REPO) | `false` | `${{ github.repository }}` | + + +## Usage + + +```yaml + +on: + issue_comment: + types: + - created +jobs: + react: + runs-on: ubuntu-latest + if: ${{ github.event.issue.pull_request + steps: + - uses: elastic/oblt-actions/github/comment-reaction@v1 + with: + github-token: ${{ secrets.PAT_TOKEN }} + emoji: '-1' + # ... +``` + diff --git a/github/comment-reaction/action.yml b/github/comment-reaction/action.yml new file mode 100644 index 00000000..2082eb31 --- /dev/null +++ b/github/comment-reaction/action.yml @@ -0,0 +1,31 @@ +name: 'github/comment-reaction' + +description: React to the given comment with an emoji (default +1). + +inputs: + comment-id: + description: 'The GitHub commentId' + default: ${{ github.event.comment.id }} + emoji: + description: 'The GitHub emoji (see https://docs.github.com/en/rest/reactions?apiVersion=2022-11-28#about-reactions)' + default: '+1' + github-token: + description: 'The GitHub access token.' + required: true + repository: + description: 'The GitHub repository (format: ORG/REPO)' + default: ${{ github.repository }} + +runs: + using: "composite" + steps: + - name: React to the given comment + run: | + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + /repos/${{ inputs.repository }}/issues/comments/${{ inputs.commentId }}/reactions \ + -f content='${{ inputs.emoji }}' + env: + GH_TOKEN: ${{ inputs.github-token }} + shell: bash From e96ad34ae7512e71149237b962c8d503f52a5843 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 7 Oct 2024 22:57:31 +0200 Subject: [PATCH 2/5] use defaults --- github/comment-reaction/README.md | 5 +++-- github/comment-reaction/action.yml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/github/comment-reaction/README.md b/github/comment-reaction/README.md index 4320cad8..51a7f0f4 100644 --- a/github/comment-reaction/README.md +++ b/github/comment-reaction/README.md @@ -12,7 +12,7 @@ React to the given comment with an emoji (default +1). |----------------|--------------------------------------------------------------------------------------------------------|----------|----------------------------------| | `comment-id` | The GitHub commentId | `false` | `${{ github.event.comment.id }}` | | `emoji` | The GitHub emoji (see https://docs.github.com/en/rest/reactions?apiVersion=2022-11-28#about-reactions) | `false` | `+1` | -| `github-token` | The GitHub access token. | `true` | ` ` | +| `github-token` | The GitHub access token. | `false` | `${{ github.token }}` | | `repository` | The GitHub repository (format: ORG/REPO) | `false` | `${{ github.repository }}` | @@ -29,10 +29,11 @@ jobs: react: runs-on: ubuntu-latest if: ${{ github.event.issue.pull_request + permission: + issues: write steps: - uses: elastic/oblt-actions/github/comment-reaction@v1 with: - github-token: ${{ secrets.PAT_TOKEN }} emoji: '-1' # ... ``` diff --git a/github/comment-reaction/action.yml b/github/comment-reaction/action.yml index 2082eb31..ab13b9a0 100644 --- a/github/comment-reaction/action.yml +++ b/github/comment-reaction/action.yml @@ -11,7 +11,7 @@ inputs: default: '+1' github-token: description: 'The GitHub access token.' - required: true + default: ${{ github.token }} repository: description: 'The GitHub repository (format: ORG/REPO)' default: ${{ github.repository }} From a24ca1c3b26f1f687d93596ee1cf61b6822dbc50 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 7 Oct 2024 23:00:56 +0200 Subject: [PATCH 3/5] add tests --- .../test-github-comment-reaction.yml | 22 +++++++++++++++++++ github/comment-reaction/README.md | 1 + 2 files changed, 23 insertions(+) create mode 100644 .github/workflows/test-github-comment-reaction.yml diff --git a/.github/workflows/test-github-comment-reaction.yml b/.github/workflows/test-github-comment-reaction.yml new file mode 100644 index 00000000..fd4b7129 --- /dev/null +++ b/.github/workflows/test-github-comment-reaction.yml @@ -0,0 +1,22 @@ +name: test-github-comment-reaction + +on: + push: + paths: + - '.github/workflows/test-github-comment-reaction.yml' + - 'github/comment-reaction/**' + +permissions: + contents: read + issues: write + +jobs: + comment: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./github/comment-reaction + id: validation + with: + comment-id: "2178560535" + emoji: "+1" diff --git a/github/comment-reaction/README.md b/github/comment-reaction/README.md index 51a7f0f4..d1a0293b 100644 --- a/github/comment-reaction/README.md +++ b/github/comment-reaction/README.md @@ -1,6 +1,7 @@ # github/comment-reaction [![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https://github.com/search?q=elastic%2Foblt-actions%2Fgithub%2Fcomment-reaction+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code) +[![test-github-comment-reaction](https://github.com/elastic/oblt-actions/actions/workflows/test-github-comment-reaction.yml/badge.svg?branch=main)](https://github.com/elastic/oblt-actions/actions/workflows/test-github-comment-reaction.yml) React to the given comment with an emoji (default +1). From 8f7b37a7175201b12106e7888478548959054c04 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 7 Oct 2024 23:04:02 +0200 Subject: [PATCH 4/5] fix --- github/comment-reaction/action.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/github/comment-reaction/action.yml b/github/comment-reaction/action.yml index ab13b9a0..5484180c 100644 --- a/github/comment-reaction/action.yml +++ b/github/comment-reaction/action.yml @@ -24,8 +24,11 @@ runs: gh api \ --method POST \ -H "Accept: application/vnd.github+json" \ - /repos/${{ inputs.repository }}/issues/comments/${{ inputs.commentId }}/reactions \ - -f content='${{ inputs.emoji }}' + /repos/${{ env.REPO }}/issues/comments/${{ env.COMMENT_ID }}/reactions \ + -f content='${{ env.EMOJI }}' env: + COMMENT_ID: ${{ inputs.comment-id }} + EMOJI: ${{ inputs.emoji }} GH_TOKEN: ${{ inputs.github-token }} + REPO: ${{ inputs.repository }} shell: bash From 0e9d1854e6e6a53cbceeeef3133d35c455b0cbff Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 7 Oct 2024 23:05:15 +0200 Subject: [PATCH 5/5] change permissions --- .github/workflows/test-github-comment-reaction.yml | 2 +- github/comment-reaction/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-github-comment-reaction.yml b/.github/workflows/test-github-comment-reaction.yml index fd4b7129..719cdfe9 100644 --- a/.github/workflows/test-github-comment-reaction.yml +++ b/.github/workflows/test-github-comment-reaction.yml @@ -8,7 +8,7 @@ on: permissions: contents: read - issues: write + pull-requests: write jobs: comment: diff --git a/github/comment-reaction/README.md b/github/comment-reaction/README.md index d1a0293b..cd0496d5 100644 --- a/github/comment-reaction/README.md +++ b/github/comment-reaction/README.md @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-latest if: ${{ github.event.issue.pull_request permission: - issues: write + pull-requests: write steps: - uses: elastic/oblt-actions/github/comment-reaction@v1 with: