-
Notifications
You must be signed in to change notification settings - Fork 707
185 lines (167 loc) · 7.22 KB
/
issue-auto-response.yml
File metadata and controls
185 lines (167 loc) · 7.22 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
name: Issue Auto Response
on:
issues:
types: [opened, labeled]
issue_comment:
types: [created]
concurrency:
group: issue-auto-response-${{ github.event.issue.number }}
cancel-in-progress: true
permissions:
contents: read
jobs:
auto-response:
if: |
!github.event.issue.pull_request &&
!endsWith(github.actor, '[bot]') &&
!contains(github.event.issue.labels.*.name, 'duplicate') &&
!contains(github.event.issue.labels.*.name, 'spam') &&
!contains(github.event.issue.labels.*.name, 'bot-skip') &&
vars.CODEX_BOT_ENABLED == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- name: Check bot response state
id: check_bot
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const marker = "*Open-CoDesign Bot*";
const allowedLogins = (process.env.BOT_LOGINS || "github-actions[bot]")
.split(",").map((v) => v.trim()).filter(Boolean);
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100
}
);
const botComments = comments
.filter((c) => {
if (!(c?.body || "").includes(marker)) return false;
const u = c.user;
if (!u || u.type !== "Bot") return false;
return allowedLogins.includes(u.login);
})
.sort((a, b) => new Date(b.created_at || 0) - new Date(a.created_at || 0));
const latestBot = botComments[0] || null;
let shouldRespond = false;
let reason = "unhandled event";
if (context.eventName === "issues") {
const body = (context.payload.issue?.body || "").trim();
const labelName = context.payload.label?.name || "";
const forceRerun = labelName === "bot-rerun";
shouldRespond = Boolean(body) && (!latestBot || forceRerun);
reason = !body
? "skip empty issue body"
: shouldRespond
? forceRerun
? "forced issue bot rerun"
: "new issue without bot response"
: "issue already has bot response";
} else if (context.eventName === "issue_comment") {
const comment = context.payload.comment;
const author = comment?.user;
const isBotComment =
author?.type === "Bot" ||
(author?.login || "").endsWith("[bot]");
const body = (comment?.body || "").trim();
if (isBotComment) {
reason = "skip bot comment";
} else if (!body) {
reason = "skip empty comment";
} else if (!latestBot) {
shouldRespond = true;
reason = "human comment without prior bot response";
} else {
const commentTime = new Date(comment.created_at || 0).getTime();
const botTime = new Date(latestBot.created_at || 0).getTime();
shouldRespond = commentTime > botTime;
reason = shouldRespond
? "human follow-up after bot response"
: "comment is not newer than latest bot response";
}
}
core.info(`Issue bot response decision: ${shouldRespond ? "run" : "skip"} (${reason})`);
core.setOutput("should_respond", shouldRespond ? "true" : "false");
core.setOutput("reason", reason);
core.setOutput("latest_bot_comment_id", latestBot ? String(latestBot.id) : "");
env:
BOT_LOGINS: ${{ vars.BOT_LOGINS }}
- name: Checkout repository
if: steps.check_bot.outputs.should_respond == 'true'
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: Resolve issue provider config
if: steps.check_bot.outputs.should_respond == 'true'
id: issue_config
shell: bash
env:
DEFAULT_API_KEY: ${{ secrets.OPENAI_API_KEY }}
DEFAULT_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
DEFAULT_MODEL: ${{ vars.OPENAI_MODEL }}
DEFAULT_EFFORT: ${{ vars.OPENAI_EFFORT }}
REVIEW_API_KEY: ${{ secrets.REVIEW_OPENAI_API_KEY }}
REVIEW_BASE_URL: ${{ secrets.REVIEW_OPENAI_BASE_URL }}
REVIEW_MODEL: ${{ vars.REVIEW_OPENAI_MODEL }}
REVIEW_EFFORT: ${{ vars.REVIEW_OPENAI_EFFORT }}
run: |
api_key="$REVIEW_API_KEY"
[ -n "$api_key" ] || api_key="$DEFAULT_API_KEY"
base_url="$REVIEW_BASE_URL"
[ -n "$base_url" ] || base_url="$DEFAULT_BASE_URL"
model="$REVIEW_MODEL"
[ -n "$model" ] || model="$DEFAULT_MODEL"
effort="$REVIEW_EFFORT"
[ -n "$effort" ] || effort="$DEFAULT_EFFORT"
[ -n "$model" ] || model='gpt-5.4'
[ -n "$effort" ] || effort='high'
is_deepseek='false'
case "$base_url" in
*api.deepseek.com*)
is_deepseek='true'
;;
esac
{
echo "api_key=$api_key"
echo "base_url=$base_url"
echo "model=$model"
echo "effort=$effort"
echo "is_deepseek=$is_deepseek"
} >> "$GITHUB_OUTPUT"
- name: Set up Node.js for DeepSeek issue response
if: steps.check_bot.outputs.should_respond == 'true' && steps.issue_config.outputs.is_deepseek == 'true'
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "20"
- name: Run DeepSeek for Issue Auto Response
if: steps.check_bot.outputs.should_respond == 'true' && steps.issue_config.outputs.is_deepseek == 'true'
env:
GH_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}
DEEPSEEK_API_KEY: ${{ steps.issue_config.outputs.api_key }}
DEEPSEEK_BASE_URL: ${{ steps.issue_config.outputs.base_url }}
DEEPSEEK_MODEL: ${{ steps.issue_config.outputs.model }}
DEEPSEEK_EFFORT: ${{ steps.issue_config.outputs.effort }}
run: node .github/scripts/deepseek-issue-response.mjs
- name: Run Codex for Issue Auto Response
if: steps.check_bot.outputs.should_respond == 'true' && steps.issue_config.outputs.is_deepseek != 'true'
uses: openai/codex-action@e0fdf01220eb9a88167c4898839d273e3f2609d1 # v1
env:
GH_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}
with:
openai-api-key: ${{ steps.issue_config.outputs.api_key }}
responses-api-endpoint: ${{ steps.issue_config.outputs.base_url }}
model: ${{ steps.issue_config.outputs.model }}
effort: ${{ steps.issue_config.outputs.effort }}
sandbox: danger-full-access
safety-strategy: drop-sudo
prompt-file: .github/prompts/issue-auto-response.md
allow-bots: true
allow-users: '*'