-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dependabot): Automate dependabot reviews #33067
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1212697
feat(ci): Add a task to update reviewers for dependabot
chouetz 6c122ca
new workflow for dependabot pr
chouetz 67cdf26
add workflow to ask reviews
chouetz 4608a98
use the correct bot in workflow, restrict to dependabot and add tests
chouetz d2dc1e3
Test if PR is mergeable before pushing into MQ
chouetz cbcc899
Split the workflow for MQ addition and warning to agent-devx
chouetz d23d097
codereview
chouetz 42d6ce0
update tests
chouetz 3d2497e
do not use unnecessary token and scope env variables
chouetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
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 | ||
|
||
steps: | ||
# Use a token as only the github App can push to the merge queue | ||
- uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1 | ||
id: app-token | ||
with: | ||
app-id: ${{ vars.DD_GITHUB_TOKEN_GENERATOR_APP_ID }} | ||
private-key: ${{ secrets.DD_GITHUB_TOKEN_GENERATOR_PRIVATE_KEY }} | ||
- name: Check if the PR is mergeable | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
id: check-mergeable | ||
with: | ||
github-token: ${{ steps.app-token.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 `${allAproved && 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@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
github-token: ${{ steps.app-token.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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
name: "Add reviewers and ask review for dependabot PR" | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: | ||
- main | ||
|
||
permissions: {} | ||
jobs: | ||
add_reviewers: | ||
if: github.event.pull_request.user.login == 'dependabot[bot]' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Setup python | ||
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 | ||
with: | ||
python-version-file: .python-version | ||
cache: 'pip' | ||
cache-dependency-path: '**/requirements*.txt' | ||
|
||
- name: Install dependencies | ||
run: pip install -r requirements.txt -r tasks/requirements.txt | ||
|
||
- name: Add reviewers and ask review | ||
env: | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: inv -e issue.add-reviewers -p $PR_NUMBER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Warn Failed Dependabot PR | ||
|
||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
- edited | ||
|
||
jobs: | ||
check_comment: | ||
if: github.actor == 'dd-devflow[bot]' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check for error in comment | ||
id: check-comment | ||
env: | ||
PR_BODY: ${{ github.event.comment.body }} | ||
run: | | ||
if echo "$PR_BODY" | grep -iE "(blocked|cancelled|conflicts|draft|error|failed|failing|timeout|unqueued|updated)"; then | ||
echo "not_merged=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "not_merged=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Contact agent-devx | ||
if: ${{ steps.check-comment.outputs.not_merged == 'true' }} | ||
run: | | ||
message="Hi!\nThis dependabot PR ${{github.event.issue.html_url}} was not merged.\nPlease have a look." | ||
curl -X POST -H "Content-Type: application/json" --data '{"message": "$message"}' ${{ secrets.SLACK_AGENT_DEVX_WEBHOOK }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should test for
!== 'APPROVED'
since only a comment doesn't mean we approveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just check here for the detailed explanation: a
COMMENT
doesn't mean you approve but you can haveCOMMENT
from non-required reviewers. So we needno CHANGES_REQUESTED && requested_teams is empty