Skip to content

Commit f6a6be9

Browse files
committed
Update comment on issue edit
1 parent 57405c4 commit f6a6be9

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

.github/workflows/duplicate-issue.yml

+30-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
1-
name: Copy Issue Description to Comment with Header
1+
name: Update Comment with Original Request on Edit
22

33
on:
44
issues:
5-
types: [opened]
5+
types: [opened, edited]
66

77
jobs:
8-
copy_description_to_comment:
8+
update_comment:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: Copy issue description to comment with header
11+
- name: Update comment with header and horizontal rule on issue edit
1212
uses: actions/github-script@v6
1313
with:
1414
github-token: ${{secrets.GITHUB_TOKEN}}
1515
script: |
1616
const issue = context.issue;
1717
const issueBody = context.payload.issue.body;
18+
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
1819
19-
// Create a comment with a header and the issue description
20-
const commentBody = `### Original Request\n\n${issueBody}`;
20+
// Create or update a comment with a header, horizontal rule, and the issue description
21+
const commentBody = `### Original Request\n\n-----\n\n${issueBody}`;
2122
22-
await github.rest.issues.createComment({
23+
// Fetch all comments for the issue
24+
const { data: comments } = await octokit.rest.issues.listComments({
2325
owner: issue.owner,
2426
repo: issue.repo,
2527
issue_number: issue.number,
26-
body: commentBody
2728
});
29+
30+
// Find a specific comment by its unique header (if it exists)
31+
const originalRequestComment = comments.find(comment => comment.body.startsWith('### Original Request'));
32+
33+
if (originalRequestComment) {
34+
// If the comment exists, update it
35+
await octokit.rest.issues.updateComment({
36+
owner: issue.owner,
37+
repo: issue.repo,
38+
comment_id: originalRequestComment.id,
39+
body: commentBody,
40+
});
41+
} else {
42+
// If the comment does not exist, create it
43+
await octokit.rest.issues.createComment({
44+
owner: issue.owner,
45+
repo: issue.repo,
46+
issue_number: issue.number,
47+
body: commentBody,
48+
});
49+
}

0 commit comments

Comments
 (0)