WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Add dependabot PR to the Merge Queue #23913

Add dependabot PR to the Merge Queue

Add dependabot PR to the Merge Queue #23913

---
name: Add dependabot PR to the Merge Queue
on:
pull_request_review:
types:
- submitted
- edited
permissions: {}
jobs:
add_to_merge_queue:
if: github.event.pull_request.user.login == 'dependabot[bot]'
runs-on: ubuntu-latest
environment:
name: dependabot
permissions:
id-token: write # This is required for getting the required OIDC token from GitHub
steps:
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
id: octo-sts
with:
scope: DataDog/datadog-agent
policy: self.add-dependabot-pr-to-mq.comment-pr
- name: Check if the PR is mergeable
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
id: check-mergeable
with:
github-token: ${{ steps.octo-sts.outputs.token }}
script: |
const pullRequestNumber = context.payload.pull_request.number;
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequestNumber
});
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequestNumber
});
// Users can have several reviews, which are listed in chronological order: we use a map to keep the last review state.
let reviewers = new Map();
for (const review of reviews) {
reviewers.set(review.user.login, review.state);
}
let allApproved = true;
for (const [reviewer, state] of reviewers) {
if (state === 'CHANGES_REQUESTED') {
allApproved = false;
break;
}
}
// When a required reviewer approves, the team is removed from the requested_teams list.
// As such, a mergeable PR has no more requested teams and no changes requested in its reviews.
return `${allApproved && pullRequest.requested_teams.length === 0}`;
result-encoding: string
- name: Add Merge Comment to Pull Request
if: ${{ steps.check-mergeable.outputs.result == 'true' }}
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
github-token: ${{ steps.octo-sts.outputs.token }}
script: |
const pullRequestNumber = context.payload.pull_request.number;
const commentBody = "/merge";
// Add a comment to the pull request
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
body: commentBody
});