-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpoe-code-github-issue-comment-created.yml
More file actions
194 lines (191 loc) · 7.93 KB
/
poe-code-github-issue-comment-created.yml
File metadata and controls
194 lines (191 loc) · 7.93 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Auto-generated by: poe-code github-workflows install github-issue-comment-created
name: "GitHub: Issue Comment Created"
on:
issue_comment:
types:
- created
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number }}
cancel-in-progress: true
jobs:
guard:
if: format('{0}', github.event.issue.pull_request != null) != 'true' && github.event.issue.state == 'open' && github.event.comment.user.type != 'Bot'
runs-on: ubuntu-latest
env:
OUTPUT_FORMAT: terminal
outputs:
should_run: ${{ steps.guard_result.outputs.should_run }}
permissions:
contents: read
steps:
- name: Preflight
env:
POE_CODE_AGENT_APP_ID: ${{ secrets.POE_CODE_AGENT_APP_ID }}
POE_CODE_AGENT_PRIVATE_KEY: ${{ secrets.POE_CODE_AGENT_PRIVATE_KEY }}
POE_API_KEY: ${{ secrets.POE_API_KEY }}
run: |
missing=()
[ -z "$POE_CODE_AGENT_APP_ID" ] && missing+=("POE_CODE_AGENT_APP_ID")
[ -z "$POE_CODE_AGENT_PRIVATE_KEY" ] && missing+=("POE_CODE_AGENT_PRIVATE_KEY")
[ -z "$POE_API_KEY" ] && missing+=("POE_API_KEY")
if [ ${#missing[@]} -gt 0 ]; then
for name in "${missing[@]}"; do
echo "::error::Missing required secret: $name — add it in Settings → Secrets and variables → Actions"
done
exit 1
fi
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.POE_CODE_AGENT_APP_ID }}
private-key: ${{ secrets.POE_CODE_AGENT_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install -g poe-code@latest
- id: allow_check
continue-on-error: true
run: poe-code github-workflows require-user-allow github-issue-comment-created
env:
POE_CODE_STDERR_LOGS: "1"
COMMENT_AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
- id: prefix_check
continue-on-error: true
run: poe-code github-workflows require-comment-prefix github-issue-comment-created
env:
POE_CODE_STDERR_LOGS: "1"
COMMENT_BODY: ${{ github.event.comment.body }}
- id: guard_result
run: |
if [ "${{ steps.allow_check.outcome }}" = "success" ] && [ "${{ steps.prefix_check.outcome }}" = "success" ]; then
echo "should_run=true" >> "$GITHUB_OUTPUT"
else
echo "should_run=false" >> "$GITHUB_OUTPUT"
fi
run:
needs: guard
if: needs.guard.outputs.should_run == 'true'
runs-on: ubuntu-latest
env:
OUTPUT_FORMAT: terminal
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Preflight
env:
POE_CODE_AGENT_APP_ID: ${{ secrets.POE_CODE_AGENT_APP_ID }}
POE_CODE_AGENT_PRIVATE_KEY: ${{ secrets.POE_CODE_AGENT_PRIVATE_KEY }}
POE_API_KEY: ${{ secrets.POE_API_KEY }}
run: |
missing=()
[ -z "$POE_CODE_AGENT_APP_ID" ] && missing+=("POE_CODE_AGENT_APP_ID")
[ -z "$POE_CODE_AGENT_PRIVATE_KEY" ] && missing+=("POE_CODE_AGENT_PRIVATE_KEY")
[ -z "$POE_API_KEY" ] && missing+=("POE_API_KEY")
if [ ${#missing[@]} -gt 0 ]; then
for name in "${missing[@]}"; do
echo "::error::Missing required secret: $name — add it in Settings → Secrets and variables → Actions"
done
exit 1
fi
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.POE_CODE_AGENT_APP_ID }}
private-key: ${{ secrets.POE_CODE_AGENT_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install -g poe-code@latest
- id: pr_context
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
if ("${{ github.event.issue.pull_request != null }}" !== "true") {
core.setOutput("pr_number", "");
core.setOutput("pr_title", "");
core.setOutput("pr_author", "");
core.setOutput("head_ref", "");
return;
}
const response = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: Number("${{ github.event.issue.number }}")
});
const headRepo = response.data.head.repo?.full_name ?? "";
const currentRepo = `${context.repo.owner}/${context.repo.repo}`;
const isSameRepo = headRepo === currentRepo;
core.setOutput("pr_number", String(response.data.number ?? ""));
core.setOutput("pr_title", response.data.title ?? "");
core.setOutput("pr_author", response.data.user?.login ?? "");
core.setOutput("head_ref", isSameRepo ? (response.data.head.ref ?? "") : "");
- id: add_in_progress_reaction
continue-on-error: true
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const response = await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: Number("${{ github.event.comment.id }}"),
content: "eyes"
});
core.setOutput("reaction_id", String(response.data.id ?? ""));
- if: steps.pr_context.outputs.head_ref != ''
id: checkout_pr_branch
uses: actions/checkout@v4
with:
ref: ${{ steps.pr_context.outputs.head_ref }}
token: ${{ steps.app-token.outputs.token }}
- if: steps.pr_context.outputs.head_ref == ''
id: checkout_default_branch
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Configure git identity for GitHub App
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
run: |
USER_ID=$(gh api "/users/${APP_SLUG}[bot]" --jq .id)
git config --global user.name "${APP_SLUG}[bot]"
git config --global user.email "${USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
- run: poe-code github-workflows prepare github-issue-comment-created
env:
POE_CODE_STDERR_LOGS: "1"
POE_API_KEY: ${{ secrets.POE_API_KEY }}
- run: poe-code github-workflows github-issue-comment-created --yes
env:
POE_CODE_STDERR_LOGS: "1"
POE_API_KEY: ${{ secrets.POE_API_KEY }}
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
PR_NUMBER: ${{ steps.pr_context.outputs.pr_number }}
PR_TITLE: ${{ steps.pr_context.outputs.pr_title }}
PR_AUTHOR: ${{ steps.pr_context.outputs.pr_author }}
COMMENT_BODY: ${{ github.event.comment.body }}
COMMENT_AUTHOR: ${{ github.event.comment.user.login }}
GITHUB_REPOSITORY: ${{ github.repository }}
- id: remove_in_progress_reaction
if: always() && steps.add_in_progress_reaction.outputs.reaction_id != ''
continue-on-error: true
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
await github.rest.reactions.deleteForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: Number("${{ github.event.comment.id }}"),
reaction_id: Number("${{ steps.add_in_progress_reaction.outputs.reaction_id }}")
});