From 09a79a0da3ca768e556b93f76833c2b5764548c0 Mon Sep 17 00:00:00 2001 From: "Gordon Beeming [SSW]" Date: Wed, 13 Sep 2023 12:53:36 +1000 Subject: [PATCH] When a PR comes from a fork we shouldn't add labels (#10) --- .github/workflows/pr-manage-stale.yml | 39 +++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-manage-stale.yml b/.github/workflows/pr-manage-stale.yml index f094f1e..dbba6bd 100644 --- a/.github/workflows/pr-manage-stale.yml +++ b/.github/workflows/pr-manage-stale.yml @@ -24,12 +24,31 @@ jobs: new_pull_request: if: ${{ github.event_name == 'pull_request' }} runs-on: ubuntu-latest - steps: - - name: add labels - uses: actions-ecosystem/action-add-labels@v1 - with: - labels: | - Age: 🥚 - New + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: add label + shell: pwsh + run: | + $thisPr = gh pr view ${{ github.event.pull_request.number }} --json number,isCrossRepository | ConvertFrom-Json + if ($thisPr.isCrossRepository) { + Write-Output "Skipping cross repository PR" + return + } + + # ensure labels exist - create them if they don't + # https://docs.github.com/en/rest/reference/issues#create-a-label + $label = "Age: 🥚 - New" + $description = "About 2 hours old" + Write-Output "Ensuring label exists: $label ($description))" + gh api repos/${{ github.repository }}/labels -f name="$label" -f color=000000 -f description="$description" + + Write-Output "Adding label: $label" + gh pr edit $thisPr.number --add-label "$label" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + scheduled_run: if: ${{ github.event_name != 'pull_request' }} @@ -102,6 +121,10 @@ jobs: } $newLabel = $labels[$ageAsPoints - 1] + $labelExists = $prLabels | Where-Object { $_.name -eq $newLabel } + if ($labelExists) { + return + } Write-Output "Adding label: $newLabel" # all labels except the new label @@ -111,7 +134,7 @@ jobs: gh pr edit $number --add-label "$newLabel" --remove-label "$allLabels" Write-Output "" - if ($ageInHours -ge 36 -and $ageInHours -lt 38 -and $author.is_bot -eq $false) { # after 36 hours old + if ($ageInHours -eq 36 -and $author.is_bot -eq $false) { # 36 hours old $comment = @" Howzit @$($author.login), @@ -128,4 +151,4 @@ jobs: } } env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file