173 lines
6.3 KiB
YAML
173 lines
6.3 KiB
YAML
name: 🎯 Pull Request Auto Manager
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [opened, synchronize, reopened, edited, labeled, unlabeled, closed]
|
|
|
|
jobs:
|
|
check-merge-conflicts:
|
|
name: Check Merge Conflicts
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Check Merge Conflicts
|
|
# Label Conflicting Pull Requests
|
|
# https://github.com/marketplace/actions/label-conflicting-pull-requests
|
|
uses: eps1lon/actions-label-merge-conflict@v3
|
|
with:
|
|
dirtyLabel: '🚫 Merge Conflicts'
|
|
repoToken: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
|
commentOnDirty: >
|
|
⚠️ This PR has conflicts that need to be resolved before it can be merged.
|
|
|
|
pr-size-labeler:
|
|
name: Apply Label for PR Size
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Label PR Size
|
|
# Pull Request Size Labeler
|
|
# https://github.com/marketplace/actions/pull-request-size-labeler
|
|
uses: codelytv/pr-size-labeler@v1
|
|
with:
|
|
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
|
xs_label: 'PR - Small'
|
|
xs_max_size: '1'
|
|
s_label: 'PR - Small'
|
|
s_max_size: '100'
|
|
m_label: 'PR - Medium'
|
|
m_max_size: '500'
|
|
l_label: 'PR - Large'
|
|
l_max_size: '1000'
|
|
xl_label: 'PR - XL'
|
|
fail_if_xl: 'false'
|
|
message_if_xl: >
|
|
⚠️ This PR is over 1000 lines, which is larger than recommended.
|
|
|
|
Please make sure that it only addresses a single issue - PRs this large are hard to test and may be rejected.
|
|
github_api_url: 'https://api.github.com'
|
|
files_to_ignore: |
|
|
"package-lock.json"
|
|
"public/lib/*"
|
|
|
|
label-release-prs:
|
|
name: Label PRs Targeting Release Branch
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Label PRs Targeting Release Branch
|
|
if: github.base_ref == 'release'
|
|
run: |
|
|
gh pr edit ${{ github.event.pull_request.number }} --add-label "❗ Against Release Branch"
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
|
|
|
apply-file-based-labels:
|
|
name: Apply Labels Based on Changed Files
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Apply Labels Based on Changed Files
|
|
# Pull Request Labeler
|
|
# https://github.com/marketplace/actions/labeler
|
|
uses: actions/labeler@v5
|
|
with:
|
|
repo-token: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
|
|
|
check-merge-blocking-labels:
|
|
name: Check Merge Blocking Labels
|
|
needs: [check-merge-conflicts, pr-size-labeler, label-release-prs, apply-file-based-labels]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Check Merge Blocking
|
|
# GitHub Script
|
|
# https://github.com/marketplace/actions/github-scriptLabels
|
|
id: label-check
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const prLabels = context.payload.pull_request.labels.map(label => label.name);
|
|
const blockingLabels = [
|
|
"⛔ Don't Merge",
|
|
"🔨 Needs Work",
|
|
"🔬 Needs Testing",
|
|
"⛔ Waiting For External/Upstream",
|
|
"❗ Against Release Branch",
|
|
"💥💣 Breaking Changes"
|
|
];
|
|
const hasBlockingLabel = prLabels.some(label => blockingLabels.includes(label));
|
|
|
|
if (hasBlockingLabel) {
|
|
console.log("Blocking label detected. Setting warning status.");
|
|
await github.rest.checks.create({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
name: "PR Label Warning",
|
|
head_sha: context.payload.pull_request.head.sha,
|
|
status: "completed",
|
|
conclusion: "neutral",
|
|
output: {
|
|
title: "Potential Merge Issue",
|
|
summary: "This PR has a merge-blocking label. Proceed with caution."
|
|
}
|
|
});
|
|
} else {
|
|
console.log("No merge-blocking labels found.");
|
|
}
|
|
|
|
pr-auto-comments:
|
|
name: Post PR Comments Based on Labels
|
|
needs: [check-merge-conflicts, pr-size-labeler, label-release-prs, apply-file-based-labels]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout Repository
|
|
# Checkout
|
|
# https://github.com/marketplace/actions/checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Post PR Comments Based on Labels
|
|
# Label Commenter for PRs
|
|
# https://github.com/marketplace/actions/label-commenter
|
|
uses: peaceiris/actions-label-commenter@v1
|
|
with:
|
|
config_file: .github/pr-auto-comments.yml
|
|
github_token: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
|
|
|
update-linked-issues:
|
|
name: Update Issues on Staging Merge
|
|
runs-on: ubuntu-latest
|
|
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'staging'
|
|
|
|
steps:
|
|
- name: Extract Linked Issues
|
|
id: extract_issues
|
|
run: |
|
|
ISSUES=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | grep -oiE '(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved) #([0-9]+)' | awk '{print $2}' | tr -d '#' | jq -R -s -c 'split("\n")[:-1]')
|
|
echo "issues=$ISSUES" >> $GITHUB_ENV
|
|
|
|
- name: Fetch Directly Linked Issues
|
|
id: fetch_linked_issues
|
|
run: |
|
|
PR_NUMBER=${{ github.event.pull_request.number }}
|
|
REPO=${{ github.repository }}
|
|
API_URL="https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/issues"
|
|
ISSUES=$(curl -s -H "Authorization: token ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}" "$API_URL" | jq -r '.[].number' | jq -R -s -c 'split("\n")[:-1]')
|
|
echo "linked_issues=$ISSUES" >> $GITHUB_ENV
|
|
|
|
- name: Merge Issue Lists
|
|
id: merge_issues
|
|
run: |
|
|
ISSUES=$(jq -c -n --argjson a "$issues" --argjson b "$linked_issues" '$a + $b | unique')
|
|
echo "final_issues=$ISSUES" >> $GITHUB_ENV
|
|
|
|
- name: Comment and Label Issues
|
|
env:
|
|
GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
for ISSUE in $(echo $final_issues | jq -r '.[]'); do
|
|
echo "Updating issue #$ISSUE"
|
|
gh issue edit $ISSUE -R ${{ github.repository }} --add-label "✅ Done (staging)"
|
|
done
|