Skip to content

Modernize the workflow. #45

Modernize the workflow.

Modernize the workflow. #45

name: Cleanup Pull Requests
on:
push:
branches:
- trunk
- '3.[89]'
- '[4-9].[0-9]'
- test-close-prs
schedule:
- cron: '0 */12 * * *'
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
jobs:
# Runs the QUnit tests for WordPress.
#
# Performs the following steps:
# - Checks out the repository.
close-prs-push:
name: Close pull requests on commit
runs-on: ubuntu-latest
# if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'push' }}
steps:
- name: Parse commit message
id: fixed-tickets
run: |
COMMIT_MESSAGE=$(cat <<'EOF' | sed -n '/^Fixes #/,/\./p'
${{ github.event.head_commit.message }}
EOF
)
echo "fixed_list=${COMMIT_MESSAGE}" >> $GITHUB_OUTPUT
- name: Find pull requests
id: pr-results
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const fixesLine = "${{ steps.fixed-tickets.outputs.fixed_list }}";
let ticketList = false;
let query = '';
ticketList = fixesLine.match( /[0-9]+/g );
if ( ticketList && ticketList.length > 0 ) {
let tempQuery = query;
ticketList.every( ( value, index ) => {
if ( 0 !== index ) {
tempQuery += ' OR';
}
tempQuery += `https://core.trac.wordpress.org/ticket/${value}`;
if ( tempQuery.length <= 256 ) {
query = tempQuery;
return true;
} else {
return false;
}
});
query += 'is:pr is:open in:title,body repo:WordPress/wordpress-develop';
}
const related_prs = await github.rest.search.issuesAndPullRequests({
q: query,
});
console.log( related_prs );
return related_prs && related_prs.items;
- name: Get git-svn-id
id: git-svn-id
run: |
COMMIT_MESSAGE=$(cat <<'EOF' | sed -n '$p'
${{ github.event.head_commit.message }}
EOF
)
echo "svn_revision_number=${COMMIT_MESSAGE}" >> $GITHUB_OUTPUT
- name: Close pull requests
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const gitSVNIDString = '${{ steps.git-svn-id.outputs.svn_revision_number }}';
const revisionMatch = gitSVNIDString.match( /trunk@([0-9]+)/ );
console.log( revisionMatch[1] );
if ( ! revisionMatch || ! revisionMatch[1] ) {
return;
}
const svnRevision = revisionMatch[1];
const closeMessage = `Merged into WordPress core in changeset https://core.trac.wordpress.org/changeset/${svnRevision}`;
// const prsToClose = ${{ steps.pr-results.outputs.result }}
// prsToClose.forEach( ( { owner, repo, number } ) => {
// const comment = await github.rest.issues.createComment( {
// owner,
// repo,
// pull_number: number,
// body: closeMessage
// } );
// const close = await github.rest.pulls.update( {
// owner: pr.owner,
// repo: pr.repo,
// pull_number: pr.number,
// state: 'closed'
// } )
// } );