UBERF-7944: Support for not_planed close for issues (#6396)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-08-27 14:10:50 +07:00 committed by GitHub
parent e231f89e0b
commit d7820206c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 81 additions and 31 deletions

View File

@ -3,24 +3,17 @@
//
-->
<script lang="ts">
import { Ref, WithLookup, groupByArray } from '@hcengineering/core'
import {
GithubPullRequestReviewState,
GithubReview,
GithubReviewComment,
GithubReviewThread
} from '@hcengineering/github'
import { Ref, WithLookup } from '@hcengineering/core'
import { GithubPullRequestReviewState, GithubReview } from '@hcengineering/github'
import { ActivityMessageHeader, ActivityMessageTemplate } from '@hcengineering/activity-resources'
import { Person, PersonAccount } from '@hcengineering/contact'
import { personAccountByIdStore, personByIdStore } from '@hcengineering/contact-resources'
import { IntlString } from '@hcengineering/platform'
import { MessageViewer, createQuery } from '@hcengineering/presentation'
import { Component, PaletteColorIndexes, getPlatformColor, themeStore } from '@hcengineering/ui'
import diffview from '@hcengineering/diffview'
import github from '../../plugin'
import ReviewCommentPresenter from './ReviewCommentPresenter.svelte'
import { MessageViewer } from '@hcengineering/presentation'
import { isEmptyMarkup } from '@hcengineering/text'
import { PaletteColorIndexes, getPlatformColor, themeStore } from '@hcengineering/ui'
import github from '../../plugin'
export let value: WithLookup<GithubReview>
export let showNotify: boolean = false

View File

@ -68,7 +68,11 @@
)
}
async function changeResolution (): Promise<void> {
await getClient().update(value, { isResolved: !value.isResolved, resolvedBy: null })
if (value.isResolved) {
await getClient().update(value, { isResolved: false, resolvedBy: null })
} else {
await getClient().update(value, { isResolved: true, resolvedBy: getCurrentAccount()._id })
}
}
const toRefPersonAccount = (account: Ref<Account>): Ref<PersonAccount> => account as Ref<PersonAccount>

View File

