mirror of
https://github.com/harness/drone.git
synced 2025-05-21 19:39:59 +08:00
fix: [code-1519]: fix issue on approval btn (#1074)
This commit is contained in:
parent
0f888bf20f
commit
7cd975c370
@ -23,6 +23,7 @@ import { Menu, PopoverPosition } from '@blueprintjs/core'
|
|||||||
import cx from 'classnames'
|
import cx from 'classnames'
|
||||||
import { Render } from 'react-jsx-match'
|
import { Render } from 'react-jsx-match'
|
||||||
import { isEmpty } from 'lodash-es'
|
import { isEmpty } from 'lodash-es'
|
||||||
|
import { useAppContext } from 'AppContext'
|
||||||
import { useStrings } from 'framework/strings'
|
import { useStrings } from 'framework/strings'
|
||||||
import type { EnumPullReqReviewDecision, TypesPullReq } from 'services/code'
|
import type { EnumPullReqReviewDecision, TypesPullReq } from 'services/code'
|
||||||
import type { GitInfoProps } from 'utils/GitUtils'
|
import type { GitInfoProps } from 'utils/GitUtils'
|
||||||
@ -55,6 +56,7 @@ const ReviewSplitButton = (props: ReviewSplitButtonProps) => {
|
|||||||
const { refetchReviewers, pullRequestMetadata, repoMetadata, shouldHide, refreshPr, disabled } = props
|
const { refetchReviewers, pullRequestMetadata, repoMetadata, shouldHide, refreshPr, disabled } = props
|
||||||
const { getString } = useStrings()
|
const { getString } = useStrings()
|
||||||
const { showError, showSuccess } = useToaster()
|
const { showError, showSuccess } = useToaster()
|
||||||
|
const { currentUser } = useAppContext()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: reviewers,
|
data: reviewers,
|
||||||
@ -65,33 +67,33 @@ const ReviewSplitButton = (props: ReviewSplitButtonProps) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const determineOverallDecision = (data: any[] | null) => {
|
const determineOverallDecision = (data: any[] | null) => {
|
||||||
let hasChangeReq = false
|
|
||||||
let allApproved = true
|
|
||||||
if (data === null || isEmpty(data)) {
|
if (data === null || isEmpty(data)) {
|
||||||
return ApproveState.APPROVE // Default case
|
return ApproveState.APPROVE // Default case
|
||||||
}
|
}
|
||||||
for (const item of data) {
|
// Check if the current user is among the reviewers
|
||||||
if (item.review_decision === ApproveState.CHANGEREQ) {
|
const currentUserReviews = data.filter(val => val.reviewer.uid === currentUser.uid)
|
||||||
hasChangeReq = true
|
|
||||||
break
|
if (currentUserReviews.length === 0) {
|
||||||
} else if (item.review_decision !== ApproveState.APPROVED) {
|
// Current user not found among reviewers, return default approval state
|
||||||
allApproved = false
|
return ApproveState.APPROVE
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasChangeReq) {
|
// Directly return based on the review decision of the current user
|
||||||
|
const decision = currentUserReviews[0].review_decision
|
||||||
|
if (decision === ApproveState.CHANGEREQ) {
|
||||||
return ApproveState.CHANGEREQ
|
return ApproveState.CHANGEREQ
|
||||||
} else if (allApproved) {
|
} else if (decision === ApproveState.APPROVED) {
|
||||||
return ApproveState.APPROVED
|
return ApproveState.APPROVED
|
||||||
} else {
|
} else {
|
||||||
return ApproveState.APPROVE // Default case
|
return ApproveState.APPROVE // Default case or any other state not explicitly handled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const [commitSha, setCommitSha] = useState('')
|
const [commitSha, setCommitSha] = useState('')
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (reviewers) {
|
if (reviewers) {
|
||||||
if (reviewers[0] && reviewers[0].sha) {
|
const currentUserData = reviewers.filter(val => val.reviewer.uid === currentUser.uid)
|
||||||
setCommitSha(reviewers[0].sha)
|
if (currentUserData[0] && currentUserData[0].sha) {
|
||||||
|
setCommitSha(currentUserData[0].sha)
|
||||||
}
|
}
|
||||||
setApproveState(determineOverallDecision(reviewers))
|
setApproveState(determineOverallDecision(reviewers))
|
||||||
}
|
}
|
||||||
@ -141,7 +143,6 @@ const ReviewSplitButton = (props: ReviewSplitButtonProps) => {
|
|||||||
|
|
||||||
const getApprovalState = (state: string) => {
|
const getApprovalState = (state: string) => {
|
||||||
const checkOutdated = processReviewDecision(approveState, commitSha, pullRequestMetadata?.source_sha)
|
const checkOutdated = processReviewDecision(approveState, commitSha, pullRequestMetadata?.source_sha)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(state === ApproveState.APPROVED && checkOutdated === ApproveState.OUTDATED) ||
|
(state === ApproveState.APPROVED && checkOutdated === ApproveState.OUTDATED) ||
|
||||||
(state === ApproveState.CHANGEREQ && checkOutdated === ApproveState.OUTDATED)
|
(state === ApproveState.CHANGEREQ && checkOutdated === ApproveState.OUTDATED)
|
||||||
@ -177,7 +178,6 @@ const ReviewSplitButton = (props: ReviewSplitButtonProps) => {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
className={cx(css.reviewButton, {
|
className={cx(css.reviewButton, {
|
||||||
|
Loading…
Reference in New Issue
Block a user