Skip to content

Commit

Permalink
renames, updates pr title access
Browse files Browse the repository at this point in the history
  • Loading branch information
JackSpagnoliNHS committed Jan 23, 2024
1 parent efb72a7 commit e9470c8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: 'Combine PRs'
name: "Combine PRs"

# Controls when the action will run - in this case triggered manually
on:
workflow_dispatch:
inputs:
branchPrefix:
description: 'Branch prefix to find combinable PRs based on'
description: "Branch prefix to find combinable PRs based on"
required: true
default: 'dependabot'
default: "dependabot"
mustBeGreen:
description: 'Only combine PRs that are green (status is success)'
description: "Only combine PRs that are green (status is success)"
required: true
default: "true"
combineBranchName:
description: 'Name of the branch to combine PRs into'
description: "Name of the branch to combine PRs into"
required: true
default: 'combine-dependabot-PRs'
default: "combine-dependabot-PRs"
ignoreLabel:
description: 'Exclude PRs with this label'
description: "Exclude PRs with this label"
required: true
default: 'nocombine'
default: "nocombine"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
core.setFailed('Failed to create combined branch - maybe a branch by that name already exists?');
return;
}
let combinedPRs = [];
let mergeFailedPRs = [];
for(const { branch, prString } of branchesAndPRStrings) {
Expand All @@ -133,7 +133,7 @@ jobs:
mergeFailedPRs.push(prString);
}
}
console.log('Creating combined PR');
const combinedPRsString = combinedPRs.join('\n');
let body = '✅ This PR was created by the Combine PRs action by combining the following PRs:\n' + combinedPRsString;
Expand All @@ -148,4 +148,4 @@ jobs:
head: '${{ github.event.inputs.combineBranchName }}',
base: baseBranch,
body: body
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }}


File renamed without changes.
15 changes: 13 additions & 2 deletions .github/workflows/pr_title_check.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
name: Quality Checks

on:
# Will be null if PR title was not updated
workflow_call:
inputs:
PR_TITLE:
required: true
type: string

jobs:
pr_title_format_check:
runs-on: ubuntu-latest
steps:
# If PR title was not updated by the dependabot prefixer, set PR_TITLE variable to PR title
- name: Set Up-to-date PR Title
if: ${{ !env.PR_TITLE }}
run: |
echo "PR_TITLE=${{ github.event.pull_request.title }}" >> $GITHUB_ENV
- name: Check PR Title is Prefixed with Change Type
run: |
if [[ "${{ github.event.pull_request.title }}" =~ ^(Fix|Update|New|Breaking|Docs|Build|Upgrade|Chore):.*$ ]]; then
if [[ "${{ env.PR_TITLE }}" =~ ^(Fix|Update|New|Breaking|Docs|Build|Upgrade|Chore):.*$ ]]; then
echo "PR title is prefixed with change type."
else
echo "PR title is not prefixed with change type."
Expand All @@ -21,7 +32,7 @@ jobs:
- name: Check PR Title contains Ticket/Dependabot Reference
run: |
if [[ "${{ github.event.pull_request.title }}" =~ ^.*:.*\[(AEA-[0-9]{4}|dependabot)\].*-.*$ ]]; then
if [[ "${{ env.PR_TITLE }}" =~ ^.*:.*\[(AEA-[0-9]{4}|dependabot)\].*-.*$ ]]; then
echo "PR title contains ticket or dependabot reference."
else
echo "PR title does not contain ticket or dependabot reference."
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ on:

jobs:
dependabot_prefix_title:
uses: ./.github/workflows/rename-dependabot-prs.yml
uses: ./.github/workflows/rename_dependabot_prs.yml

quality_checks:
needs: dependabot_prefix_title
uses: ./.github/workflows/quality_checks.yml
with:
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
Expand All @@ -18,3 +19,6 @@ jobs:
pr_title_format_check:
needs: dependabot_prefix_title
uses: ./.github/workflows/pr_title_check.yml
with:
# Will be null if PR title was not updated
PR_TITLE: ${{ needs.dependabot_prefix_title.outputs.updated_pr_title }}
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,29 @@ jobs:
run: |
if [[ "${{ env.PR_IS_DEPENDABOT }}" == "true" && "${{ env.PR_IS_PREFIXED }}" == "false" ]]; then
echo "PR title should be updated."
echo "PR_TITLE_SHOULD_BE_UPDATED=true" >> $GITHUB_ENV
echo "PR_UPDATED_TITLE=Chore: [dependabot] - ${{ github.event.pull_request.title }}" >> $GITHUB_ENV
else
echo "PR title should not be updated."
echo "No change to PR title."
fi
- name: Update PR title with Prefix
if: env.PR_TITLE_SHOULD_BE_UPDATED == 'true'
if: env.PR_UPDATED_TITLE
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const new_title = `Chore: [dependabot] - ${{ github.event.pull_request.title }}`
console.log(`Updating PR title to: ${new_title}`)
console.log(`Updating PR title to: ${{ env.PR_UPDATED_TITLE }}`)
github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
title: new_title
title: ${{ env.PR_UPDATED_TITLE }}
})
- name: Set Updated PR Title as Output
if: env.PR_UPDATED_TITLE
id: set_updated_pr_title_output
run: |
echo "::set-output name=updated_pr_title::${{ env.PR_UPDATED_TITLE }}"

0 comments on commit e9470c8

Please sign in to comment.