MCPcopy Create free account
hub / github.com/decaporg/decap-cms / getDefaultBranchName

Function getDefaultBranchName

packages/decap-cms-lib-util/src/API.ts:220–253  ·  view source on GitHub ↗
(configs: {
  backend: Backend;
  repo: string;
  token?: string;
  apiRoot?: string;
})

Source from the content-addressed store, hash-verified

218}
219
220export async function getDefaultBranchName(configs: {
221 backend: Backend;
222 repo: string;
223 token?: string;
224 apiRoot?: string;
225}) {
226 let apiPath;
227 const { token, backend, repo, apiRoot } = configs;
228 switch (backend) {
229 case 'gitlab': {
230 apiPath = `/projects/${encodeURIComponent(repo)}`;
231 break;
232 }
233 case 'bitbucket': {
234 apiPath = `/repositories/${repo}`;
235 break;
236 }
237 default: {
238 apiPath = `/repos/${repo}`;
239 }
240 }
241 const repoInfo = await apiRequest(apiPath, { token, backend, apiRoot });
242 let defaultBranchName;
243 if (backend === 'bitbucket') {
244 const {
245 mainbranch: { name },
246 } = repoInfo;
247 defaultBranchName = name;
248 } else {
249 const { default_branch } = repoInfo;
250 defaultBranchName = default_branch;
251 }
252 return defaultBranchName;
253}
254
255export async function readFile(
256 id: string | null | undefined,

Callers 1

authenticateMethod · 0.90

Calls 1

apiRequestFunction · 0.85

Tested by

no test coverage detected