feat: [CODE-1234]: create a pull request template for your repository (#942)

This commit is contained in:
Karan Saraswat 2024-01-05 05:55:53 +00:00 committed by Harness
parent 80f91c2408
commit f314fc1e5f
2 changed files with 28 additions and 1 deletions

View File

@ -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)
}

View File

@ -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}