Skip to content

Commit

Permalink
branch support
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-bodnar committed Jul 21, 2023
1 parent 8b67da6 commit f88f8fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
16 changes: 13 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions src/translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,42 @@ export class Translator {
this.logger.log('info', 'Uploading sources...');

const readmeFile = await this.getFile();

const storageFile = await this.crowdin.uploadStorageApi.addStorage(
this.config.file,
fs.readFileSync(this.config.file)
);

let branchId = undefined;

if (this.config.branch) {
let branch = await this.getBranch();

if (!branch) {
branch = (
await this.crowdin.sourceFilesApi.createBranch(this.credentials.projectId, {
name: this.config.branch
})
).data;
}

branchId = branch.id;
}

if (readmeFile) {
await this.crowdin.sourceFilesApi.updateOrRestoreFile(this.credentials.projectId, readmeFile.id, {
storageId: storageFile.data.id
});

this.logger.log('info', 'Source file successfully updated');
} else {
await this.crowdin.sourceFilesApi.createFile(this.credentials.projectId, {
storageId: storageFile.data.id,
name: this.config.file,
branchId: (await this.getBranch())?.id
branchId: branchId
});
}

this.logger.log('info', 'Sources uploaded!');
this.logger.log('info', 'Source file successfully created');
}
}

private async downloadTranslations(): Promise<string> {
Expand Down

0 comments on commit f88f8fa

Please sign in to comment.