Skip to content

Commit

Permalink
Merge pull request #159 from Lombiq/issue/OSOE-506
Browse files Browse the repository at this point in the history
OSOE-506: Authenticate GitHub API request with GITHUB_TOKEN
  • Loading branch information
DemeSzabolcs authored Dec 25, 2022
2 parents bcd643d + b48b522 commit da0369a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions .github/actions/verify-submodule-pull-request/Check-Parent.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
param(
param(
[string] $Repository,
[string] $Branch
)

$requestParameters = @{
Uri = "https://api.github.com/repos/$Repository/pulls?state=open&per_page=100"
Method = "Get"
Headers = @{ Accept = "application/vnd.github.v3+json" }
}
$titles = (Invoke-WebRequest @requestParameters).Content | ConvertFrom-Json | ForEach-Object { $PSItem.title }

if (!($Branch -match '(\w+-\d+)'))
{
exit
}

$url = "https://api.github.com/repos/$Repository/pulls?state=open&per_page=100"
$response = Invoke-WebRequest $url -Headers (Get-GitHubApiAuthorizationHeader) -Method Get
$titles = $response.Content | ConvertFrom-Json | ForEach-Object { $PSItem.title }

$issueCode = $matches[0]
$lookFor = "${issueCode}:"
if (($titles | Where-Object { $PSItem -and $PSItem.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 }
Set-Failed "Couldn't find any pull request whose title starts with `"$lookFor`" in $Repository. Please create one."
Set-Failed "Couldn't find any pull request whose title starts with `"$lookFor`" in $Repository. Please create one."
4 changes: 1 addition & 3 deletions .github/actions/verify-submodule-pull-request/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ inputs:
runs:
using: "composite"
steps:
- name: Setup and Print PR Title
- name: Setup Scripts
shell: pwsh
run: |
Write-Output "Pull Request Title: ${{ inputs.title }}"
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/validate-submodule-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
- name: Ensure Parent PR Exists
if: github.event.pull_request != ''
uses: Lombiq/GitHub-Actions/.github/actions/verify-submodule-pull-request@dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: ${{ github.event.pull_request.title }}
repository: ${{ inputs.repository }}

0 comments on commit da0369a

Please sign in to comment.