()
| 84 | |
| 85 | // Helper function to get the default branch of the dispatch target repository |
| 86 | const getDefaultBranchRef = async () => { |
| 87 | // Only use the context payload's default_branch when dispatching to the caller's own repo |
| 88 | if (!isCrossRepoDispatch && context.payload.repository?.default_branch) { |
| 89 | return `refs/heads/${context.payload.repository.default_branch}`; |
| 90 | } |
| 91 | |
| 92 | // Fall back to querying the target repository |
| 93 | try { |
| 94 | const { data: repoData } = await githubClient.rest.repos.get({ |
| 95 | owner: repo.owner, |
| 96 | repo: repo.repo, |
| 97 | }); |
| 98 | return `refs/heads/${repoData.default_branch}`; |
| 99 | } catch (error) { |
| 100 | core.warning(`Failed to fetch default branch: ${getErrorMessage(error)}`); |
| 101 | return "refs/heads/main"; |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | // When running in a PR context, GITHUB_REF points to the merge ref (refs/pull/{PR_NUMBER}/merge) |
| 106 | // which is not a valid branch ref for dispatching workflows. Instead, we need to use |
no test coverage detected