diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 3ae2fa74..b94f1851 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1278,16 +1278,38 @@ func (p *Pages) IssueCommentBodyFragment(w io.Writer, params IssueCommentBodyPar return p.executePlain("repo/issues/fragments/issueCommentBody", w, params) } +type StackedDiff struct { + Diff *types.NiceDiff + Opts types.DiffOpts +} + type RepoNewPullParams struct { - LoggedInUser *oauth.MultiAccountUser - RepoInfo repoinfo.RepoInfo - Branches []types.Branch - Strategy string - SourceBranch string - TargetBranch string - Title string - Body string - Active string + LoggedInUser *oauth.MultiAccountUser + RepoInfo repoinfo.RepoInfo + Branches []types.Branch + SourceBranches []types.Branch + ForkBranches []types.Branch + Forks []models.Repo + Source Source + SourceBranch string + TargetBranch string + Fork string + Patch string + Title string + Body string + IsStacked bool + Comparison *types.RepoFormatPatchResponse + Diff *types.NiceDiff + DiffOpts types.DiffOpts + StackedDiffs []StackedDiff + MergeCheck *types.MergeCheckResponse + StackTitles map[string]string + StackBodies map[string]string + PrefillError string + Active string + LabelDefs map[string]*models.LabelDefinition + LabelState models.LabelState + StackLabelStates map[string]models.LabelState } func (p *Pages) RepoNewPull(w io.Writer, params RepoNewPullParams) error { @@ -1295,6 +1317,14 @@ func (p *Pages) RepoNewPull(w io.Writer, params RepoNewPullParams) error { return p.executeRepo("repo/pulls/new", w, params) } +func (p *Pages) PullComposeHostFragment(w io.Writer, params RepoNewPullParams) error { + return p.executePlain("repo/pulls/fragments/pullComposeHost", w, params) +} + +func (p *Pages) MarkdownPreviewFragment(w io.Writer, body string) error { + return p.executePlain("fragments/markdownPreview", w, body) +} + type RepoPullsParams struct { LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo @@ -1391,44 +1421,6 @@ func (p *Pages) RepoPullInterdiffPage(w io.Writer, params RepoPullInterdiffParam return p.execute("repo/pulls/interdiff", w, params) } -type PullPatchUploadParams struct { - RepoInfo repoinfo.RepoInfo -} - -func (p *Pages) PullPatchUploadFragment(w io.Writer, params PullPatchUploadParams) error { - return p.executePlain("repo/pulls/fragments/pullPatchUpload", w, params) -} - -type PullCompareBranchesParams struct { - RepoInfo repoinfo.RepoInfo - Branches []types.Branch - SourceBranch string -} - -func (p *Pages) PullCompareBranchesFragment(w io.Writer, params PullCompareBranchesParams) error { - return p.executePlain("repo/pulls/fragments/pullCompareBranches", w, params) -} - -type PullCompareForkParams struct { - RepoInfo repoinfo.RepoInfo - Forks []models.Repo - Selected string -} - -func (p *Pages) PullCompareForkFragment(w io.Writer, params PullCompareForkParams) error { - return p.executePlain("repo/pulls/fragments/pullCompareForks", w, params) -} - -type PullCompareForkBranchesParams struct { - RepoInfo repoinfo.RepoInfo - SourceBranches []types.Branch - TargetBranches []types.Branch -} - -func (p *Pages) PullCompareForkBranchesFragment(w io.Writer, params PullCompareForkBranchesParams) error { - return p.executePlain("repo/pulls/fragments/pullCompareForksBranches", w, params) -} - type PullResubmitParams struct { LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo diff --git a/appview/pages/pulls_compose.go b/appview/pages/pulls_compose.go new file mode 100644 index 00000000..1e0ab432 --- /dev/null +++ b/appview/pages/pulls_compose.go @@ -0,0 +1,24 @@ +package pages + +import "strings" + +type Source string + +const ( + SourcePatch Source = "patch" + SourceBranch Source = "branch" + SourceFork Source = "fork" +) + +func ParseSource(s string) (Source, bool) { + switch strings.ToLower(s) { + case string(SourcePatch): + return SourcePatch, true + case string(SourceFork): + return SourceFork, true + case string(SourceBranch): + return SourceBranch, true + default: + return "", false + } +} diff --git a/appview/pages/templates/fragments/markdownPreview.html b/appview/pages/templates/fragments/markdownPreview.html new file mode 100644 index 00000000..b65f13b3 --- /dev/null +++ b/appview/pages/templates/fragments/markdownPreview.html @@ -0,0 +1,9 @@ +{{ define "fragments/markdownPreview" }} + {{ if . }} +
+ {{ . | markdown }} +
+ {{ else }} +
Nothing to preview.
+ {{ end }} +{{ end }} diff --git a/appview/pages/templates/repo/pulls/fragments/pullComposeHost.html b/appview/pages/templates/repo/pulls/fragments/pullComposeHost.html new file mode 100644 index 00000000..c3e75d63 --- /dev/null +++ b/appview/pages/templates/repo/pulls/fragments/pullComposeHost.html @@ -0,0 +1,74 @@ +{{ define "repo/pulls/fragments/pullComposeHost" }} +
+ {{ if .PrefillError }} +
+ {{ i "triangle-alert" "w-4 h-4 flex-shrink-0" }} + {{ .PrefillError }} +
+ {{ end }} + + {{ $hasCommits := and .Comparison .Comparison.FormatPatch }} + {{ $hasDiff := false }} + {{ if .Diff }}{{ if .Diff.Diff }}{{ $hasDiff = true }}{{ end }}{{ end }} + {{ $showDetails := and (or $hasCommits $hasDiff) (not .IsStacked) }} + +
+
+
+
+
+ {{ template "pullComposeSectionNumber" 1 }} +
+

source

+
+
+ {{ template "repo/pulls/fragments/pullStepSource" . }} +
+
+ +
+ {{ if $showDetails }} +
+ {{ else }} +
+ {{ end }} +
+
+ {{ template "pullComposeSectionNumber" 2 }} +
+

review

+
+
+ {{ template "repo/pulls/fragments/pullStepReview" . }} +
+
+ + {{ if $showDetails }} +
+
+
+
+ {{ template "pullComposeSectionNumber" 3 }} +
+

details

+
+
+ {{ template "repo/pulls/fragments/pullStepDetails" . }} +
+
+ {{ end }} +
+ +
+
+{{ end }} + +{{ define "pullComposeSectionNumber" }} + {{ . }} +{{ end }} diff --git a/appview/pages/templates/repo/pulls/fragments/pullStepDetails.html b/appview/pages/templates/repo/pulls/fragments/pullStepDetails.html new file mode 100644 index 00000000..b76fd5e7 --- /dev/null +++ b/appview/pages/templates/repo/pulls/fragments/pullStepDetails.html @@ -0,0 +1,146 @@ +{{ define "repo/pulls/fragments/pullStepDetails" }} + {{ $hasSidePanel := and .LabelDefs .RepoInfo.Roles.IsPushAllowed }} + {{ $previewUrl := printf "/%s/pulls/new/preview" .RepoInfo.FullName }} + {{ $labelCtx := dict "Defs" .LabelDefs "State" .LabelState "RepoInfo" .RepoInfo "Subject" "" "LoggedInUser" .LoggedInUser }} + +
+
+ {{ template "pullStepDetailsSingle" (dict "Root" . "PreviewUrl" $previewUrl) }} + {{ template "pullSubmitRow" . }} +
+ + {{ if $hasSidePanel }} + + {{ end }} +
+ + {{ template "markdownEditorScript" }} +{{ end }} + +{{ define "pullStepDetailsSingle" }} + {{ $root := .Root }} + {{ $previewUrl := .PreviewUrl }} +
+ + +
+ + {{ template "markdownEditor" (dict + "Id" "pull-body" + "Name" "body" + "Value" $root.Body + "Rows" 6 + "Placeholder" "Describe your change. Markdown is supported." + "PreviewUrl" $previewUrl + ) }} +{{ end }} + +{{ define "markdownEditor" }} + {{ $id := .Id }} + {{ $name := .Name }} + {{ $value := .Value }} + {{ $rows := .Rows }} + {{ $placeholder := .Placeholder }} + {{ $previewUrl := .PreviewUrl }} +
+ {{ $tabClasses := "group flex items-center gap-2 px-3 py-1 text-sm whitespace-nowrap rounded hover:no-underline data-[active=true]:bg-white data-[active=true]:dark:bg-gray-800 data-[active=true]:shadow-sm data-[active=true]:cursor-default data-[active=false]:hover:text-gray-900 data-[active=false]:dark:hover:text-white" }} +
+ + +
+
+ +
+ +
+{{ end }} + +{{ define "pullSubmitRow" }} +
+ {{ if and .MergeCheck .MergeCheck.IsConflicted }} +
+ + {{ i "x" "w-4 h-4" }} + Can't automatically merge + + You can still create the pull request +
+ {{ else if and .MergeCheck .MergeCheck.Error }} +
+ {{ i "triangle-alert" "w-4 h-4" }} + Merge check failed +
+ {{ end }} + + +
+{{ end }} + +{{ define "markdownEditorScript" }} + +{{ end }} diff --git a/appview/pages/templates/repo/pulls/fragments/pullStepSource.html b/appview/pages/templates/repo/pulls/fragments/pullStepSource.html new file mode 100644 index 00000000..43ae182f --- /dev/null +++ b/appview/pages/templates/repo/pulls/fragments/pullStepSource.html @@ -0,0 +1,156 @@ +{{ define "repo/pulls/fragments/pullStepSource" }} +
+ + + {{ template "pullSourceTabs" . }} + + {{ if eq .Source "patch" }} +
+ {{ template "repo/fragments/labelSectionHeaderText" "Merge into" }} + {{ template "pullTargetBranchSelect" . }} +
+ {{ template "repo/pulls/fragments/pullPatchUpload" . }} + {{ else }} +
+
+ {{ template "repo/fragments/labelSectionHeaderText" "Merge into" }} + {{ template "pullTargetBranchSelect" . }} +
+
+ {{ template "repo/fragments/labelSectionHeaderText" "Pull from" }} + {{ if eq .Source "fork" }} + {{ template "repo/pulls/fragments/pullCompareForks" . }} + {{ else }} + {{ template "repo/pulls/fragments/pullCompareBranches" . }} + {{ end }} +
+
+ {{ end }} + +
+ + {{ if ne .Source "patch" }} +
+ + + + {{ i "circle-question-mark" "size-4" }} + + {{ i "loader-circle" "size-4 animate-spin hidden peer-[.htmx-request]:inline text-gray-500 dark:text-gray-400" }} +
+ {{ end }} +
+{{ end }} + +{{ define "pullTargetBranchSelect" }} +
+ + {{ i "loader-circle" "size-4 animate-spin hidden peer-[.htmx-request]:inline text-gray-500 dark:text-gray-400" }} +
+{{ end }} + +{{ define "pullSourceTabs" }} + {{ $active := "bg-white dark:bg-gray-800 shadow-sm cursor-default" }} + {{ $inactive := "bg-transparent hover:bg-white/50 dark:hover:bg-gray-800/50" }} + {{ $shared := "group flex-1 p-3 text-left hover:no-underline flex flex-col gap-1 rounded border-0" }} + {{ $titleCls := "font-medium text-sm dark:text-white flex items-center gap-2" }} + {{ $descCls := "text-xs text-gray-500 dark:text-gray-400" }} + {{ $fullName := .RepoInfo.FullName }} +
+ {{ if .RepoInfo.Roles.IsPushAllowed }} + + {{ end }} + + +
+{{ end }} diff --git a/types/diff.go b/types/diff.go index 5204581b..96509ae0 100644 --- a/types/diff.go +++ b/types/diff.go @@ -8,7 +8,10 @@ import ( ) type DiffOpts struct { - Split bool `json:"split"` + Split bool `json:"split"` + RefreshUrl string `json:"refresh_url,omitempty"` + Target string `json:"target,omitempty"` + Field string `json:"field,omitempty"` } func (d DiffOpts) Encode() string { diff --git a/types/patch.go b/types/patch.go index ce9bfae0..1c725f4b 100644 --- a/types/patch.go +++ b/types/patch.go @@ -18,3 +18,11 @@ func (f FormatPatch) ChangeId() (string, error) { } return "", fmt.Errorf("no change-id found") } + +func (f FormatPatch) ChangeIdOrEmpty() string { + id, err := f.ChangeId() + if err != nil { + return "" + } + return id +}