Skip to content

[SREP-618] feat: Add refresh command to fetch config from server #139

[SREP-618] feat: Add refresh command to fetch config from server

[SREP-618] feat: Add refresh command to fetch config from server #139

name: Dependabot Auto-Merge
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: write
pull-requests: write
checks: read
actions: read
jobs:
auto-merge:
runs-on: ubuntu-latest
# Only run for Dependabot PRs on the upstream repository (not forks)
if: github.actor == 'dependabot[bot]' && github.repository == 'openshift/backplane-cli'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Fetch Dependabot Metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Check PR Labels
id: check-labels
run: |
# Since this job only runs for Dependabot PRs (filtered at job level),
# we allow all Dependabot PRs regardless of labels since they are inherently dependency updates
echo "has-required-labels=true" >> $GITHUB_OUTPUT
echo "✅ Dependabot PR detected - auto-merge enabled for safe updates"
- name: Enable Auto-Merge for Safe Updates
if: |
steps.check-labels.outputs.has-required-labels == 'true' && (
steps.metadata.outputs.update-type == 'version-update:semver-patch' ||
steps.metadata.outputs.update-type == 'version-update:semver-minor' ||
steps.metadata.outputs.update-type == 'version-update:semver-digest'
)
run: |
echo "Enabling auto-merge for ${{ steps.metadata.outputs.update-type }} update"
echo "Dependency: ${{ steps.metadata.outputs.dependency-names }}"
echo "Previous version: ${{ steps.metadata.outputs.previous-version }}"
echo "New version: ${{ steps.metadata.outputs.new-version }}"
# Set GH_TOKEN for curl commands (token is automatically masked in logs)
GH_TOKEN="${{ secrets.GITHUB_TOKEN }}"
export GH_TOKEN
# Get PR node ID for GraphQL mutation
PR_NODE_ID=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r '.node_id')
if [[ -z "$PR_NODE_ID" || "$PR_NODE_ID" == "null" ]]; then
echo "❌ Failed to fetch PR node ID"
exit 1
fi
echo "PR Node ID: $PR_NODE_ID"
# Enable auto-merge using GraphQL API (only way that works)
response=$(curl -s -w "%{http_code}" -o /tmp/response.json \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/graphql" \
-d "{\"query\":\"mutation { enablePullRequestAutoMerge(input: { pullRequestId: \\\"$PR_NODE_ID\\\", mergeMethod: SQUASH }) { pullRequest { autoMergeRequest { enabledAt } } } }\"}")
if [[ "$response" -eq 200 ]]; then
echo "✅ Auto-merge enabled successfully via GraphQL"
cat /tmp/response.json
else
echo "❌ Failed to enable auto-merge. HTTP status: $response"
echo "Response body:"
cat /tmp/response.json
echo "::warning::Could not enable auto-merge due to permissions. PR labeled for manual review."
# Add a comment to the PR explaining the situation (token is automatically masked)
curl -s -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
-d '{"body":"🤖 **Dependabot Auto-Merge Status**\n\nThis PR meets the criteria for auto-merge but could not be automatically merged due to repository permissions.\n\n**Details:**\n- Update type: ${{ steps.metadata.outputs.update-type }}\n- Dependencies: ${{ steps.metadata.outputs.dependency-names }}\n- Previous version: ${{ steps.metadata.outputs.previous-version }}\n- New version: ${{ steps.metadata.outputs.new-version }}\n\nPlease review and merge manually if appropriate."}'
fi
- name: Comment on Major Version Updates
if: |
steps.check-labels.outputs.has-required-labels == 'true' &&
steps.metadata.outputs.update-type == 'version-update:semver-major'
run: |
# Set GH_TOKEN for curl commands (token is automatically masked in logs)
GH_TOKEN="${{ secrets.GITHUB_TOKEN }}"
export GH_TOKEN
# Add a comment to the PR explaining major version update (token is automatically masked)
curl -s -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
-d '{"body":"🚨 **Major Version Update Detected** 🚨\n\nThis PR contains a major version update that requires manual review:\n- **Dependency:** ${{ steps.metadata.outputs.dependency-names }}\n- **Previous version:** ${{ steps.metadata.outputs.previous-version }}\n- **New version:** ${{ steps.metadata.outputs.new-version }}\n\nPlease review the changelog and breaking changes before merging.\n\nAuto-merge has been **disabled** for this PR."}'
- name: Log Auto-Merge Decision
run: |
echo "Auto-merge decision for PR #${{ github.event.pull_request.number }}:"
echo "- Update type: ${{ steps.metadata.outputs.update-type }}"
echo "- Has required labels: ${{ steps.check-labels.outputs.has-required-labels }}"
echo "- Dependency: ${{ steps.metadata.outputs.dependency-names }}"
if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-patch" ]] || \
[[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-minor" ]] || \
[[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-digest" ]]; then
if [[ "${{ steps.check-labels.outputs.has-required-labels }}" == "true" ]]; then
echo "✅ Auto-merge ENABLED"
else
echo "❌ Auto-merge DISABLED: Missing required labels"
fi
else
echo "❌ Auto-merge DISABLED: Major version update or unknown update type"
fi