MCPcopy Index your code
hub / github.com/github/docs / setBranchAsRef

Function setBranchAsRef

src/graphql/scripts/update-files.js:121–147  ·  view source on GitHub ↗
(options, graphqlVersion, branch = false)

Source from the content-addressed store, hash-verified

119}
120
121async function setBranchAsRef(options, graphqlVersion, branch = false) {
122 const versionType = getVersionType(graphqlVersion)
123 const defaultBranch = 'master'
124
125 const branches = {
126 dotcom: defaultBranch,
127 ghec: defaultBranch,
128 ghes: `enterprise-${graphqlVersion.replace('ghes-', '')}-release`,
129 // TODO confirm the below is accurate after the release branch is created
130 ghae: 'github-ae-release',
131 }
132
133 // the first time this runs, it uses the branch found for the version above
134 if (!branch) branch = branches[versionType]
135
136 // set the branch as the ref
137 options.ref = `heads/${branch}`
138
139 // check whether the branch can be found in github/github
140 const foundRefs = await listMatchingRefs(...Object.values(options))
141
142 // if foundRefs array is empty, the branch cannot be found, so try a fallback
143 if (!foundRefs.length) {
144 const fallbackBranch = defaultBranch
145 await setBranchAsRef(options, graphqlVersion, fallbackBranch)
146 }
147}
148
149// given a GraphQL version like `ghes-2.22`, return `ghes`;
150// given a GraphQL version like `ghae` or `dotcom`, return as is

Callers 1

getRemoteRawContentFunction · 0.85

Calls 2

listMatchingRefsFunction · 0.90
getVersionTypeFunction · 0.85

Tested by

no test coverage detected