You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2026/10/16 21:01:18 UTC

(maven-gh-actions-shared) branch v5 updated: Add pr-number composite action [ci skip]

This is an automated email from the ASF dual-hosted git repository.

slawekjaranowski pushed a commit to branch v5
in repository https://gitbox.apache.org/repos/asf/maven-gh-actions-shared.git


The following commit(s) were added to refs/heads/v5 by this push:
     new 888e9bf  Add pr-number composite action [ci skip]
888e9bf is described below

commit 888e9bf4a6e66c00c382e8193f132066572ea509
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Fri Oct 16 22:51:02 2026 +0200

    Add pr-number composite action [ci skip]
    
    Find the pull request whose current head is the given commit, also for
    pull requests from forks, where workflow_run.pull_requests is empty.
    
    Co-Authored-By: Claude Opus 5.5 <no...@anthropic.com>
---
 .github/actions/pr-number/action.yml | 58 ++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/.github/actions/pr-number/action.yml b/.github/actions/pr-number/action.yml
new file mode 100644
index 0000000..453131e
--- /dev/null
+++ b/.github/actions/pr-number/action.yml
@@ -0,0 +1,58 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: "PR number"
+description: "Find the pull request whose current head is the given commit"
+
+inputs:
+  head-sha:
+    description: "Commit the pull request head must point to"
+    required: true
+  state:
+    description: "Pull request state to search: open, closed, merged or all"
+    required: true
+  repository:
+    description: "Repository to search"
+    default: ${{ github.repository }}
+  token:
+    description: "Token used for the GitHub API"
+    default: ${{ github.token }}
+
+outputs:
+  number:
+    description: "Pull request number, empty when no pull request matches"
+    value: ${{ steps.pr.outputs.number }}
+
+runs:
+  using: "composite"
+  steps:
+    - name: Find the pull request
+      id: pr
+      shell: bash
+      env:
+        GH_TOKEN: ${{ inputs.token }}
+        REPO: ${{ inputs.repository }}
+        HEAD_SHA: ${{ inputs.head-sha }}
+        STATE: ${{ inputs.state }}
+      run: |
+        [[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::bad head sha"; exit 1; }
+        [[ "$STATE" =~ ^(open|closed|merged|all)$ ]] || { echo "::error::bad state"; exit 1; }
+        PR=$(gh pr list -R "$REPO" --state "$STATE" --search "$HEAD_SHA" \
+               --json number,headRefOid \
+               --jq ".[] | select(.headRefOid == \"$HEAD_SHA\") | .number" | head -n1)
+        echo "PR number: ${PR:-<none>} for commit: $HEAD_SHA"
+        echo "number=$PR" >> "$GITHUB_OUTPUT"