@@ -40,26 +40,45 @@ jobs:
40
40
41
41
- name : Comment on PR
42
42
uses : actions/github-script@v7
43
- if : failure()
43
+ if : failure() && github.event_name == 'pull_request'
44
44
with :
45
45
github-token : ${{secrets.GITHUB_TOKEN}}
46
- script : |
47
- github.rest.issues.createComment({
48
- issue_number: context.issue.number,
49
- owner: context.repo.owner,
50
- repo: context.repo.repo,
51
- body: `Unable to build without Cargo.lock file.
46
+ script : |
47
+ const issue_number = context.issue.number;
48
+ const owner = context.repo.owner;
49
+ const repo = context.repo.repo;
52
50
53
- This means that after this change 3rd party projects may have
54
- difficulties using crates in this repo as a dependency. If this
55
- isn't easy to fix please open an issue so we can fix it later.
51
+ const commentBody = `Unable to build without Cargo.lock file.
56
52
57
- To reproduce locally run
53
+ This means that after this change 3rd party projects may have
54
+ difficulties using crates in this repo as a dependency. If this
55
+ isn't easy to fix please open an issue so we can fix it later.
58
56
59
- \`\`\`
60
- cargo generate-lockfile
61
- cargo check --all-targets
62
- \`\`\`
57
+ To reproduce locally run
63
58
64
- This PR can still be merged.`
65
- })
59
+ \`\`\`
60
+ cargo generate-lockfile
61
+ cargo check --all-targets
62
+ \`\`\`
63
+
64
+ This PR can still be merged.`;
65
+
66
+ // Fetch existing comments
67
+ const { data: comments } = await github.rest.issues.listComments({
68
+ owner,
69
+ repo,
70
+ issue_number,
71
+ });
72
+
73
+ // Find existing comment
74
+ const existingComment = comments.find(c => c.body == commentBody);
75
+ if (!existingComment) {
76
+ await github.rest.issues.createComment({
77
+ owner,
78
+ repo,
79
+ issue_number,
80
+ body: commentBody
81
+ });
82
+ } else {
83
+ console.log("Already commentted.")
84
+ }
0 commit comments