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

Class API

packages/decap-cms-backend-github/src/API.ts:232–2000  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230let migrationNotified = false;
231
232export default class API {
233 apiRoot: string;
234 token: string;
235 tokenKeyword: string;
236 branch: string;
237 useOpenAuthoring?: boolean;
238 repo: string;
239 originRepo: string;
240 repoOwner: string;
241 repoName: string;
242 originRepoOwner: string;
243 originRepoName: string;
244 repoURL: string;
245 originRepoURL: string;
246 mergeMethod: string;
247 initialWorkflowStatus: string;
248 cmsLabelPrefix: string;
249 baseUrl?: string;
250 getUser: ({ token }: { token: string }) => Promise<GitHubUser>;
251 _userPromise?: Promise<GitHubUser>;
252 _metadataSemaphore?: Semaphore;
253
254 commitAuthor?: {};
255
256 constructor(config: Config) {
257 this.apiRoot = config.apiRoot || 'https://api.github.com';
258 this.token = config.token || '';
259 this.tokenKeyword = config.tokenKeyword || 'token';
260 this.branch = config.branch || 'master';
261 this.useOpenAuthoring = config.useOpenAuthoring;
262 this.repo = config.repo || '';
263 this.originRepo = config.originRepo || this.repo;
264 this.repoURL = `/repos/${this.repo}`;
265 // when not in 'useOpenAuthoring' mode originRepoURL === repoURL
266 this.originRepoURL = `/repos/${this.originRepo}`;
267
268 const [repoParts, originRepoParts] = [this.repo.split('/'), this.originRepo.split('/')];
269 this.repoOwner = repoParts[0];
270 this.repoName = repoParts[1];
271
272 this.originRepoOwner = originRepoParts[0];
273 this.originRepoName = originRepoParts[1];
274
275 this.mergeMethod = config.squashMerges ? 'squash' : 'merge';
276 this.cmsLabelPrefix = config.cmsLabelPrefix;
277 this.initialWorkflowStatus = config.initialWorkflowStatus;
278 this.baseUrl = config.baseUrl;
279 this.getUser = config.getUser;
280 }
281
282 static DEFAULT_COMMIT_MESSAGE = 'Automatically generated by Decap CMS';
283
284 user(): Promise<{ name: string; login: string; email?: string }> {
285 if (!this._userPromise) {
286 this._userPromise = this.getUser({ token: this.token });
287 }
288 return this._userPromise.then(user => ({
289 name: user.name || 'Unknown',

Callers

nothing calls this directly

Calls 2

getBranchPullRequestMethod · 0.95
deleteBranchMethod · 0.95

Tested by

no test coverage detected