From 51b1ce9cd4391ad8e3fa2fe0e0e7eba9c8b0029d Mon Sep 17 00:00:00 2001 From: Louis-Amaury Chaib Date: Mon, 16 Oct 2023 19:07:08 +0000 Subject: [PATCH] Support reporting to a PR from another repository Fixes #25 --- README.md | 1 + action.yml | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b00ae2d..fcb22f3 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Available settings: | ------------------------ | --------------------------------------- | ------------------------------------------------------------------------------------------------------------- | | gh_access_token | | Token to access GH API. In most cases you can use GITHUB_TOKEN that is available in the workflow | | report_path | 'reports' | Path to reports from the download artifact action | +| repository | ${{ github.repository }} | Repository containing the commit or pull request that triggered the tests | | sha | ${{ github.sha }} | SHA of the commit that triggered the tests | | pull_request_id | ${{ github.event.number }} | ID of the pull request that triggered pipeline | | summary | 'true' | Add report to job summary | diff --git a/action.yml b/action.yml index 19caddc..2238af0 100644 --- a/action.yml +++ b/action.yml @@ -9,9 +9,13 @@ inputs: required: true default: 'reports' sha: - description: 'SHA of the commit tha triggered the tests' + description: 'SHA of the commit that triggered the tests' required: false default: "${{ github.sha }}" + repository: + description: 'Repository of the commit or pull request that triggered the tests' + required: false + default: "${{ github.repository }}" pull_request_id: description: 'ID of the Pull Request' required: false @@ -34,8 +38,13 @@ runs: steps: - shell: bash run: | - export OWNER="$(echo "${{ github.repository }}" | awk -F / '{print $1}' | sed -e "s/:refs//")" - export REPO="$(echo "${{ github.repository }}" | awk -F / '{print $2}' | sed -e "s/:refs//")" + if [[ "${{ inputs.repository }}" =~ "/" ]]; then + export OWNER="$(echo "${{ inputs.repository }}" | awk -F / '{print $1}' | sed -e "s/:refs//")" + export REPO="$(echo "${{ inputs.repository }}" | awk -F / '{print $2}' | sed -e "s/:refs//")" + else + export OWNER="$(echo "${{ github.repository }}" | awk -F / '{print $1}' | sed -e "s/:refs//")" + export REPO="$(echo "${{ inputs.repository }}" | sed -e "s/:refs//")" + fi echo "REPOSITORY_OWNER=$OWNER" >> $GITHUB_ENV echo "REPOSITORY_NAME=$REPO" >> $GITHUB_ENV - shell: bash