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

Class API

packages/decap-cms-backend-forgejo/src/API.ts:113–1054  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111};
112
113export default class API {
114 apiRoot: string;
115 token: string;
116 branch: string;
117 repo: string;
118 originRepo: string;
119 repoOwner: string;
120 repoName: string;
121 originRepoOwner: string;
122 originRepoName: string;
123 repoURL: string;
124 originRepoURL: string;
125 useOpenAuthoring: boolean;
126 cmsLabelPrefix: string;
127 initialWorkflowStatus: string;
128
129 _userPromise?: Promise<ForgejoUser>;
130 _metadataSemaphore?: Semaphore;
131
132 commitAuthor?: {};
133
134 constructor(config: Config) {
135 if (!config.apiRoot) {
136 throw new Error('API root is required');
137 }
138
139 this.apiRoot = config.apiRoot;
140 this.token = config.token || '';
141 this.branch = config.branch || 'master';
142 this.repo = config.repo || '';
143 this.originRepo = config.originRepo || this.repo;
144 this.useOpenAuthoring = !!config.useOpenAuthoring;
145 this.cmsLabelPrefix = config.cmsLabelPrefix || '';
146 this.initialWorkflowStatus = config.initialWorkflowStatus || 'draft';
147 this.repoURL = `/repos/${this.repo}`;
148 this.originRepoURL = `/repos/${this.originRepo}`;
149
150 const [repoParts, originRepoParts] = [this.repo.split('/'), this.originRepo.split('/')];
151 this.repoOwner = repoParts[0];
152 this.repoName = repoParts[1];
153
154 this.originRepoOwner = originRepoParts[0];
155 this.originRepoName = originRepoParts[1];
156 }
157
158 static DEFAULT_COMMIT_MESSAGE = 'Automatically generated by Static CMS';
159
160 user(): Promise<{ full_name: string; login: string; avatar_url: string; email: string }> {
161 if (!this._userPromise) {
162 this._userPromise = this.getUser();
163 }
164 return this._userPromise;
165 }
166
167 getUser() {
168 return this.request('/user') as Promise<ForgejoUser>;
169 }
170

Callers

nothing calls this directly

Calls 2

getBranchPullRequestMethod · 0.95
deleteBranchMethod · 0.95

Tested by

no test coverage detected