feat: [CODE-2382] update review events with the latest changes (#2717)

* fix: [CODE-2382] updated interface
* feat: [CODE-2382] update review events with the latest changes
This commit is contained in:
Ritik Kapoor 2024-09-23 17:01:11 +00:00 committed by Harness
parent 8dac8c2797
commit 1725841f67
6 changed files with 135 additions and 3 deletions

View File

@ -36,7 +36,9 @@ export enum CommentType {
BRANCH_DELETE = 'branch-delete',
BRANCH_RESTORE = 'branch-restore',
STATE_CHANGE = 'state-change',
LABEL_MODIFY = 'label-modify'
LABEL_MODIFY = 'label-modify',
REVIEWER_ADD = 'reviewer-add',
REVIEWER_DELETE = 'reviewer-delete'
}
export enum LabelActivity {
@ -45,6 +47,12 @@ export enum LabelActivity {
RE_ASSIGN = 'reassign'
}
export enum ReviewerAddActivity {
REQUESTED = 'requested',
ASSIGNED = 'assigned',
SELF_ASSIGNED = 'self_assigned'
}
/**
* @deprecated
*/

View File

@ -851,6 +851,11 @@ export interface StringsMap {
prGenSummary: string
prHasNoConflicts: string
prMustSelectSourceAndTargetBranches: string
'prReview.assigned': string
'prReview.removed': string
'prReview.requested': string
'prReview.selfAssigned': string
'prReview.selfRemoved': string
prSourceAndTargetMustBeDifferent: string
'prState.draftDesc': string
'prState.draftHeading': string

View File

@ -367,6 +367,12 @@ prChecks:
killed: '{count}/{total} {count|1:check,checks} killed.'
notFound: No pipelines or external checks found for this repository.
viewExternal: View Details
prReview:
assigned: '{author} assigned {reviewer} as a reviewer'
requested: '{author} requested a review from {reviewer}'
selfAssigned: '{reviewer} self-requested a review'
removed: '{author} removed the request for review from {reviewer}'
selfRemoved: '{author} removed their request for review'
webhookListingContent: 'create,delete,deployment ...'
general: 'General'
webhooks: 'Webhooks'

View File

@ -19,13 +19,13 @@ import { Avatar, Container, Layout, StringSubstitute, Text } from '@harnessio/ui
import { Icon, IconName } from '@harnessio/icons'
import { Color, FontVariation } from '@harnessio/design-system'
import { defaultTo } from 'lodash-es'
import { Case, Match } from 'react-jsx-match'
import { Case, Falsy, Match, Truthy } from 'react-jsx-match'
import { CodeIcon, GitInfoProps, MergeStrategy } from 'utils/GitUtils'
import { useStrings } from 'framework/strings'
import type { TypesPullReqActivity } from 'services/code'
import type { CommentItem } from 'components/CommentBox/CommentBox'
import { PullRequestSection } from 'utils/Utils'
import { CommentType, LabelActivity } from 'components/DiffViewer/DiffViewerUtils'
import { CommentType, LabelActivity, ReviewerAddActivity } from 'components/DiffViewer/DiffViewerUtils'
import { useAppContext } from 'AppContext'
import { CommitActions } from 'components/CommitActions/CommitActions'
import { PipeSeparator } from 'components/PipeSeparator/PipeSeparator'
@ -44,6 +44,10 @@ interface MergePayload {
merge_method: string
rules_bypassed: boolean
}
interface ReviewerAddActivityPayload {
reviewer_type: ReviewerAddActivity
}
//ToDo : update all comment options with the correct payload type and remove Unknown
export const SystemComment: React.FC<SystemCommentProps> = ({ pullReqMetadata, commentItems, repoMetadataPath }) => {
const { getString } = useStrings()
@ -424,6 +428,99 @@ export const SystemComment: React.FC<SystemCommentProps> = ({ pullReqMetadata, c
)
}
case CommentType.REVIEWER_ADD: {
const mentionId = payload?.metadata?.mentions?.ids?.[0] ?? 0
const mentionDisplayName = payload?.mentions?.[mentionId]?.display_name ?? ''
return (
<Container className={css.mergedBox}>
<Layout.Horizontal spacing="small" style={{ alignItems: 'center' }}>
<Avatar name={payload?.author?.display_name} size="small" hoverCard={false} />
<Text tag="div">
<Match expr={(payload?.payload as ReviewerAddActivityPayload).reviewer_type}>
<Case val={ReviewerAddActivity.ASSIGNED}>
<StringSubstitute
str={getString('prReview.assigned')}
vars={{
author: <strong>{payload?.author?.display_name}</strong>,
reviewer: <strong>{mentionDisplayName}</strong>
}}
/>
</Case>
<Case val={ReviewerAddActivity.REQUESTED}>
<StringSubstitute
str={getString('prReview.requested')}
vars={{
author: <strong>{payload?.author?.display_name}</strong>,
reviewer: <strong>{mentionDisplayName}</strong>
}}
/>
</Case>
<Case val={ReviewerAddActivity.SELF_ASSIGNED}>
<StringSubstitute
str={getString('prReview.selfAssigned')}
vars={{
reviewer: <strong>{mentionDisplayName}</strong>
}}
/>
</Case>
</Match>
</Text>
<PipeSeparator height={9} />
<TimePopoverWithLocal
time={defaultTo(payload?.created as number, 0)}
inline={true}
width={100}
font={{ variation: FontVariation.SMALL }}
color={Color.GREY_400}
/>
</Layout.Horizontal>
</Container>
)
}
case CommentType.REVIEWER_DELETE: {
const mentionId = payload?.metadata?.mentions?.ids?.[0] ?? 0
const mentionDisplayName = payload?.mentions?.[mentionId]?.display_name ?? ''
return (
<Container className={css.mergedBox}>
<Layout.Horizontal spacing="small" style={{ alignItems: 'center' }}>
<Avatar name={payload?.author?.display_name} size="small" hoverCard={false} />
<Text tag="div">
<Match expr={payload?.author?.id === mentionId}>
<Truthy>
<StringSubstitute
str={getString('prReview.selfRemoved')}
vars={{
author: <strong>{payload?.author?.display_name}</strong>
}}
/>
</Truthy>
<Falsy>
<StringSubstitute
str={getString('prReview.removed')}
vars={{
author: <strong>{payload?.author?.display_name}</strong>,
reviewer: <strong>{mentionDisplayName}</strong>
}}
/>
</Falsy>
</Match>
</Text>
<PipeSeparator height={9} />
<TimePopoverWithLocal
time={defaultTo(payload?.created as number, 0)}
inline={true}
width={100}
font={{ variation: FontVariation.SMALL }}
color={Color.GREY_400}
/>
</Layout.Horizontal>
</Container>
)
}
default: {
// eslint-disable-next-line no-console
console.warn('Unable to render system type activity', commentItems)

View File

@ -135,6 +135,7 @@ export type EnumPullReqActivityType =
| 'label-modify'
| 'merge'
| 'review-submit'
| 'reviewer-add'
| 'reviewer-delete'
| 'state-change'
| 'title-change'
@ -4996,6 +4997,7 @@ export interface ListPullReqActivitiesQueryParams {
| 'label-modify'
| 'merge'
| 'review-submit'
| 'reviewer-add'
| 'reviewer-delete'
| 'state-change'
| 'title-change'

View File

@ -4644,6 +4644,7 @@ paths:
- label-modify
- merge
- review-submit
- reviewer-add
- reviewer-delete
- state-change
- title-change
@ -4772,6 +4773,12 @@ paths:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Not Found
'409':
content:
application/json:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Conflict
'422':
content:
application/json:
@ -4834,6 +4841,12 @@ paths:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Forbidden
'409':
content:
application/json:
schema:
$ref: '#/components/schemas/UsererrorError'
description: Conflict
'422':
content:
application/json:
@ -10562,6 +10575,7 @@ components:
- label-modify
- merge
- review-submit
- reviewer-add
- reviewer-delete
- state-change
- title-change