Files
winget-pkgs/.github/workflows/check-duplicate-prs.yml
T
Begula 8b4e8a25a2 Check for duplicate PRs (#29868)
* Create pre-validate-pr.yml

* Update pre-validate-pr.yml

* Update pre-validate-pr.yml

* Update pre-validate-pr.yml

* Update and rename pre-validate-pr.yml to check-duplicate-prs.yml

* Update check-duplicate-prs.yml

* Added check for existing PR and set `is:pr` in API request
2022-03-01 07:11:46 -08:00

42 lines
2.0 KiB
YAML

name: Check duplicate PRs
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'manifests/**'
env:
DUPLICATE_PR_FOUND: 'no'
DUPLICATE_PR_NUMBER: '0'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run validation checks
id: validation
shell: pwsh
run: |
(Invoke-WebRequest https://api.github.com/repos/microsoft/winget-pkgs/pulls/${{ github.event.number }}/files).content | ConvertFrom-Json | ForEach-Object { $changedFiles = @($_.filename) }
$prPath = $changedFiles | ForEach-Object { $_.Remove($_.LastIndexOf("/")) } | Select-Object -Unique
$PackageVersion = $prPath.Substring($prPath.LastIndexOf("/")+1)
$PackageIdentifier = $prPath.Substring($prPath.IndexOf('/',10)+1).TrimEnd("/$PackageVersion") -replace '/','.'
$PRApiResponse = @(Invoke-WebRequest "https://api.github.com/search/issues?q=repo%3Amicrosoft%2Fwinget-pkgs%20%20is%3Apr$($PackageIdentifier -replace '\.', '%2F'))%2F$PackageVersion%20in%3Apath&per_page=1" -UseBasicParsing -ErrorAction SilentlyContinue | ConvertFrom-Json)[0]
if ($PRApiResponse.total_count -gt 0 -and $PRApiResponse.items.number -ne '${{ github.event.number }}')
{
Write-Output "DUPLICATE_PR_FOUND=yes" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "DUPLICATE_PR_NUMBER=$($PRApiResponse.items.number)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
- if: ${{ env.DUPLICATE_PR_FOUND == 'yes' }}
name: Comment on PR
uses: actions/github-script@v5
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Duplicate of #${{ env.DUPLICATE_PR_NUMBER }}'
})