(
branchName: string,
message: string,
files: UpdateFile[]
)
| 109 | } |
| 110 | |
| 111 | async commit( |
| 112 | branchName: string, |
| 113 | message: string, |
| 114 | files: UpdateFile[] |
| 115 | ): Promise<string> { |
| 116 | await this.checkout(branchName); |
| 117 | |
| 118 | await Promise.all( |
| 119 | files.map(async (file) => { |
| 120 | const filePath = join(this.options.repositoryDir, file.path); |
| 121 | const fileParentDir = dirname(filePath); |
| 122 | |
| 123 | if (file.deleted) { |
| 124 | //remove the file or silently ignore if it does not exist |
| 125 | await fs.remove(filePath); |
| 126 | return filePath; |
| 127 | } |
| 128 | |
| 129 | if (!existsSync(filePath)) { |
| 130 | await mkdir(fileParentDir, { recursive: true }); |
| 131 | await writeFile(filePath, file.content ?? ""); |
| 132 | return filePath; |
| 133 | } else if (!file.skipIfExists) { |
| 134 | await mkdir(fileParentDir, { recursive: true }); |
| 135 | await writeFile(filePath, file.content ?? ""); |
| 136 | return filePath; |
| 137 | } |
| 138 | }) |
| 139 | ); |
| 140 | |
| 141 | await this.add(["."]); |
| 142 | |
| 143 | const status = await this.git.status(); |
| 144 | if (status.staged.length + status.renamed.length > 0) { |
| 145 | const { commit: commitSha } = await this.git.commit(message); |
| 146 | await this.push(); |
| 147 | return commitSha; |
| 148 | } else { |
| 149 | this.logger.warn(`Trying to commit empty changeset`, { status }); |
| 150 | } |
| 151 | return ""; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Clones the repository if not already cloned and sets the working directory to the repository directory. |
no test coverage detected