mirror of
https://github.com/github/awesome-copilot.git
synced 2026-06-13 11:33:32 +00:00
chore: publish from staged
This commit is contained in:
@@ -2,8 +2,11 @@ name: Check PR Target Branch
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
branches: [main]
|
types: [opened, edited, reopened, synchronize]
|
||||||
types: [opened]
|
|
||||||
|
concurrency:
|
||||||
|
group: check-pr-target-${{ github.event.pull_request.number }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
@@ -16,7 +19,29 @@ jobs:
|
|||||||
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
|
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const body = [
|
const pull = context.payload.pull_request;
|
||||||
|
const owner = context.repo.owner;
|
||||||
|
const repo = context.repo.repo;
|
||||||
|
const pullNumber = context.issue.number;
|
||||||
|
const botLogin = 'github-actions[bot]';
|
||||||
|
|
||||||
|
const { data: reviews } = await github.rest.pulls.listReviews({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
pull_number: pullNumber,
|
||||||
|
per_page: 100
|
||||||
|
});
|
||||||
|
|
||||||
|
const latestBotReview = reviews
|
||||||
|
.filter((review) => review.user?.login === botLogin)
|
||||||
|
.sort((a, b) => new Date(a.submitted_at ?? a.created_at) - new Date(b.submitted_at ?? b.created_at))
|
||||||
|
.at(-1);
|
||||||
|
|
||||||
|
const latestBotState = latestBotReview?.state;
|
||||||
|
|
||||||
|
if (pull.base.ref === 'main') {
|
||||||
|
if (latestBotState !== 'CHANGES_REQUESTED') {
|
||||||
|
const requestChangesBody = [
|
||||||
'⚠️ **This PR targets `main`, but PRs should target `staged`.**',
|
'⚠️ **This PR targets `main`, but PRs should target `staged`.**',
|
||||||
'',
|
'',
|
||||||
'The `main` branch is auto-published from `staged` and should not receive direct PRs.',
|
'The `main` branch is auto-published from `staged` and should not receive direct PRs.',
|
||||||
@@ -27,9 +52,29 @@ jobs:
|
|||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
await github.rest.pulls.createReview({
|
await github.rest.pulls.createReview({
|
||||||
owner: context.repo.owner,
|
owner,
|
||||||
repo: context.repo.repo,
|
repo,
|
||||||
pull_number: context.issue.number,
|
pull_number: pullNumber,
|
||||||
event: 'REQUEST_CHANGES',
|
event: 'REQUEST_CHANGES',
|
||||||
body
|
body: requestChangesBody
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (latestBotState === 'CHANGES_REQUESTED') {
|
||||||
|
const approveBody = [
|
||||||
|
'✅ Base branch is now set correctly.',
|
||||||
|
'',
|
||||||
|
'Removing the prior block because this PR no longer targets `main`.'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
await github.rest.pulls.createReview({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
pull_number: pullNumber,
|
||||||
|
event: 'APPROVE',
|
||||||
|
body: approveBody
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user