diff --git a/models/server-time/src/index.ts b/models/server-time/src/index.ts index 5803e518e7..6a17aaa7a5 100644 --- a/models/server-time/src/index.ts +++ b/models/server-time/src/index.ts @@ -61,7 +61,8 @@ export function createModel (builder: Builder): void { txMatch: { _class: core.class.TxCollectionCUD, 'tx._class': core.class.TxCreateDoc - } + }, + isAsync: true }) builder.createDoc(serverCore.class.Trigger, core.space.Model, { diff --git a/server-plugins/gmail-resources/src/index.ts b/server-plugins/gmail-resources/src/index.ts index 516e0c3d55..0c6384377c 100644 --- a/server-plugins/gmail-resources/src/index.ts +++ b/server-plugins/gmail-resources/src/index.ts @@ -109,7 +109,7 @@ export async function sendEmailNotification ( try { const sesURL = getMetadata(serverNotification.metadata.SesUrl) if (sesURL === undefined || sesURL === '') { - ctx.error('Please provide email service url to enable email confirmations.') + ctx.error('Please provide email service url to enable email notifications.') return } await fetch(concatLink(sesURL, '/send'), { diff --git a/server-plugins/time-resources/src/index.ts b/server-plugins/time-resources/src/index.ts index 0301f5bb3b..f34faa32a5 100644 --- a/server-plugins/time-resources/src/index.ts +++ b/server-plugins/time-resources/src/index.ts @@ -228,7 +228,7 @@ export async function OnToDoCreate (tx: TxCUD, control: TriggerControl): Pr messageHtml: jsonToMarkup(nodeDoc(nodeParagraph(nodeText(todo.title)))) } - return await getCommonNotificationTxes( + const txes = await getCommonNotificationTxes( control, object, data, @@ -240,6 +240,16 @@ export async function OnToDoCreate (tx: TxCUD, control: TriggerControl): Pr createTx.modifiedOn, notifyResult ) + + await control.apply(txes) + + const ids = txes.map((it) => it._id) + control.operationContext.derived.targets.notifications = (it) => { + if (ids.includes(it._id)) { + return [receiverInfo.account.email] + } + } + return [] } /** diff --git a/services/github/pod-github/src/sync/pullrequests.ts b/services/github/pod-github/src/sync/pullrequests.ts index c1c288005f..bf08144eeb 100644 --- a/services/github/pod-github/src/sync/pullrequests.ts +++ b/services/github/pod-github/src/sync/pullrequests.ts @@ -506,11 +506,16 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS container.container, pullRequestExternal.body ) + + const op = this.client.apply(generateId()) + let createdPullRequest: GithubPullRequest | undefined + await this.ctx.withLog( 'create pull request in platform', {}, async () => { - await this.createPullRequest( + createdPullRequest = await this.createPullRequest( + op, info, accountGH, { @@ -528,13 +533,17 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS { url: pullRequestExternal.url } ) - const pullRequestObj = await this.client.findOne(github.class.GithubPullRequest, { - _id: info._id as unknown as Ref - }) + const pullRequestObj = + createdPullRequest ?? + (await this.client.findOne(github.class.GithubPullRequest, { + _id: info._id as unknown as Ref + })) if (pullRequestObj !== undefined) { - await this.todoSync(pullRequestObj, pullRequestExternal, info, account) + await this.todoSync(op, pullRequestObj, pullRequestExternal, info, account) } + await op.commit() + return { needSync: '', external: pullRequestExternal, @@ -615,10 +624,11 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS async afterSync (existing: Issue, account: Ref, issueExternal: any, info: DocSyncInfo): Promise { const pullRequest = existing as GithubPullRequest - await this.todoSync(pullRequest, issueExternal as PullRequestExternalData, info, account) + await this.todoSync(this.client, pullRequest, issueExternal as PullRequestExternalData, info, account) } async todoSync ( + client: TxOperations, pullRequest: Pick< GithubPullRequest, '_id' | 'identifier' | 'reviewers' | 'title' | 'state' | 'space' | '_class' | 'modifiedBy' @@ -628,11 +638,11 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS account: Ref ): Promise { // Find all todo's related to PR. - const allTodos = await this.client.findAll(github.mixin.GithubTodo, { attachedTo: pullRequest._id }) + const allTodos = await client.findAll(github.mixin.GithubTodo, { attachedTo: pullRequest._id }) // We also need to track deleted Todos, const removedTodos: GithubTodo[] = [] - const removedTodoOps = await this.client.findAll>( + const removedTodoOps = await client.findAll>( core.class.TxCollectionCUD, { objectId: pullRequest._id, @@ -644,7 +654,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS const todoIds = removedTodoOps.filter((it) => it.tx._class === core.class.TxCreateDoc).map((it) => it.tx.objectId) - const mixinOps = await this.client.findAll>( + const mixinOps = await client.findAll>( core.class.TxMixin, { objectId: { $in: todoIds } @@ -721,7 +731,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS (!hasPending && pendingOrDismissed.get(r) !== undefined) ) { if (todos.length === 0) { - await this.requestReview(pullRequest, external, r, account) + await this.requestReview(client, pullRequest, external, r, account) } } } @@ -754,7 +764,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS if (todos.length === 0) { requestedIds.push(c) // We do not have todos's create one to solve issue. - await this.requestFix(pullRequest, external, c, account) + await this.requestFix(client, pullRequest, external, c, account) } } break @@ -772,7 +782,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS if (todos.length === 0 && !requestedIds.includes(c)) { requestedIds.push(c) // We do not have todos's create one to solve issue. - await this.requestFix(pullRequest, external, c, account) + await this.requestFix(client, pullRequest, external, c, account) } } } @@ -798,12 +808,13 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS } private async requestReview ( + client: TxOperations, pullRequest: Pick, external: PullRequestExternalData, todoUser: Ref, account: Ref ): Promise { - const latestTodo = await this.client.findOne( + const latestTodo = await client.findOne( time.class.ToDo, { user: todoUser, @@ -813,7 +824,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS sort: { rank: SortingOrder.Ascending } } ) - const todoId = await this.client.addCollection( + const todoId = await client.addCollection( time.class.ProjectToDo, time.space.ToDos, pullRequest._id, @@ -833,7 +844,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS undefined, account ) - await this.client.createMixin( + await client.createMixin( todoId, time.class.ToDo, time.space.ToDos, @@ -847,6 +858,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS } private async requestFix ( + client: TxOperations, pullRequest: Pick< GithubPullRequest, '_id' | 'identifier' | 'reviewers' | 'title' | 'space' | 'state' | 'space' | '_class' @@ -855,7 +867,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS todoUser: Ref, account: Ref ): Promise { - const latestTodo = await this.client.findOne( + const latestTodo = await client.findOne( time.class.ToDo, { user: todoUser, @@ -866,7 +878,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS } ) - const todoId = await this.client.addCollection( + const todoId = await client.addCollection( time.class.ProjectToDo, time.space.ToDos, pullRequest._id, @@ -886,7 +898,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS undefined, account ) - await this.client.createMixin( + await client.createMixin( todoId, time.class.ToDo, time.space.ToDos, @@ -1124,6 +1136,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS } private async createPullRequest ( + client: TxOperations, info: DocSyncInfo, account: Ref, pullRequestData: GithubPullRequestData & { status: Issue['status'] }, @@ -1133,8 +1146,8 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS taskType: Ref, repository: GithubIntegrationRepository, isDescriptionLocked: boolean - ): Promise { - const lastOne = await this.client.findOne( + ): Promise { + const lastOne = await client.findOne( tracker.class.Issue, { space: prj._id }, { sort: { rank: SortingOrder.Descending }, limit: 1 } @@ -1176,7 +1189,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS } const prId = info._id as unknown as Ref - await this.client.addCollection( + await client.addCollection( github.class.GithubPullRequest, info.space, tracker.ids.NoParent, @@ -1187,7 +1200,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS new Date(pullRequestExternal.createdAt).getTime(), account ) - await this.client.createMixin( + await client.createMixin( prId, github.class.GithubPullRequest, info.space, @@ -1199,7 +1212,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS descriptionLocked: isDescriptionLocked } ) - await this.client.createMixin(prId, github.mixin.GithubIssue, prj._id, prj.mixinClass, {}) + await client.createMixin(prId, github.mixin.GithubIssue, prj._id, prj.mixinClass, {}) await this.addConnectToMessage( github.string.PullRequestConnectedActivityInfo, @@ -1209,6 +1222,20 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS pullRequestExternal, repository ) + + return { + ...value, + _id: prId, + _class: github.class.GithubPullRequest, + space: info.space as any, + attachedTo: tracker.ids.NoParent, + attachedToClass: tracker.class.Issue, + collection: 'subIssues', + modifiedOn: new Date(pullRequestExternal.createdAt).getTime(), + modifiedBy: account, + createdOn: new Date(pullRequestExternal.createdAt).getTime(), + createdBy: account + } } async externalSync (