Skip to content

Commit

Permalink
feat: API updates (#451)
Browse files Browse the repository at this point in the history
* workflow updates

* translations api update

* list terms update

* list strings update

* fix

* branch api updates
  • Loading branch information
yevheniyJ authored Dec 7, 2024
1 parent 026eb3d commit 133ca9f
Showing 7 changed files with 189 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/glossaries/index.ts
Original file line number Diff line number Diff line change
@@ -197,6 +197,7 @@ export class Glossaries extends CrowdinApi {
url = this.addQueryParam(url, 'translationOfTermId', options.translationOfTermId);
url = this.addQueryParam(url, 'conceptId', options.conceptId);
url = this.addQueryParam(url, 'orderBy', options.orderBy);
url = this.addQueryParam(url, 'croql', options.croql);
return this.getList(url, options.limit, options.offset);
}

@@ -417,6 +418,7 @@ export namespace GlossariesModel {
languageId?: string;
conceptId?: number;
orderBy?: string;
croql?: string;
/**
* @deprecated
*/
69 changes: 69 additions & 0 deletions src/sourceFiles/index.ts
Original file line number Diff line number Diff line change
@@ -144,6 +144,51 @@ export class SourceFiles extends CrowdinApi {
return this.patch(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param branchId branch identifier
* @param request request body
* @see https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.post
*/
mergeBranch(
projectId: number,
branchId: number,
request: SourceFilesModel.MergeBranchRequest,
): Promise<ResponseObject<Status<SourceFilesModel.MergeBranchAttributes>>> {
const url = `${this.url}/projects/${projectId}/branches/${branchId}/merges`;
return this.post(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param branchId branch identifier
* @param mergeId merge branch identifier
* @see https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.get
*/
checkBranchMergeStatus(
projectId: number,
branchId: number,
mergeId: string,
): Promise<ResponseObject<Status<SourceFilesModel.MergeBranchAttributes>>> {
const url = `${this.url}/projects/${projectId}/branches/${branchId}/merges/${mergeId}`;
return this.get(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param branchId branch identifier
* @param mergeId merge branch identifier
* @see https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.summary.get
*/
getBranchMergeSummary(
projectId: number,
branchId: number,
mergeId: string,
): Promise<ResponseObject<SourceFilesModel.MergeBranchSummary>> {
const url = `${this.url}/projects/${projectId}/branches/${branchId}/merges/${mergeId}/summary`;
return this.get(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param options optional parameters for the request
@@ -540,6 +585,30 @@ export namespace SourceFilesModel {
title?: string;
}

export interface MergeBranchRequest {
deleteAfterMerge?: boolean;
sourceBranchId: number;
dryRun?: boolean;
}

export interface MergeBranchAttributes {
sourceBranchId: number;
deleteAfterMerge: boolean;
}

export interface MergeBranchSummary {
status: string;
sourceBranchId: number;
targetBranchId: number;
dryRun: boolean;
details: {
added: number;
deleted: number;
updated: number;
conflicted: number;
};
}

export type Priority = 'low' | 'normal' | 'high';

export interface ListProjectDirectoriesOptions extends PaginationOptions {
12 changes: 7 additions & 5 deletions src/sourceStrings/index.ts
Original file line number Diff line number Diff line change
@@ -114,6 +114,7 @@ export class SourceStrings extends CrowdinApi {
url = this.addQueryParam(url, 'branchId', options.branchId);
url = this.addQueryParam(url, 'directoryId', options.directoryId);
url = this.addQueryParam(url, 'orderBy', options.orderBy);
url = this.addQueryParam(url, 'taskId', options.taskId);
return this.getList(url, options.limit, options.offset);
}

@@ -230,15 +231,16 @@ export namespace SourceStringsModel {
}

export interface ListProjectStringsOptions extends PaginationOptions {
fileId?: number;
filter?: string;
orderBy?: string;
denormalizePlaceholders?: BooleanInt;
labelIds?: string;
scope?: SourceStringsModel.Scope;
croql?: string;
fileId?: number;
branchId?: number;
directoryId?: number;
orderBy?: number;
taskId?: number;
croql?: string;
filter?: string;
scope?: SourceStringsModel.Scope;
}

export interface String {
4 changes: 3 additions & 1 deletion src/translations/index.ts
Original file line number Diff line number Diff line change
@@ -374,14 +374,16 @@ export namespace TranslationsModel {
importEqSuggestions?: boolean;
autoApproveImported?: boolean;
translateHidden?: boolean;
addToTm?: boolean;
}

export interface UploadTranslationStringsRequest {
storageId: number;
branchId: number;
branchId?: number;
importEqSuggestions?: boolean;
autoApproveImported?: boolean;
translateHidden?: boolean;
addToTm?: boolean;
}

export interface UploadTranslationResponse {
26 changes: 26 additions & 0 deletions src/workflows/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CrowdinApi, isOptionalNumber, PaginationOptions, ResponseList, ResponseObject } from '../core';
import { SourceStringsModel } from '../sourceStrings';

/**
* Workflows are the sequences of steps that content in your project should go through (e.g. pre-translation, translation, proofreading).
@@ -50,6 +51,24 @@ export class Workflows extends CrowdinApi {
return this.get(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param stepId workflow step identifier
* @param options optional parameters for the request
* @see https://support.crowdin.com/developer/enterprise/api/v2/#tag/Workflows/operation/api.projects.workflow-steps.strings.getMany
*/
listStringsOnTheWorkflowStep(
projectId: number,
stepId: number,
options?: WorkflowModel.ListStringsOntheWorkflowStepOptions,
): Promise<ResponseList<SourceStringsModel.String>> {
let url = `${this.url}/projects/${projectId}/workflow-steps/${stepId}/strings`;
url = this.addQueryParam(url, 'languageIds', options?.languageIds);
url = this.addQueryParam(url, 'orderBy', options?.orderBy);
url = this.addQueryParam(url, 'status', options?.status);
return this.getList(url, options?.limit, options?.offset);
}

/**
* @param options optional parameters for the request
* @see https://support.crowdin.com/enterprise/api/#operation/api.workflow-templates.getMany
@@ -102,10 +121,17 @@ export namespace WorkflowModel {
assignees: { [language: string]: number[] };
};
}

export interface ListWorkflowTemplatesOptions extends PaginationOptions {
groupId?: number;
}

export interface ListStringsOntheWorkflowStepOptions extends PaginationOptions {
languageIds?: string;
orderBy?: string;
status?: 'todo' | 'done' | 'pending' | 'incomplete' | 'need_review';
}

export interface Workflow {
id: number;
title: string;
56 changes: 56 additions & 0 deletions tests/sourceFiles/api.test.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ describe('Source Files API', () => {
const fileRevisionId = 888;

const branchId = 12;
const sourceBranchId = 14;
const mergeBranchId = 'merge-123';
const mergeBranchStatus = 'merged';
const branchName = 'master';
const branchTitle = 'testTitle';
const storageId = 123;
@@ -160,6 +163,42 @@ describe('Source Files API', () => {
title: branchTitle,
},
})
.post(
`/projects/${projectId}/branches/${branchId}/merges`,
{
sourceBranchId,
},
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
identifier: mergeBranchId,
},
})
.get(`/projects/${projectId}/branches/${branchId}/merges/${mergeBranchId}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
identifier: mergeBranchId,
},
})
.get(`/projects/${projectId}/branches/${branchId}/merges/${mergeBranchId}/summary`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
status: mergeBranchStatus,
},
})
.get(`/projects/${projectId}/directories`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
@@ -506,6 +545,23 @@ describe('Source Files API', () => {
expect(branch.data.title).toBe(branchTitle);
});

it('Merge branch', async () => {
const mergeStatus = await api.mergeBranch(projectId, branchId, {
sourceBranchId,
});
expect(mergeStatus.data.identifier).toBe(mergeBranchId);
});

it('Check Branch Merge Status', async () => {
const mergeStatus = await api.checkBranchMergeStatus(projectId, branchId, mergeBranchId);
expect(mergeStatus.data.identifier).toBe(mergeBranchId);
});

it('Get Branch Merge Summary', async () => {
const mergeStatus = await api.getBranchMergeSummary(projectId, branchId, mergeBranchId);
expect(mergeStatus.data.status).toBe(mergeBranchStatus);
});

it('List project directories', async () => {
const directories = await api.listProjectDirectories(projectId);
expect(directories.data.length).toBe(1);
26 changes: 26 additions & 0 deletions tests/workflows/api.test.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ describe('Workflows API', () => {
const api: Workflows = new Workflows(credentials);
const id = 2;
const projectId = 4;
const stringId = 123;

const limit = 25;

@@ -43,6 +44,24 @@ describe('Workflows API', () => {
id: id,
},
})
.get(`/projects/${projectId}/workflow-steps/${id}/strings`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: [
{
data: {
id: stringId,
},
},
],
pagination: {
offset: 0,
limit: limit,
},
})
.get('/workflow-templates', undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
@@ -89,6 +108,13 @@ describe('Workflows API', () => {
expect(workflowStep.data.id).toBe(id);
});

it('List Strings on the Workflow Step', async () => {
const strings = await api.listStringsOnTheWorkflowStep(projectId, id);
expect(strings.data.length).toBe(1);
expect(strings.data[0].data.id).toBe(stringId);
expect(strings.pagination.limit).toBe(limit);
});

it('List Workflow Templates', async () => {
const workflows = await api.listWorkflowTemplates();
expect(workflows.data.length).toBe(1);

0 comments on commit 133ca9f

Please sign in to comment.