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 type { EditorView } from '@codemirror/view'
|
||||
import { EditorSelection } from '@codemirror/state'
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import { Editor } from 'components/Editor/Editor'
|
||||
import { MarkdownViewer } from 'components/MarkdownViewer/MarkdownViewer'
|
||||
import { useStrings } from 'framework/strings'
|
||||
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 css from './MarkdownEditorWithPreview.module.scss'
|
||||
|
||||
@ -73,6 +74,7 @@ const toolbar: ToolbarItem[] = [
|
||||
interface MarkdownEditorWithPreviewProps {
|
||||
className?: string
|
||||
value?: string
|
||||
templateData?: string
|
||||
onChange?: (value: string) => void
|
||||
onSave?: (value: string) => void
|
||||
onCancel?: () => void
|
||||
@ -102,6 +104,7 @@ interface MarkdownEditorWithPreviewProps {
|
||||
export function MarkdownEditorWithPreview({
|
||||
className,
|
||||
value = '',
|
||||
templateData = '',
|
||||
onChange,
|
||||
onSave,
|
||||
onCancel,
|
||||
@ -271,6 +274,18 @@ export function MarkdownEditorWithPreview({
|
||||
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [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) => {
|
||||
setFile(newFile)
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ import { CodeIcon, normalizeGitRef, isRefATag, makeDiffRefs, isGitRev } from 'ut
|
||||
import { Changes } from 'components/Changes/Changes'
|
||||
import type {
|
||||
OpenapiCreatePullReqRequest,
|
||||
OpenapiGetContentOutput,
|
||||
RepoFileContent,
|
||||
TypesCommit,
|
||||
TypesDiffStats,
|
||||
TypesPullReq,
|
||||
@ -88,6 +90,15 @@ export default function Compare() {
|
||||
},
|
||||
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(
|
||||
(creationType: PRCreationType) => {
|
||||
if (!sourceGitRef || !targetGitRef) {
|
||||
@ -247,6 +258,7 @@ export default function Compare() {
|
||||
standalone={standalone}
|
||||
repoMetadata={repoMetadata}
|
||||
value={description}
|
||||
templateData={(prTemplateData?.content as RepoFileContent)?.data}
|
||||
onChange={setDescription}
|
||||
hideButtons
|
||||
autoFocusAndPosition={true}
|
||||
|
Loading…
Reference in New Issue
Block a user