Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

feat: added bitbucket issue integration #507

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fern/definition/ticket/comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ service:
request:
name: CreateCommentRequest
body: CreateOrUpdateCommentRequest
query-parameters:
fields: optional<string>
response: CreateOrUpdateCommentResponse
errors:
- errors.UnAuthorizedError
Expand All @@ -89,6 +91,8 @@ service:
request:
name: UpdateCommentRequest
body: CreateOrUpdateCommentRequest
query-parameters:
fields: optional<string>
response: CreateOrUpdateCommentResponse
errors:
- errors.UnAuthorizedError
Expand Down
4 changes: 4 additions & 0 deletions fern/definition/ticket/task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ service:
request:
name: CreateTaskRequest
body: CreateOrUpdateTaskRequest
query-parameters:
fields: optional<string>
response: CreateOrUpdateTaskResponse
errors:
- errors.UnAuthorizedError
Expand All @@ -88,6 +90,8 @@ service:
request:
name: UpdateTaskRequest
body: CreateOrUpdateTaskRequest
query-parameters:
fields: optional<string>
response: CreateOrUpdateTaskResponse
errors:
- errors.UnAuthorizedError
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const config = {
MS_DYNAMICS_SALES_CLIENT_ID: process.env.MS_DYNAMICS_SALES_CLIENT_ID!,
MS_DYNAMICS_SALES_CLIENT_SECRET: process.env.MS_DYNAMICS_SALES_CLIENT_SECRET!,
MS_DYNAMICS_SALES_ORG_URL: process.env.MS_DYNAMICS_SALES_ORG_URL!,
BITBUCKET_CLIENT_ID: process.env.BITBUCKET_CLIENT_ID!,
BITBUCKET_CLIENT_SECRET: process.env.BITBUCKET_CLIENT_SECRET!,
};

export default config;
4 changes: 3 additions & 1 deletion packages/backend/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Request, Response } from 'express';

export type CRM_TP_ID = 'zohocrm' | 'sfdc' | 'pipedrive' | 'hubspot' | 'closecrm' | 'ms_dynamics_365_sales';
export type CHAT_TP_ID = 'slack' | 'discord';
export type TICKET_TP_ID = 'linear' | 'clickup' | 'asana' | 'jira' | 'trello';
export type TICKET_TP_ID = 'linear' | 'clickup' | 'asana' | 'jira' | 'trello' | 'bitbucket';

