diff --git a/.github/workflows/_get_pr_id.yml b/.github/workflows/_get_pr_id.yml index 78b56d1c..a0f8a78d 100644 --- a/.github/workflows/_get_pr_id.yml +++ b/.github/workflows/_get_pr_id.yml @@ -4,9 +4,6 @@ name: Get PR ID on: workflow_call: inputs: - repository: - type: string - required: true commit-sha: type: string required: true @@ -32,7 +29,7 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GH_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/${{ inputs.repository }}/commits/${{ inputs.commit-sha }} | \ + https://api.github.com/repos/${{ github.repository }}/commits/${{ inputs.commit-sha }} | \ jq -r ".commit.message" ) ID=$(echo "$commit_message" | head -1 | grep -o "(#.*)" | grep -o "[0-9]*") diff --git a/.github/workflows/test_get_pr_id.yml b/.github/workflows/test_get_pr_id.yml index 7886d890..d34a9155 100644 --- a/.github/workflows/test_get_pr_id.yml +++ b/.github/workflows/test_get_pr_id.yml @@ -9,25 +9,71 @@ on: - .github/workflows/_get_pr_id.yml - .github/workflows/test_get_pr_id.yml + jobs: - pr: + main_commit: uses: .github/workflows/_get_pr_id.yml with: - repository: "bitwarden/gh-actions" commit-sha: "7d46c75af91adbfdfc70689f4d8b3405b26bda6b" - test_pr: - name: Test Get PR ID + + branch_commit: + uses: .github/workflows/_get_pr_id.yml + with: + commit-sha: "f30be53c2a5b3d61928c0f41a2e25605a9901d6a" + + + dne_commit: + uses: .github/workflows/_get_pr_id.yml + with: + commit-sha: "f30be53c2a5b3d61928c0f41a2e25605a9901d6b" + + + test_main_commit: + name: Test Get PR ID - Success runs-on: ubuntu-22.04 needs: - - pr + - main_commit steps: - - name: Assert PR ID + - name: Assert env: - ID: ${{ needs.pr.outputs.id }} + ID: ${{ needs.main_commit.outputs.id }} run: | if [[ "$ID" != "196" ]]; then exit 1 fi exit 0 + + test_branch_pr: + name: Test Get PR ID - empty for non-main commit + runs-on: ubuntu-22.04 + needs: + - branch_commit + steps: + - name: Assert + env: + ID: ${{ needs.branch_commit.outputs.id }} + run: | + if [[ "$ID" != "" ]]; then + exit 1 + fi + + exit 0 + + + test_dne_commit: + name: Test Get PR ID - empty for non-existent commit + runs-on: ubuntu-22.04 + needs: + - dne_commit + steps: + - name: Assert + env: + ID: ${{ needs.dne_commit.outputs.id }} + run: | + if [[ "$ID" != "" ]]; then + exit 1 + fi + + exit 0