Skip to content

Commit 3c91a21

Browse files
committed
Only comment once
1 parent 43ed23a commit 3c91a21

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

.github/workflows/build-without-lockfile.yml

+36-17
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,45 @@ jobs:
4040
4141
- name: Comment on PR
4242
uses: actions/github-script@v7
43-
if: failure()
43+
if: failure() && github.event_name == 'pull_request'
4444
with:
4545
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;
5250
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.
5652
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.
5856
59-
\`\`\`
60-
cargo generate-lockfile
61-
cargo check --all-targets
62-
\`\`\`
57+
To reproduce locally run
6358
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

Comments
 (0)