mirror of https://github.com/harness/drone.git
Check if PR source branch exists to build path to files properly (#2042)
parent
9480cf414c
commit
7351d63ccc
|
@ -51,6 +51,7 @@ import { useShowRequestError } from 'hooks/useShowRequestError'
|
|||
import { getErrorMessage, isInViewport } from 'utils/Utils'
|
||||
import { createRequestIdleCallbackTaskPool } from 'utils/Task'
|
||||
import { useResizeObserver } from 'hooks/useResizeObserver'
|
||||
import { useFindGitBranch } from 'hooks/useFindGitBranch'
|
||||
import Config from 'Config'
|
||||
import {
|
||||
DIFF2HTML_CONFIG,
|
||||
|
@ -313,6 +314,8 @@ const DiffViewerInternal: React.FC<DiffViewerProps> = ({
|
|||
lazy: !useFullDiff || !!memorizedState.get(diff.filePath)?.fullDiff
|
||||
})
|
||||
|
||||
const branchInfo = useFindGitBranch(pullReqMetadata?.source_branch)
|
||||
|
||||
useShowRequestError(fullDiffError, 0)
|
||||
|
||||
useEffect(
|
||||
|
@ -420,7 +423,11 @@ const DiffViewerInternal: React.FC<DiffViewerProps> = ({
|
|||
<Link
|
||||
to={routes.toCODERepository({
|
||||
repoPath: repoMetadata.path as string,
|
||||
gitRef: pullReqMetadata?.source_branch || commitSHA || '',
|
||||
gitRef: pullReqMetadata?.source_branch
|
||||
? branchInfo
|
||||
? pullReqMetadata?.source_branch
|
||||
: pullReqMetadata?.source_sha
|
||||
: commitSHA || '',
|
||||
resourcePath: diff.isRename ? diff.newName : diff.filePath
|
||||
})}>
|
||||
{diff.isRename ? `${diff.oldName} -> ${diff.newName}` : diff.filePath}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2023 Harness, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useGet } from 'restful-react'
|
||||
import { useAtomValue } from 'jotai'
|
||||
import type { RepoBranch } from 'services/code'
|
||||
import { LIST_FETCHING_LIMIT } from 'utils/Utils'
|
||||
import { repoMetadataAtom } from 'atoms/repoMetadata'
|
||||
|
||||
export function useFindGitBranch(branchName?: string, includeCommit = false) {
|
||||
const repoMetadata = useAtomValue(repoMetadataAtom)
|
||||
const { data } = useGet<RepoBranch[]>({
|
||||
path: `/api/v1/repos/${repoMetadata?.path}/+/branches`,
|
||||
queryParams: {
|
||||
limit: LIST_FETCHING_LIMIT,
|
||||
include_commit: includeCommit,
|
||||
query: branchName
|
||||
},
|
||||
lazy: !repoMetadata || !branchName
|
||||
})
|
||||
|
||||
return data?.find(branch => branch.name === branchName)
|
||||
}
|
Loading…
Reference in New Issue