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

Method uploadAndCommit

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

Source from the content-addressed store, hash-verified

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