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

Method uploadAndCommit

packages/decap-cms-backend-gitlab/src/API.ts:584–624  ·  view source on GitHub ↗
(
    items: CommitItem[],
    { commitMessage = '', branch = this.branch, newBranch = false },
  )

Source from the content-addressed store, hash-verified

582 }
583
584 async uploadAndCommit(
585 items: CommitItem[],
586 { commitMessage = '', branch = this.branch, newBranch = false },
587 ) {
588 const actions = items.map(item => ({
589 action: item.action,
590 file_path: item.path,
591 ...(item.oldPath ? { previous_path: item.oldPath } : {}),
592 ...(item.base64Content !== undefined
593 ? { content: item.base64Content, encoding: 'base64' }
594 : {}),
595 }));
596
597 const commitParams: CommitsParams = {
598 branch,
599 commit_message: commitMessage,
600 actions,
601 ...(newBranch ? { start_branch: this.branch } : {}),
602 };
603 if (this.commitAuthor) {
604 const { name, email } = this.commitAuthor;
605 commitParams.author_name = name;
606 commitParams.author_email = email;
607 }
608
609 try {
610 const result = await this.requestJSON({
611 url: `${this.repoURL}/repository/commits`,
612 method: 'POST',
613 headers: { 'Content-Type': 'application/json; charset=utf-8' },
614 body: JSON.stringify(commitParams),
615 });
616 return result;
617 } catch (error) {
618 const message = error.message || '';
619 if (newBranch && message.includes(`Could not update ${branch}`)) {
620 await throwOnConflictingBranches(branch, name => this.getBranch(name), API_NAME);
621 }
622 throw error;
623 }
624 }
625
626 async getCommitItems(
627 files: { path: string; newPath?: string }[],

Callers 3

persistFilesMethod · 0.95
APIClass · 0.95
editorialWorkflowGitMethod · 0.95

Calls 3

getBranchMethod · 0.95
mapMethod · 0.80

Tested by

no test coverage detected