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

Class API

packages/decap-cms-backend-gitlab/src/API.ts:211–1042  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211export default class API {
212 apiRoot: string;
213 graphQLAPIRoot: string;
214 token: string | boolean;
215 branch: string;
216 useOpenAuthoring?: boolean;
217 repo: string;
218 repoURL: string;
219 commitAuthor?: CommitAuthor;
220 squashMerges: boolean;
221 initialWorkflowStatus: string;
222 cmsLabelPrefix: string;
223 requestFunction?: (req: ApiRequest) => Promise<Response>;
224
225 graphQLClient?: ApolloClient<NormalizedCacheObject>;
226
227 constructor(config: Config) {
228 this.apiRoot = config.apiRoot || 'https://gitlab.com/api/v4';
229 this.graphQLAPIRoot = config.graphQLAPIRoot || 'https://gitlab.com/api/graphql';
230 this.token = config.token || false;
231 this.requestFunction = config.requestFunction;
232 this.branch = config.branch || 'master';
233 this.repo = config.repo || '';
234 this.repoURL = `/projects/${encodeURIComponent(this.repo)}`;
235 this.squashMerges = config.squashMerges;
236 this.initialWorkflowStatus = config.initialWorkflowStatus;
237 this.cmsLabelPrefix = config.cmsLabelPrefix;
238 if (config.useGraphQL === true) {
239 this.graphQLClient = this.getApolloClient();
240 }
241 }
242
243 getApolloClient() {
244 const authLink = setContext((_, { headers }) => {
245 return {
246 headers: {
247 'Content-Type': 'application/json; charset=utf-8',
248 ...headers,
249 Authorization: this.token ? `Bearer ${this.token}` : '',
250 },
251 };
252 });
253 const httpLink = createHttpLink({
254 uri: this.graphQLAPIRoot,
255 fetch: this.requestFunction
256 ? (input: RequestInfo, init?: RequestInit) => {
257 const url = typeof input === 'string' ? input : input.url;
258 const request = unsentRequest.fromFetchArguments(url, init).toJS() as ApiRequest;
259 return this.requestFunction!(request);
260 }
261 : undefined,
262 });
263 return new ApolloClient({
264 link: authLink.concat(httpLink),
265 cache: new InMemoryCache(),
266 defaultOptions: {
267 watchQuery: {
268 fetchPolicy: NO_CACHE,

Callers

nothing calls this directly

Calls 15

requestMethod · 0.95
getDefaultBranchMethod · 0.95
uploadAndCommitMethod · 0.95
requestWithBackoffFunction · 0.90
responseParserFunction · 0.90
readFileFunction · 0.90
parseLinkHeaderFunction · 0.90
thenFunction · 0.90
getMaxAccessFunction · 0.85
MapInterface · 0.85
batchFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected