diff --git a/.github/workflows/test-github-actions.yaml b/.github/workflows/test-github-actions.yaml index 0d0d863..3ac4fe8 100644 --- a/.github/workflows/test-github-actions.yaml +++ b/.github/workflows/test-github-actions.yaml @@ -128,3 +128,51 @@ jobs: git config --list --global test "$(git config --get user.email)" = "compiler@pionix.de" test "$(git config --get user.name)" = "Github Service Account" + test-find-issue-comment: + runs-on: ubuntu-22.04 + steps: + - name: Find issue comment + # LTODO: switch to main branch + uses: everest/everest-ci/github-actions/find-issue-comment@feature/add-render-jinja2-action + id: find-issue-comment + with: + owner: everest + repo: everest + token: ${{ secrets.SA_GITHUB_PAT }} + issue_number: 98 + user: pionix-compiler + test-update-issue-comment: + runs-on: ubuntu-22.04 + steps: + - name: Find issue comment + # LTODO: switch to main branch + uses: everest/everest-ci/github-actions/find-issue-comment@feature/add-render-jinja2-action + id: find-issue-comment + with: + owner: everest + repo: everest + token: ${{ secrets.SA_GITHUB_PAT }} + issue_number: 98 + user: pionix-compiler + - name: Update issue comment + # LTODO: switch to main branch + uses: everest/everest-ci/github-actions/update-issue-comment@feature/add-render-jinja2-action + with: + owner: everest + repo: everest + token: ${{ secrets.SA_GITHUB_PAT }} + comment_id: ${{ steps.find-issue-comment.outputs.comment_id }} + body: "Hello World 2" + # test-create-issue-comment: + # runs-on: ubuntu-22.04 + # steps: + # - name: Create issue comment + # # LTODO: switch to main branch + # uses: everest/everest-ci/github-actions/create-issue-comment@feature/add-render-jinja2-action + # id: create-issue-comment + # with: + # owner: everest + # repo: everest + # token: ${{ secrets.SA_GITHUB_PAT }} + # issue_number: 98 + # body: "Hello World" diff --git a/github-actions/create-issue-comment/action.yaml b/github-actions/create-issue-comment/action.yaml new file mode 100644 index 0000000..afacb33 --- /dev/null +++ b/github-actions/create-issue-comment/action.yaml @@ -0,0 +1,36 @@ +name: Create issue comment +description: Create issue comment +inputs: + owner: + description: 'Owner' + required: true + type: string + repo: + description: 'Repo' + required: true + type: string + issue_number: + description: 'Issue number' + required: true + type: int + token: + description: 'Token' + required: true + type: string + body: + description: 'Body' + required: true + type: string +runs: + using: "composite" + steps: + - name: Create comment + shell: bash + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ inputs.token }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ inputs.owner }}/${{ inputs.repo }}/issues/${{ inputs.issue_number }}/comments \ + -d '{"body":"${{ inputs.body }}"}' diff --git a/github-actions/find-issue-comment/action.yaml b/github-actions/find-issue-comment/action.yaml new file mode 100644 index 0000000..07f689a --- /dev/null +++ b/github-actions/find-issue-comment/action.yaml @@ -0,0 +1,66 @@ +name: Find issue comment by user +description: Find issue comment by user +inputs: + owner: + description: 'Owner' + required: true + type: string + repo: + description: 'Repo' + required: true + type: string + issue_number: + description: 'Issue number' + required: true + type: int + token: + description: 'Token' + required: true + type: string + user: + description: 'User' + required: true + type: string +outputs: + comment_id: + description: 'Comment id' + value: ${{ steps.find-comment.outputs.comment_id }} + success: + description: 'Success' + value: ${{ steps.find-comment.outputs.success }} +runs: + using: "composite" + steps: + - name: Get all comments + shell: bash + run: | + curl -L \ + -o "output.json" \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ inputs.token }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ inputs.owner }}/${{ inputs.repo }}/issues/${{ inputs.issue_number }}/comments + id: comments + - name: Find comment + id: find-comment + shell: python3 {0} + run: | + import json, os + comment_id = None + success = "False" + with open('output.json') as f: + comments = json.load(f) + for comment in comments: + if comment['user']['login'] == "${{ inputs.user }}": + if comment_id is not None: + raise Exception(f"Found multiple comments by user ${{ inputs.user }}") + comment_id = comment['id'] + success = "True" + with open(os.environ['GITHUB_OUTPUT'], 'a') as f: + f.write(f'comment_id={ comment_id }\n') + f.write(f'success={ success }\n') + - name: Result + shell: bash + run: | + echo "comment_id: ${{ steps.find-comment.outputs.comment_id }}" + echo "success: ${{ steps.find-comment.outputs.success }}" \ No newline at end of file