Skip to content

Commit

Permalink
Merge pull request #7 from Lombiq/issue/OSOE-131
Browse files Browse the repository at this point in the history
OSOE-131: Detect in submodules if there's no PR here
  • Loading branch information
0liver authored Jun 8, 2022
2 parents f848747 + cef5d8d commit 4ac6995
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Verify Submodule Pull Request

on:
workflow_call:
inputs:
repo:
required: false
type: string
default: Lombiq/Open-Source-Orchard-Core-Extensions

env:
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}

defaults:
run:
shell: pwsh

jobs:
parent-pull-request-exists:
runs-on: ubuntu-latest
name: Ensure Parent PR Exists
steps:
- name: Print PR Title
run: echo $Env:PULL_REQUEST_TITLE

- name: Add Commands to Subsequent Workflow Steps
run: |
$code = @'
<#
.Synopsis
Fails the current step with the provided message. Same as "core.setFailed()" from the official toolkit
(https://github.com/actions/toolkit).
#>
function Set-Failed([Parameter(Mandatory = $True)] [string] $Message)
{
Write-Output "::error::$Message"
exit 1
}
'@
$profileDirectory = [System.IO.Path]::GetDirectoryName($Profile)
[System.IO.Directory]::CreateDirectory($profileDirectory)
$code | Out-File $Profile
- name: Ensure Current PR Title Includes Issue Code
run: |
if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { exit 0 }
Set-Failed 'The pull request title is not in the expected format. Please start with the issue code followed by a colon and the title, e.g. "PROJ-123: My PR Title".'
- name: Ensure Parent Repository Contains Matching PR
run: |
$url = 'https://api.github.com/repos/${{ inputs.repo }}/pulls?state=open&per_page=100'
$titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title }
$issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1'
$lookFor = "${issueCode}:"
if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 }
Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`". Please create one."

0 comments on commit 4ac6995

Please sign in to comment.