diff --git a/.github/workflows/calculate-branch.yaml b/.github/workflows/calculate-branch.yaml index aa2717d..a650f94 100644 --- a/.github/workflows/calculate-branch.yaml +++ b/.github/workflows/calculate-branch.yaml @@ -6,6 +6,11 @@ on: description: The branch name required: true type: string + owner: + description: The GitHub owner of the repository + required: false + type: string + default: encodium repo: description: The GitHub repository name required: true @@ -29,29 +34,30 @@ jobs: GH_TOKEN: ${{ secrets.github_token }} run: | requested_branch="${{ inputs.branch }}" + owner="${{ inputs.owner }}" repo="${{ inputs.repo }}" branch_name= found= echo "Checking to see if the branch \"${requested_branch}\" exists in this project." + branch_info=$(gh api "/repos/${owner}/${repo}/branches/${requested_branch}" --jq '{name: .name, sha: .commit.sha}') - branch_info=$(gh api "/repos/encodium/${repo}/branches/$requested_branch" --jq '{name: .name, sha: .commit.sha}') - branch_name_candidate=$(echo "$branch_info" | jq -r '.name') - sha=$(echo "$branch_info" | jq -r '.sha') - sha_short=$(echo "$branch_info" | jq -r '.sha[:7]') + branch_name_candidate=$(echo "${branch_info}" | jq -r '.name') + sha=$(echo "${branch_info}" | jq -r '.sha') + sha_short=$(echo "${branch_info}" | jq -r '.sha[:7]') echo "Branch name from response: ${branch_name_candidate}" echo "SHA from response: ${sha}" echo "SHA (short) from response: ${sha_short}" - if [[ "$branch_name_candidate" == "$requested_branch" ]]; + if [[ "${branch_name_candidate}" == "${requested_branch}" ]]; then echo "Branch \"${branch_name_candidate}\" found." - branch_name="$branch_name_candidate" + branch_name="${branch_name_candidate}" found=true fi - echo "branch=$branch_name" >> "$GITHUB_OUTPUT" - echo "found=$found" >> "$GITHUB_OUTPUT" - echo "sha=$sha" >> "$GITHUB_OUTPUT" - echo "sha_short=$sha_short" >> "$GITHUB_OUTPUT" + echo "branch=${branch_name}" >> "$GITHUB_OUTPUT" + echo "found=${found}" >> "$GITHUB_OUTPUT" + echo "sha=${sha}" >> "$GITHUB_OUTPUT" + echo "sha_short=${sha_short}" >> "$GITHUB_OUTPUT"