-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgithub-actions-issue-comment-by-gpt.yml
41 lines (37 loc) · 1.28 KB
/
github-actions-issue-comment-by-gpt.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Run Script
on:
issues:
types: [opened, labeled]
jobs:
auto-reply:
if: github.event.label.name == 'run_1'
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup GitHub CLI
uses: cli/setup-gh@v1
- name: Run Script
id: script
run: |
try {
output=$(./script.sh)
echo "::set-output name=result::$output"
} catch {
echo "The script failed to run"
output="An error has occurred while running the script."
}
- name: Post Comment
id: comment
uses: actions/github-script@v3.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
const comments = await github.issues.listComments({...context.repo, issue_number});
const bot_comment_exists = comments.data.some(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('Your output text here'));
if (!bot_comment_exists) {
await github.issues.createComment({...context.repo, issue_number, body: '${{steps.script.outputs.result}}'});
}