mirror of
https://github.com/harness/drone.git
synced 2025-05-21 19:39:59 +08:00
fix: [code-682]: fix bug in pr creation (#330)
This commit is contained in:
parent
5713a26c7c
commit
bfea74dbe5
@ -1,5 +1,5 @@
|
|||||||
import { noop } from 'lodash-es'
|
import { noop } from 'lodash-es'
|
||||||
import React, { useCallback, useState } from 'react'
|
import React, { useCallback, useState, useEffect } from 'react'
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
PageBody,
|
PageBody,
|
||||||
@ -20,14 +20,21 @@ import { useAppContext } from 'AppContext'
|
|||||||
import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata'
|
import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata'
|
||||||
import { useStrings } from 'framework/strings'
|
import { useStrings } from 'framework/strings'
|
||||||
import { RepositoryPageHeader } from 'components/RepositoryPageHeader/RepositoryPageHeader'
|
import { RepositoryPageHeader } from 'components/RepositoryPageHeader/RepositoryPageHeader'
|
||||||
import { getErrorMessage, showToaster } from 'utils/Utils'
|
import { LIST_FETCHING_LIMIT, getErrorMessage, showToaster } from 'utils/Utils'
|
||||||
import { Images } from 'images'
|
import { Images } from 'images'
|
||||||
import { CodeIcon, isRefATag, makeDiffRefs } from 'utils/GitUtils'
|
import { CodeIcon, isRefATag, makeDiffRefs } from 'utils/GitUtils'
|
||||||
import { Changes } from 'components/Changes/Changes'
|
import { Changes } from 'components/Changes/Changes'
|
||||||
import type { OpenapiCreatePullReqRequest, TypesDiffStats, TypesPullReq, TypesRepository } from 'services/code'
|
import type {
|
||||||
|
OpenapiCreatePullReqRequest,
|
||||||
|
TypesCommit,
|
||||||
|
TypesDiffStats,
|
||||||
|
TypesPullReq,
|
||||||
|
TypesRepository
|
||||||
|
} from 'services/code'
|
||||||
import { LoadingSpinner } from 'components/LoadingSpinner/LoadingSpinner'
|
import { LoadingSpinner } from 'components/LoadingSpinner/LoadingSpinner'
|
||||||
import { TabTitleWithCount, tabContainerCSS } from 'components/TabTitleWithCount/TabTitleWithCount'
|
import { TabTitleWithCount, tabContainerCSS } from 'components/TabTitleWithCount/TabTitleWithCount'
|
||||||
import { MarkdownEditorWithPreview } from 'components/MarkdownEditorWithPreview/MarkdownEditorWithPreview'
|
import { MarkdownEditorWithPreview } from 'components/MarkdownEditorWithPreview/MarkdownEditorWithPreview'
|
||||||
|
import { usePageIndex } from 'hooks/usePageIndex'
|
||||||
import { TabContentWrapper } from 'components/TabContentWrapper/TabContentWrapper'
|
import { TabContentWrapper } from 'components/TabContentWrapper/TabContentWrapper'
|
||||||
import { CompareContentHeader, PRCreationType } from './CompareContentHeader/CompareContentHeader'
|
import { CompareContentHeader, PRCreationType } from './CompareContentHeader/CompareContentHeader'
|
||||||
import { CompareCommits } from './CompareCommits'
|
import { CompareCommits } from './CompareCommits'
|
||||||
@ -43,17 +50,28 @@ export default function Compare() {
|
|||||||
const [title, setTitle] = useState('')
|
const [title, setTitle] = useState('')
|
||||||
const [description, setDescription] = useState('')
|
const [description, setDescription] = useState('')
|
||||||
const { showError } = useToaster()
|
const { showError } = useToaster()
|
||||||
const {
|
const [page, setPage] = usePageIndex()
|
||||||
data,
|
|
||||||
error: errorStats
|
const { data, error: errorStats } = useGet<TypesDiffStats>({
|
||||||
} = useGet<TypesDiffStats>({
|
|
||||||
path: `/api/v1/repos/${repoMetadata?.path}/+/diff-stats/${targetGitRef}...${sourceGitRef}`,
|
path: `/api/v1/repos/${repoMetadata?.path}/+/diff-stats/${targetGitRef}...${sourceGitRef}`,
|
||||||
lazy: !repoMetadata
|
lazy: !repoMetadata || sourceGitRef === ''
|
||||||
})
|
})
|
||||||
const { mutate: createPullRequest, loading: creatingInProgress } = useMutate<TypesPullReq>({
|
const { mutate: createPullRequest, loading: creatingInProgress } = useMutate<TypesPullReq>({
|
||||||
verb: 'POST',
|
verb: 'POST',
|
||||||
path: `/api/v1/repos/${repoMetadata?.path}/+/pullreq`
|
path: `/api/v1/repos/${repoMetadata?.path}/+/pullreq`
|
||||||
})
|
})
|
||||||
|
const { data: commits } = useGet<{
|
||||||
|
commits: TypesCommit[]
|
||||||
|
}>({
|
||||||
|
path: `/api/v1/repos/${repoMetadata?.path}/+/commits`,
|
||||||
|
queryParams: {
|
||||||
|
LIST_FETCHING_LIMIT,
|
||||||
|
page,
|
||||||
|
git_ref: sourceGitRef,
|
||||||
|
after: targetGitRef
|
||||||
|
},
|
||||||
|
lazy: !repoMetadata || sourceGitRef === ''
|
||||||
|
})
|
||||||
const onCreatePullRequest = useCallback(
|
const onCreatePullRequest = useCallback(
|
||||||
(creationType: PRCreationType) => {
|
(creationType: PRCreationType) => {
|
||||||
if (!sourceGitRef || !targetGitRef) {
|
if (!sourceGitRef || !targetGitRef) {
|
||||||
@ -130,6 +148,11 @@ export default function Compare() {
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (commits?.commits?.length) {
|
||||||
|
setTitle(commits.commits[0].title as string)
|
||||||
|
}
|
||||||
|
}, [commits?.commits])
|
||||||
return (
|
return (
|
||||||
<Container className={css.main}>
|
<Container className={css.main}>
|
||||||
<RepositoryPageHeader
|
<RepositoryPageHeader
|
||||||
@ -180,6 +203,7 @@ export default function Compare() {
|
|||||||
id="prComparing"
|
id="prComparing"
|
||||||
defaultSelectedTabId="general"
|
defaultSelectedTabId="general"
|
||||||
large={false}
|
large={false}
|
||||||
|
onChange={() => setPage(1)}
|
||||||
tabList={[
|
tabList={[
|
||||||
{
|
{
|
||||||
id: 'general',
|
id: 'general',
|
||||||
@ -232,13 +256,14 @@ export default function Compare() {
|
|||||||
padding={{ left: 'medium' }}
|
padding={{ left: 'medium' }}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
panel:
|
panel: (
|
||||||
<CompareCommits
|
<CompareCommits
|
||||||
repoMetadata={repoMetadata as TypesRepository}
|
repoMetadata={repoMetadata as TypesRepository}
|
||||||
sourceSha={sourceGitRef}
|
sourceSha={sourceGitRef}
|
||||||
targetSha={targetGitRef}
|
targetSha={targetGitRef}
|
||||||
handleRefresh={()=>{}} // TODO: when to refresh
|
handleRefresh={() => {}} // TODO: when to refresh
|
||||||
/>
|
/>
|
||||||
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'diff',
|
id: 'diff',
|
||||||
@ -250,18 +275,23 @@ export default function Compare() {
|
|||||||
padding={{ left: 'medium' }}
|
padding={{ left: 'medium' }}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
panel:
|
panel: (
|
||||||
<TabContentWrapper loading={loading} error={error} onRetry={()=>{}} className={css.changesContainer}>
|
<TabContentWrapper
|
||||||
<Changes
|
loading={loading}
|
||||||
readOnly
|
error={error}
|
||||||
repoMetadata={repoMetadata}
|
onRetry={() => {}}
|
||||||
targetRef={targetGitRef}
|
className={css.changesContainer}>
|
||||||
sourceRef={sourceGitRef}
|
<Changes
|
||||||
emptyTitle={getString('noChanges')}
|
readOnly
|
||||||
emptyMessage={getString('noChangesCompare')}
|
repoMetadata={repoMetadata}
|
||||||
onCommentUpdate={noop}
|
targetRef={targetGitRef}
|
||||||
/>
|
sourceRef={sourceGitRef}
|
||||||
</TabContentWrapper>
|
emptyTitle={getString('noChanges')}
|
||||||
|
emptyMessage={getString('noChangesCompare')}
|
||||||
|
onCommentUpdate={noop}
|
||||||
|
/>
|
||||||
|
</TabContentWrapper>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user