@ -1057,14 +1057,15 @@ export abstract class IssueSyncManagerBase {
}
break
case task.statusCategory.Won:
if (issueExternal.state !== 'CLOSED') {
if (issueExternal.state !== 'CLOSED' || issueExternal.stateReason !== 'COMPLETED') {
issueUpdate.state = 'CLOSED'
issueUpdate.stateReason = 'COMPLETED'
}
break
case task.statusCategory.Lost:
if (issueExternal.state !== 'CLOSED') {
if (issueExternal.state !== 'CLOSED' || issueExternal.stateReason !== 'NOT_PLANNED') {
issueUpdate.state = 'CLOSED'
// issueUpdate.stateReason = 'not_planed'// Not supported change to github
issueUpdate.stateReason = 'not_planed' // Not supported change to github
}
break
}

View File

@ -21,9 +21,6 @@ import core, {
generateId,
makeCollaborativeDoc
} from '@hcengineering/core'
import task, { TaskType, calcRank } from '@hcengineering/task'
import tracker, { Issue, IssuePriority } from '@hcengineering/tracker'
import { Issue as GithubIssue, IssuesEvent, ProjectsV2ItemEvent } from '@octokit/webhooks-types'
import github, {
DocSyncInfo,
GithubIntegrationRepository,
@ -32,6 +29,9 @@ import github, {
IntegrationRepositoryData,
GithubIssue as TGithubIssue
} from '@hcengineering/github'
import task, { TaskType, calcRank } from '@hcengineering/task'
import tracker, { Issue, IssuePriority } from '@hcengineering/tracker'
import { Issue as GithubIssue, IssuesEvent, ProjectsV2ItemEvent } from '@octokit/webhooks-types'
import { Octokit } from 'octokit'
import config from '../config'
import {
@ -667,7 +667,7 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
okit: Octokit,
account: Ref<Account>
): Promise<boolean> {
const { state, body, ...issueUpdate } = await this.collectIssueUpdate(
const { state, stateReason, body, ...issueUpdate } = await this.collectIssueUpdate(
info,
existing,
platformUpdate,
@ -683,6 +683,41 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
const hasFieldStateChanges = Object.keys(issueUpdate).length > 0 || state !== undefined
// We should allow modification from user.
const closeIssue = async (): Promise<void> => {
await okit?.graphql(
`
mutation closeIssue($issue: ID!) {
closeIssue(input: {
issueId: $issue,
stateReason: ${stateReason === 'not_planed' ? 'NOT_PLANNED' : 'COMPLETED'}
}) {
issue {
id
updatedAt
}
}
}`,
{ issue: issueExternal.id }
)
}
const reopenIssue = async (): Promise<void> => {
await okit?.graphql(
`
mutation reopenIssue($issue: ID!) {
reopenIssue(input: {
issueId: $issue
}) {
issue {
id
updatedAt
}
}
}`,
{ issue: issueExternal.id }
)
}
if (hasFieldStateChanges || body !== undefined) {
if (body !== undefined && !isLocked) {
await this.ctx.withLog(
@ -696,12 +731,15 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
workspace: this.provider.getWorkspaceId().name
})
if (isGHWriteAllowed()) {
if (state === 'OPEN') {
// We need to call re-open issue
await reopenIssue()
}
await okit?.graphql(
`
mutation updateIssue($issue: ID!, $body: String! ) {
updateIssue(input: {
id: $issue,
${state !== undefined ? `state: ${state as string}` : ''}
${gqlp(issueUpdate)},
body: $body
}) {
@ -713,6 +751,9 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
}`,
{ issue: issueExternal.id, body }
)
if (state === 'CLOSED') {
await closeIssue()
}
}
},
{ url: issueExternal.url, id: existing._id }
@ -725,12 +766,17 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
async () => {
this.ctx.info('update fields', { ...issueUpdate, workspace: this.provider.getWorkspaceId().name })
if (isGHWriteAllowed()) {
await okit?.graphql(
`
const hasOtherChanges = Object.keys(issueUpdate).length > 0
if (state === 'OPEN') {
// We need to call re-open issue
await reopenIssue()
}
if (hasOtherChanges) {
await okit?.graphql(
`
mutation updateIssue($issue: ID!) {
updateIssue(input: {
id: $issue,
${state !== undefined ? `state: ${state as string}` : ''}
${gqlp(issueUpdate)}
}) {
issue {
@ -739,8 +785,12 @@ export class IssueSyncManager extends IssueSyncManagerBase implements DocSyncMan
}
}
}`,
{ issue: issueExternal.id }
)
{ issue: issueExternal.id }
)
}
if (state === 'CLOSED') {
await closeIssue()
}
}
},
{ url: issueExternal.url }

View File

@ -992,7 +992,7 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
okit: Octokit,
account: Ref<Account>
): Promise<boolean> {
let { state, body, ...issueUpdate } = await this.collectIssueUpdate(
let { state, stateReason, body, ...issueUpdate } = await this.collectIssueUpdate(
info,
existing,
platformUpdate,

View File

@ -204,7 +204,9 @@ export class ReviewThreadSyncManager implements DocSyncManager {
case 'resolved':
case 'unresolved': {
const isResolved = event.action === 'resolved'
const reviewData = await this.client.findOne(github.class.DocSyncInfo, { url: event.thread.node_id })
const reviewData = await this.client.findOne(github.class.DocSyncInfo, {
url: event.thread.node_id.toLocaleLowerCase()
})
if (reviewData !== undefined) {
const reviewObj: GithubReviewThread | undefined = await this.client.findOne<GithubReviewThread>(
@ -225,12 +227,12 @@ export class ReviewThreadSyncManager implements DocSyncManager {
},
lastModified
)
await this.client.update(
await this.client.diffUpdate(
reviewObj,
{
isResolved
isResolved,
resolvedBy: account
},
false,
lastModified,
account
)