Skip to content

[SPEC] Spec mthreads root python code #1510

[SPEC] Spec mthreads root python code

[SPEC] Spec mthreads root python code #1510

Workflow file for this run

name: "Labelling new pull requests"
# pull_request_target is used so that the workflow runs with write permissions
# even on PRs from forks, allowing labels to be applied.
# This is safe here because no code from the PR is checked out or executed;
# the labeler only reads the list of changed file paths.
on:
pull_request_target:
types:
- opened
- reopened
- ready_for_review
- synchronize
- edited
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- id: labeler
uses: actions/labeler@v6
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
configuration-path: .github/new-prs-labeler.yml
- name: Sync target branch label
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" # The base branch name of PR
PR_NUMBER="${{ github.event.pull_request.number }}" # The PR number for API calls
# Get all branch names in the repo (dynamically, no hardcoded list needed)
BRANCH_NAMES=$(gh api "repos/$GITHUB_REPOSITORY/branches" --paginate --jq '.[].name')
# Get all labels currently on this PR, with one label per line
CURRENT_LABELS=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json labels --jq '.labels[].name')
# Remove any label that matches a branch name but is not the target branch
while IFS= read -r LABEL; do
if [ "$LABEL" != "$TARGET_BRANCH" ] && echo "$BRANCH_NAMES" | grep -qx "$LABEL"; then
gh pr edit "$PR_NUMBER" --remove-label "$LABEL" --repo "$GITHUB_REPOSITORY" 2>/dev/null || true
fi
done <<< "$CURRENT_LABELS"
# Ensure the target branch label exists (create if needed) and add it
gh label create "$TARGET_BRANCH" --repo "$GITHUB_REPOSITORY" 2>/dev/null || true
gh pr edit "$PR_NUMBER" --add-label "$TARGET_BRANCH" --repo "$GITHUB_REPOSITORY"