export const DEFAULT_SCOPE = {
[TP_ID.hubspot]: [
Expand Down Expand Up @@ -48,6 +48,7 @@ export const DEFAULT_SCOPE = {
[TP_ID.trello]: ['read', 'write'],
[TP_ID.jira]: ['read:jira-work', 'read:jira-user', 'write:jira-work', 'offline_access'],
[TP_ID.ms_dynamics_365_sales]: ['offline_access', 'User.Read'],
[TP_ID.bitbucket]: ['issue', 'issue:write', 'repository', 'account'],
};

export const mapIntegrationIdToIntegrationName = {
Expand All @@ -64,6 +65,7 @@ export const mapIntegrationIdToIntegrationName = {
[TP_ID.trello]: 'Trello',
[TP_ID.jira]: 'Jira',
[TP_ID.ms_dynamics_365_sales]: 'Microsoft Dynamics 365 Sales',
[TP_ID.bitbucket]: 'Bitbucket',
};

export const rootSchemaMappingId = 'revertRootSchemaMapping';
Expand Down
24 changes: 24 additions & 0 deletions packages/backend/helpers/crm/transform/disunify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,29 @@ export async function disunifyTicketObject<T extends Record<string, any>>({

return processedObj;
}
case TP_ID.bitbucket: {
if (objType === 'ticketTask') {
let priorityId = undefined;
if (obj.priority === 'urgent') priorityId = 'blocker';
else if (obj.priority === 'high') priorityId = 'critical';
else if (obj.priority === 'medium') priorityId = 'major';
else if (obj.priority === 'low') priorityId = 'minor';
else if (obj.priority === 'lowest') priorityId = 'trivial';

return {
...transformedObj,
assignee:
obj.assignees && Array.isArray(obj.assignees) && obj.assignees.length > 0
? {
account_id: obj.assignees[0],
}
: undefined,
priority: priorityId ? priorityId : undefined,

kind: obj.issueTypeId ? obj.issueTypeId : undefined,
};
}
return processedObj;
}
}
}
38 changes: 38 additions & 0 deletions packages/backend/helpers/crm/transform/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,43 @@ export const preprocessUnifyObject = <T extends Record<string, any>>({
return { ...obj, assignee: obj.assignee ? [obj.assignee.accountId] : undefined };
},
},
[TP_ID.bitbucket]: {
[TicketStandardObjects.ticketTask]: (obj: T) => {
let priority: any;
let status: any;
if (obj.priority) {
if (obj.priority && obj.priority === 'blocker') priority = 'urgent';
else if (obj.priority && obj.priority === 'critical') priority = 'high';
else if (obj.priority && obj.priority === 'major') priority = 'medium';
else if (obj.priority && obj.priority === 'minor') priority = 'low';
else priority = 'trivial';
}

if (obj.state) {
if (String(obj.state).toLowerCase() === 'new' || String(obj.state).toLowerCase() === 'open')
status = 'open';
else if (
String(obj.state).toLowerCase() === 'wontfix' ||
String(obj.state).toLowerCase() === 'closed' ||
String(obj.state).toLowerCase() === 'invalid' ||
String(obj.state).toLowerCase() === 'onhold' ||
String(obj.state).toLowerCase() === 'duplicate' ||
String(obj.state).toLowerCase() === 'resolved'
)
status = 'closed';
else {
status = String(obj.state);
}
}

return {
...obj,
assignee: obj.assignee ? [obj.assignee.account_id] : undefined,
state: status,
priority,
};
},
},
};
const transformFn = (preprocessMap[tpId] || {})[objType];
return transformFn ? transformFn(obj) : obj;
Expand Down Expand Up @@ -389,6 +426,7 @@ export const postprocessDisUnifyTicketObject = <T extends Record<string, any>>({
[TP_ID.jira]: {},
[TP_ID.trello]: {},
[TP_ID.asana]: {},
[TP_ID.bitbucket]: {},
};
const transformFn = (preprocessMap[tpId] || {})[objType];
return transformFn ? transformFn(obj) : obj;
Expand Down
30 changes: 30 additions & 0 deletions packages/backend/prisma/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'id',
[TP_ID.jira]: 'id',
[TP_ID.trello]: 'id',
[TP_ID.bitbucket]: 'id',
},
target_field_name: 'id',
},
Expand All @@ -939,6 +940,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'id',
[TP_ID.jira]: 'id',
[TP_ID.trello]: 'id',
[TP_ID.bitbucket]: 'id',
},
target_field_name: 'remoteId',
},
Expand All @@ -948,6 +950,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'name',
[TP_ID.jira]: 'summary',
[TP_ID.trello]: 'name',
[TP_ID.bitbucket]: 'title',
},
target_field_name: 'name',
},
Expand All @@ -957,6 +960,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'assignees',
[TP_ID.jira]: 'assignee',
[TP_ID.trello]: 'idMembers',
[TP_ID.bitbucket]: 'assignee',
},
target_field_name: 'assignees',
},
Expand All @@ -966,6 +970,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'description',
[TP_ID.jira]: 'description',
[TP_ID.trello]: 'desc',
[TP_ID.bitbucket]: 'content.raw',
},
target_field_name: 'description',
},
Expand All @@ -975,6 +980,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'status',
[TP_ID.jira]: 'status.name',
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: 'state',
},
target_field_name: 'status',
},
Expand All @@ -984,6 +990,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'priority',
[TP_ID.jira]: 'priority.name',
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: 'priority',
},
target_field_name: 'priority',
},
Expand All @@ -993,6 +1000,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'creator.id',
[TP_ID.jira]: 'creator.accountId',
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: 'reporter.account_id',
},
target_field_name: 'creatorId',
},
Expand All @@ -1002,6 +1010,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'date_created',
[TP_ID.jira]: 'created',
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: 'created_on',
},
target_field_name: 'createdTimeStamp',
},
Expand All @@ -1011,6 +1020,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'date_updated',
[TP_ID.jira]: 'updated',
[TP_ID.trello]: 'dateLastActivity',
[TP_ID.bitbucket]: 'updated_on',
},
target_field_name: 'updatedTimeStamp',
},
Expand All @@ -1020,6 +1030,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'due_date',
[TP_ID.jira]: 'duedate',
[TP_ID.trello]: 'due',
[TP_ID.bitbucket]: undefined,
},
target_field_name: 'dueDate',
},
Expand All @@ -1029,6 +1040,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'date_done',
[TP_ID.jira]: undefined,
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: undefined,
},
target_field_name: 'completedDate',
},
Expand All @@ -1038,6 +1050,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'parent',
[TP_ID.jira]: 'parent.id',
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: undefined,
},
target_field_name: 'parentId',
},
Expand All @@ -1050,6 +1063,7 @@ export const ticketingFields = {
{
source_field_name: {
[TP_ID.jira]: 'issuetype.id',
[TP_ID.bitbucket]: 'kind',
},
target_field_name: 'issueTypeId',
},
Expand All @@ -1061,6 +1075,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'id',
[TP_ID.jira]: 'accountId',
[TP_ID.trello]: 'id',
[TP_ID.bitbucket]: 'account_id',
},
target_field_name: 'id',
},
Expand All @@ -1070,6 +1085,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'id',
[TP_ID.jira]: 'accountId',
[TP_ID.trello]: 'id',
[TP_ID.bitbucket]: 'account_id',
},
target_field_name: 'remoteId',
},
Expand All @@ -1079,6 +1095,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'email',
[TP_ID.jira]: 'emailAddress',
[TP_ID.trello]: 'email',
[TP_ID.bitbucket]: undefined,
},
target_field_name: 'email',
},
Expand All @@ -1088,6 +1105,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'username',
[TP_ID.jira]: 'displayName',
[TP_ID.trello]: 'fullName',
[TP_ID.bitbucket]: 'display_name',
},
target_field_name: 'name',
},
Expand All @@ -1097,6 +1115,7 @@ export const ticketingFields = {
[TP_ID.clickup]: undefined,
[TP_ID.jira]: 'active',
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: 'account_status',
},
target_field_name: 'isActive',
},
Expand All @@ -1106,6 +1125,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'profilePicture',
[TP_ID.jira]: 'avatarUrls."48x48"',
[TP_ID.trello]: 'avatarUrl',
[TP_ID.bitbucket]: 'links.avatar',
},
target_field_name: 'avatar',
},
Expand All @@ -1115,6 +1135,7 @@ export const ticketingFields = {
[TP_ID.clickup]: undefined,
[TP_ID.jira]: undefined,
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: 'created_on',
},
target_field_name: 'createdTimeStamp',
},
Expand All @@ -1124,6 +1145,7 @@ export const ticketingFields = {
[TP_ID.clickup]: undefined,
[TP_ID.jira]: undefined,
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: undefined,
},
target_field_name: 'updatedTimeStamp',
},
Expand All @@ -1133,6 +1155,7 @@ export const ticketingFields = {
[TP_ID.clickup]: undefined,
[TP_ID.jira]: undefined,
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: 'is_staff',
},
target_field_name: 'isAdmin',
},
Expand All @@ -1144,6 +1167,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'id',
[TP_ID.jira]: 'id',
[TP_ID.trello]: 'id',
[TP_ID.bitbucket]: 'id',
},
target_field_name: 'id',
},
Expand All @@ -1153,6 +1177,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'id',
[TP_ID.jira]: 'id',
[TP_ID.trello]: 'id',
[TP_ID.bitbucket]: 'id',
},
target_field_name: 'remoteId',
},
Expand All @@ -1162,6 +1187,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'comment_text',
[TP_ID.jira]: 'body',
[TP_ID.trello]: 'data.text',
[TP_ID.bitbucket]: 'content.raw',
},
target_field_name: 'body',
},
Expand All @@ -1171,6 +1197,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'user.id',
[TP_ID.jira]: 'author.accountId',
[TP_ID.trello]: 'idMemberCreator',
[TP_ID.bitbucket]: 'user.account_id',
},
target_field_name: 'createdBy',
},
Expand All @@ -1180,6 +1207,7 @@ export const ticketingFields = {
[TP_ID.clickup]: 'date',
[TP_ID.jira]: 'created',
[TP_ID.trello]: 'date',
[TP_ID.bitbucket]: 'created_on',
},
target_field_name: 'createdTimestamp',
},
Expand All @@ -1189,6 +1217,7 @@ export const ticketingFields = {
[TP_ID.clickup]: undefined,
[TP_ID.jira]: 'updated',
[TP_ID.trello]: 'data.dateLastEdited',
[TP_ID.bitbucket]: 'updated_on',
},
target_field_name: 'updatedTimeStamp',
},
Expand All @@ -1198,6 +1227,7 @@ export const ticketingFields = {
[TP_ID.clickup]: undefined,
[TP_ID.jira]: undefined,
[TP_ID.trello]: undefined,
[TP_ID.bitbucket]: undefined,
},
target_field_name: 'parentId',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "TP_ID" ADD VALUE 'bitbucket';
Loading
Loading