MCPcopy Create free account
hub / github.com/github/gh-aw / getDefaultBranchRef

Function getDefaultBranchRef

actions/setup/js/dispatch_workflow.cjs:86–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls 2

getMethod · 0.80
getErrorMessageFunction · 0.70

Tested by

no test coverage detected