mirror of
https://github.com/harness/drone.git
synced 2025-05-10 22:21:22 +08:00
feat: [CODE-1234]: create a pull request template for your repository (#942)
This commit is contained in:
parent
80f91c2408
commit
f314fc1e5f
@ -31,11 +31,12 @@ import { Color, FontVariation } from '@harnessio/design-system'
|
|||||||
import cx from 'classnames'
|
import cx from 'classnames'
|
||||||
import type { EditorView } from '@codemirror/view'
|
import type { EditorView } from '@codemirror/view'
|
||||||
import { EditorSelection } from '@codemirror/state'
|
import { EditorSelection } from '@codemirror/state'
|
||||||
|
import { isEmpty } from 'lodash-es'
|
||||||
import { Editor } from 'components/Editor/Editor'
|
import { Editor } from 'components/Editor/Editor'
|
||||||
import { MarkdownViewer } from 'components/MarkdownViewer/MarkdownViewer'
|
import { MarkdownViewer } from 'components/MarkdownViewer/MarkdownViewer'
|
||||||
import { useStrings } from 'framework/strings'
|
import { useStrings } from 'framework/strings'
|
||||||
import { formatBytes, handleFileDrop, handlePaste } from 'utils/Utils'
|
import { formatBytes, handleFileDrop, handlePaste } from 'utils/Utils'
|
||||||
import { handleUpload } from 'utils/GitUtils'
|
import { decodeGitContent, handleUpload } from 'utils/GitUtils'
|
||||||
import type { TypesRepository } from 'services/code'
|
import type { TypesRepository } from 'services/code'
|
||||||
import css from './MarkdownEditorWithPreview.module.scss'
|
import css from './MarkdownEditorWithPreview.module.scss'
|
||||||
|
|
||||||
@ -73,6 +74,7 @@ const toolbar: ToolbarItem[] = [
|
|||||||
interface MarkdownEditorWithPreviewProps {
|
interface MarkdownEditorWithPreviewProps {
|
||||||
className?: string
|
className?: string
|
||||||
value?: string
|
value?: string
|
||||||
|
templateData?: string
|
||||||
onChange?: (value: string) => void
|
onChange?: (value: string) => void
|
||||||
onSave?: (value: string) => void
|
onSave?: (value: string) => void
|
||||||
onCancel?: () => void
|
onCancel?: () => void
|
||||||
@ -102,6 +104,7 @@ interface MarkdownEditorWithPreviewProps {
|
|||||||
export function MarkdownEditorWithPreview({
|
export function MarkdownEditorWithPreview({
|
||||||
className,
|
className,
|
||||||
value = '',
|
value = '',
|
||||||
|
templateData = '',
|
||||||
onChange,
|
onChange,
|
||||||
onSave,
|
onSave,
|
||||||
onCancel,
|
onCancel,
|
||||||
@ -271,6 +274,18 @@ export function MarkdownEditorWithPreview({
|
|||||||
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [autoFocusAndPosition, viewRef, containerRef, scrollToAndSetCursorToEnd, dirty])
|
}, [autoFocusAndPosition, viewRef, containerRef, scrollToAndSetCursorToEnd, dirty])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEmpty(templateData)) {
|
||||||
|
viewRef.current?.dispatch({
|
||||||
|
changes: {
|
||||||
|
from: 0,
|
||||||
|
to: 0,
|
||||||
|
insert: decodeGitContent(templateData)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [templateData])
|
||||||
|
|
||||||
const setFileCallback = (newFile: File) => {
|
const setFileCallback = (newFile: File) => {
|
||||||
setFile(newFile)
|
setFile(newFile)
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@ import { CodeIcon, normalizeGitRef, isRefATag, makeDiffRefs, isGitRev } from 'ut
|
|||||||
import { Changes } from 'components/Changes/Changes'
|
import { Changes } from 'components/Changes/Changes'
|
||||||
import type {
|
import type {
|
||||||
OpenapiCreatePullReqRequest,
|
OpenapiCreatePullReqRequest,
|
||||||
|
OpenapiGetContentOutput,
|
||||||
|
RepoFileContent,
|
||||||
TypesCommit,
|
TypesCommit,
|
||||||
TypesDiffStats,
|
TypesDiffStats,
|
||||||
TypesPullReq,
|
TypesPullReq,
|
||||||
@ -88,6 +90,15 @@ export default function Compare() {
|
|||||||
},
|
},
|
||||||
lazy: !repoMetadata || sourceGitRef === ''
|
lazy: !repoMetadata || sourceGitRef === ''
|
||||||
})
|
})
|
||||||
|
const { data: prTemplateData } = useGet<OpenapiGetContentOutput>({
|
||||||
|
path: `/api/v1/repos/${repoMetadata?.path}/+/content/.harness/pull_request_template.md`,
|
||||||
|
queryParams: {
|
||||||
|
include_commit: false,
|
||||||
|
git_ref: normalizeGitRef(targetGitRef)
|
||||||
|
},
|
||||||
|
lazy: !repoMetadata || sourceGitRef === ''
|
||||||
|
})
|
||||||
|
|
||||||
const onCreatePullRequest = useCallback(
|
const onCreatePullRequest = useCallback(
|
||||||
(creationType: PRCreationType) => {
|
(creationType: PRCreationType) => {
|
||||||
if (!sourceGitRef || !targetGitRef) {
|
if (!sourceGitRef || !targetGitRef) {
|
||||||
@ -247,6 +258,7 @@ export default function Compare() {
|
|||||||
standalone={standalone}
|
standalone={standalone}
|
||||||
repoMetadata={repoMetadata}
|
repoMetadata={repoMetadata}
|
||||||
value={description}
|
value={description}
|
||||||
|
templateData={(prTemplateData?.content as RepoFileContent)?.data}
|
||||||
onChange={setDescription}
|
onChange={setDescription}
|
||||||
hideButtons
|
hideButtons
|
||||||
autoFocusAndPosition={true}
|
autoFocusAndPosition={true}
|
||||||
|
Loading…
Reference in New Issue
Block a user