Skip to content

Commit dcf722f

Browse files
committed
enhance auto-merge workflow to prevent duplicate approvals by the bot
1 parent 161d907 commit dcf722f

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

.github/workflows/dependabot_automerge.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,27 @@ jobs:
2727
with:
2828
github-token: ${{ secrets.GITHUB_TOKEN }}
2929
script: |
30-
await github.rest.pulls.createReview({
30+
const { data: reviews } = await github.rest.pulls.listReviews({
3131
owner: context.repo.owner,
3232
repo: context.repo.repo,
3333
pull_number: context.payload.pull_request.number,
34-
event: "APPROVE"
3534
});
3635
36+
const alreadyApprovedByBot = reviews.some(
37+
(review) =>
38+
review.state === "APPROVED" &&
39+
review.user?.login === "github-actions[bot]"
40+
);
41+
42+
if (!alreadyApprovedByBot) {
43+
await github.rest.pulls.createReview({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
pull_number: context.payload.pull_request.number,
47+
event: "APPROVE",
48+
});
49+
}
50+
3751
# Enable GitHub auto-merge; it will merge once required checks (your Test Suite) are green
3852
- name: Enable auto-merge (squash)
3953
if: steps.metadata.outputs.update-type != 'version-update:semver-major'

0 commit comments

Comments
 (0)