Skip to content

Commit

Permalink
add find-issue-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
andistorm committed Sep 11, 2023
1 parent cfd5bdf commit 5fa5811
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/test-github-actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
36 changes: 36 additions & 0 deletions github-actions/create-issue-comment/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"}'
66 changes: 66 additions & 0 deletions github-actions/find-issue-comment/action.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"
36 changes: 36 additions & 0 deletions github-actions/update-issue-comment/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Update issue comment
description: Update issue comment
inputs:
owner:
description: 'Owner'
required: true
type: string
repo:
description: 'Repo'
required: true
type: string
token:
description: 'Token'
required: true
type: string
comment_id:
description: 'Comment id'
required: true
type: int
body:
description: 'Body'
required: true
type: string
runs:
using: "composite"
steps:
- name: Update issue
shell: bash
run: |
curl -L \
-X PATCH \
-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/comments/${{ inputs.comment_id }} \
-d '{"body":"${{ inputs.body }}"}'

0 comments on commit 5fa5811

Please sign in to comment.