Skip to content

Commit 9571f19

Browse files
authored
Update classroom.yml
1 parent 85fe7d5 commit 9571f19

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

.github/workflows/classroom.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ jobs:
187187
script: |
188188
const { owner, repo } = context.repo;
189189
const targetTitle = "Feedback";
190+
const signature = "🤖 AI Feedback";
190191

191-
// List all open PRs
192+
// Find the PR by title
192193
const { data: pullRequests } = await github.rest.pulls.list({
193194
owner,
194195
repo,
@@ -197,20 +198,46 @@ jobs:
197198
});
198199

199200
const matchingPR = pullRequests.find(pr => pr.title.trim().toLowerCase() === targetTitle.toLowerCase());
200-
201201
if (!matchingPR) {
202202
throw new Error(`No open pull request found with title '${targetTitle}'`);
203203
}
204204

205205
const prNumber = matchingPR.number;
206-
const timestamp = new Date().toISOString();
207-
const body = `### 🤖 AI Feedback\n\n${process.env.FEEDBACK_BODY}\n\n---\n🕒 _Posted on ${timestamp}_`;
208206

209-
await github.rest.issues.createComment({
207+
// Get all comments on the PR
208+
const { data: comments } = await github.rest.issues.listComments({
210209
owner,
211210
repo,
212211
issue_number: prNumber,
213-
body
212+
per_page: 100
214213
});
215214

216-
console.log(`✅ Posted feedback to PR #${prNumber} titled '${targetTitle}'`);
215+
// Find existing comment from github-actions with our signature
216+
const existing = comments.find(c =>
217+
c.user?.login === "github-actions[bot]" &&
218+
c.body?.includes(signature)
219+
);
220+
221+
const timestamp = new Date().toISOString();
222+
const newEntry = `🕒 _Posted on ${timestamp}_\n\n${process.env.FEEDBACK_BODY}\n\n---\n`;
223+
224+
if (existing) {
225+
const updatedBody = `${newEntry}${existing.body}`;
226+
await github.rest.issues.updateComment({
227+
owner,
228+
repo,
229+
comment_id: existing.id,
230+
body: updatedBody
231+
});
232+
console.log(`🔄 Updated existing comment on PR #${prNumber}`);
233+
} else {
234+
const body = `### ${signature}\n\n${newEntry}`;
235+
await github.rest.issues.createComment({
236+
owner,
237+
repo,
238+
issue_number: prNumber,
239+
body
240+
});
241+
console.log(`🆕 Posted new comment on PR #${prNumber}`);
242+
}
243+

0 commit comments

Comments
 (0)