Skip to content

Playlist: Skip hidden tracks when building the track list #2631

Playlist: Skip hidden tracks when building the track list

Playlist: Skip hidden tracks when building the track list #2631

Workflow file for this run

name: Review routing
on:
# Runs this workflow from the target branch, not from the pull request.
# This makes it safe to give the job the decision API key, also for pull
# requests from forks. The job reads the pull request only through the
# GitHub API, and never runs its code.
pull_request_target:
types: [opened, reopened, synchronize, ready_for_review]
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
# Only the newest commit needs scores and review requests.
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true
jobs:
route:
name: Score the routing rules
# Pull requests to release branches are backports, which need no
# routing. A draft gets its scores when it is ready for review.
if: ${{ ! github.event.pull_request.draft && github.event.pull_request.base.ref == github.event.repository.default_branch }}
runs-on: 'ubuntu-slim'
# This job has the API key, so its token can only read. The report goes
# to the run summary, so the job writes nothing to the pull request.
permissions:
contents: read
pull-requests: read
timeout-minutes: 5
outputs:
reviewers: ${{ steps.score.outputs.reviewers }}
steps:
# On `pull_request_target`, this checks out the base branch. The
# tool has no runtime dependencies, so `npm run` needs no install.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: |
tools/review-routing
.github/review-routing
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
persist-credentials: false
# The npm that comes with this Node.js meets the `devEngines` floor
# in package.json, so the job does not install another npm.
- name: Use desired version of Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: '.nvmrc'
check-latest: true
package-manager-cache: false
- name: Score the rules
id: score
env:
DECISION_API_URL: ${{ vars.REVIEW_ROUTING_DECISION_API_URL }}
DECISION_API_KEY: ${{ secrets.REVIEW_ROUTING_DECISION_API_KEY }}
DECISION_MODEL: ${{ vars.REVIEW_ROUTING_DECISION_MODEL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
REPO: ${{ github.repository }}
run: |
# `--silent` keeps npm's own header out of the report.
# The tool runs in its workspace directory, so the path is
# absolute.
report="$(npm run --silent --workspace @wordpress/review-routing-tools route -- --pr "$PR_NUMBER" --repo "$REPO" --json-file "$RUNNER_TEMP/decisions.json")"
printf '%s\n' "$report"
printf '%s\n' "$report" >> "$GITHUB_STEP_SUMMARY"
# Several rules can name the same reviewer, who gets one request.
reviewers="$(jq -c '[ .[] | select( .requestReview ) | .reviewers[] ] | unique' "$RUNNER_TEMP/decisions.json")"
printf 'reviewers=%s\n' "$reviewers" >> "$GITHUB_OUTPUT"
request:
name: Request reviews
needs: route
if: ${{ needs.route.outputs.reviewers != '[]' }}
runs-on: 'ubuntu-slim'
permissions:
pull-requests: write
timeout-minutes: 5
steps:
# A reviewer is requested at most once for each pull request. GitHub
# removes a reviewer from the requested reviewers after they review,
# so the timeline is used instead.
- name: Request reviews
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
REVIEWERS: ${{ needs.route.outputs.reviewers }}
with:
script: |
const { owner, repo } = context.repo;
const pull = context.payload.pull_request;
const events = await github.paginate(
github.rest.issues.listEventsForTimeline,
{ owner, repo, issue_number: pull.number, per_page: 100 }
);
const skip = new Set(
[
// Exclude the author, who cannot review their own pull request.
pull.user.login,
// Exclude earlier requests using the timeline.
...events
.filter( ( event ) => event.event === 'review_requested' )
.map( ( event ) =>
event.requested_team
? `${ owner }/${ event.requested_team.slug }`
: event.requested_reviewer?.login
),
]
.filter( Boolean )
.map( ( name ) => name.toLowerCase() )
);
const wanted = JSON.parse( process.env.REVIEWERS );
const requested = wanted.filter( ( name ) => ! skip.has( name.toLowerCase() ) );
const skipped = wanted.filter( ( name ) => skip.has( name.toLowerCase() ) );
if ( requested.length ) {
await github.rest.pulls.requestReviewers( {
owner,
repo,
pull_number: pull.number,
reviewers: requested.filter( ( name ) => ! name.includes( '/' ) ),
team_reviewers: requested
.filter( ( name ) => name.includes( '/' ) )
.map( ( name ) => name.split( '/' )[ 1 ] ),
} );
}
const names = ( list ) => list.join( ', ' ) || '(none)';
await core.summary
.addRaw(
`Requested review: ${ names( requested ) }. Skipped, requested before or the author: ${ names( skipped ) }.`
)
.write();