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

Method mutate

packages/decap-cms-backend-github/src/GraphQLAPI.ts:156–194  ·  view source on GitHub ↗
(options: MutationOptions<OperationVariables>)

Source from the content-addressed store, hash-verified

154 }
155
156 async mutate(options: MutationOptions<OperationVariables>) {
157 try {
158 const result = await this.client.mutate(options);
159 return result;
160 } catch (error) {
161 const errors = error.graphQLErrors;
162 if (Array.isArray(errors) && errors.some(e => e.message === 'Ref cannot be created.')) {
163 const refName = options?.variables?.createRefInput?.name || '';
164 const branchName = trimStart(refName, 'refs/heads/');
165 if (branchName) {
166 await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME);
167 }
168 } else if (
169 Array.isArray(errors) &&
170 errors.some(e =>
171 new RegExp(
172 `A ref named "refs/heads/${CMS_BRANCH_PREFIX}/.+?" already exists in the repository.`,
173 ).test(e.message),
174 )
175 ) {
176 const refName = options?.variables?.createRefInput?.name || '';
177 const sha = options?.variables?.createRefInput?.oid || '';
178 const branchName = trimStart(refName, 'refs/heads/');
179 if (branchName && branchName.startsWith(`${CMS_BRANCH_PREFIX}/`) && sha) {
180 try {
181 // this can happen if the branch wasn't deleted when the PR was merged
182 // we backup the existing branch just in case an re-run the mutation
183 await this.backupBranch(branchName);
184 await this.deleteBranch(branchName);
185 const result = await this.client.mutate(options);
186 return result;
187 } catch (e) {
188 console.log(e);
189 }
190 }
191 }
192 throw new APIError(error.message, 500, 'GitHub');
193 }
194 }
195
196 async hasWriteAccess() {
197 const { repoOwner: owner, repoName: name } = this;

Callers 8

patchRefMethod · 0.95
deleteBranchMethod · 0.95
openPRMethod · 0.95
closePRMethod · 0.95
createPRMethod · 0.95
createBranchMethod · 0.95

Calls 5

getBranchMethod · 0.95
deleteBranchMethod · 0.95
someMethod · 0.80
backupBranchMethod · 0.80

Tested by

no test coverage detected