Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions .github/workflows/sync-milestone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ jobs:
REPO: ${{ github.repository }}
OWNER: ${{ github.repository_owner }}
run: |
# 1. Get the milestone of the officially linked issues and the PR's current milestone via GraphQL
# This catches issues linked via "Fixes #123" and similar in the body or the UI sidebar.
# 1. Get milestones from ALL linked closing issues and the PR's current milestone via GraphQL.
# closingIssuesReferences catches issues linked via "Fixes #123" and similar in the body or sidebar.
API_RESPONSE=$(gh api graphql -f query='
query($owner: String!, $name: String!, $pr: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $pr) {
milestone {
number
title
}
closingIssuesReferences(first: 1) {
closingIssuesReferences(first: 20) {
nodes {
milestone {
number
Expand All @@ -38,18 +39,43 @@ jobs:
}
}' -F owner="$OWNER" -F name="${REPO#*/}" -F pr=$PR_NUMBER)

MILESTONE_NUMBER=$(echo "$API_RESPONSE" | jq -r '.data.repository.pullRequest.closingIssuesReferences.nodes[0].milestone.number // "null"')
MILESTONE_TITLE=$(echo "$API_RESPONSE" | jq -r '.data.repository.pullRequest.closingIssuesReferences.nodes[0].milestone.title // "null"')
CURRENT_PR_MILESTONE=$(echo "$API_RESPONSE" | jq -r '.data.repository.pullRequest.milestone.number // "null"')

# 2. Check if a milestone was found
if [ "$MILESTONE_NUMBER" != "null" ] && [ -n "$MILESTONE_NUMBER" ]; then
if [ "$MILESTONE_NUMBER" = "$CURRENT_PR_MILESTONE" ]; then
echo "PR already has milestone '$MILESTONE_TITLE' set. No update needed."
else
echo "Found milestone '$MILESTONE_TITLE' from linked issue. Assigning to PR..."
gh pr edit $PR_NUMBER --milestone "$MILESTONE_TITLE" --repo "$REPO"
fi
else
echo "No milestone found on linked issues or no issues linked."
# 2. Collect all X.Y.Z milestone titles from linked issues, dedupe, version-sort, pick highest.
MILESTONE_TITLE=$(echo "$API_RESPONSE" \
| jq -r '.data.repository.pullRequest.closingIssuesReferences.nodes[].milestone.title // empty' \
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -uV \
| tail -n1)

CURRENT_PR_MILESTONE_TITLE=$(echo "$API_RESPONSE" | jq -r '.data.repository.pullRequest.milestone.title // "null"')

# 3. No qualifying milestone found across all linked issues.
if [ -z "$MILESTONE_TITLE" ]; then
echo "No X.Y.Z milestone found on any linked issue. Nothing to sync."
exit 0
fi

# 4. PR already has that exact milestone title — nothing to do.
if [ "$MILESTONE_TITLE" = "$CURRENT_PR_MILESTONE_TITLE" ]; then
echo "PR already has milestone '$MILESTONE_TITLE' set. No update needed."
exit 0
fi

echo "Candidate milestone: '$MILESTONE_TITLE' (current PR milestone: '$CURRENT_PR_MILESTONE_TITLE')"

# 5. Confirm the milestone title exists as an OPEN milestone on this repo.
# gh pr edit --milestone only accepts open milestones; closed ones return "not found".
REPO_MILESTONE_MATCH=$(gh api "repos/$REPO/milestones?per_page=100&state=open" --paginate \
| jq -r '.[].title' \
| grep -Fx "$MILESTONE_TITLE" || true)

if [ -z "$REPO_MILESTONE_MATCH" ]; then
echo "::warning::Milestone '$MILESTONE_TITLE' not found as an open milestone on $REPO (it may be closed or deleted). Skipping PR milestone update."
exit 0
fi

# 6. Assign milestone to PR — treat any failure as a warning, never fail the job.
echo "Assigning milestone '$MILESTONE_TITLE' to PR #$PR_NUMBER..."
if ! gh pr edit "$PR_NUMBER" --milestone "$MILESTONE_TITLE" --repo "$REPO"; then
echo "::warning::Failed to assign milestone '$MILESTONE_TITLE' to PR #$PR_NUMBER. Manual update may be needed."
fi
exit 0
19 changes: 18 additions & 1 deletion @types/lib/metadataTypes/Asset.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/Asset.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading