From afd12df03dd839b91b14ddf3af811c8f35a7c903 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Thu, 22 May 2025 15:21:04 +0300 Subject: [PATCH] appview: state: populate new pull form from query params --- appview/pages/pages.go | 6 +++ .../pulls/fragments/pullCompareBranches.html | 11 ++++- .../pulls/fragments/pullCompareForks.html | 3 +- appview/pages/templates/repo/pulls/new.html | 48 +++++++++++++++++-- appview/state/pull.go | 12 +++++ 5 files changed, 73 insertions(+), 7 deletions(-) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index fc593eb8..bc6aeeba 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -698,6 +698,11 @@ type RepoNewPullParams struct { LoggedInUser *oauth.User RepoInfo repoinfo.RepoInfo Branches []types.Branch + Strategy string + SourceBranch string + TargetBranch string + Title string + Body string Active string } @@ -805,6 +810,7 @@ func (p *Pages) PullCompareBranchesFragment(w io.Writer, params PullCompareBranc type PullCompareForkParams struct { RepoInfo repoinfo.RepoInfo Forks []db.Repo + Selected string } func (p *Pages) PullCompareForkFragment(w io.Writer, params PullCompareForkParams) error { diff --git a/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html b/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html index 734bdee5..bad7b045 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html +++ b/appview/pages/templates/repo/pulls/fragments/pullCompareBranches.html @@ -1,6 +1,6 @@ {{ define "repo/pulls/fragments/pullCompareBranches" }}
- +
{{ range .Forks }} - {{ end }} diff --git a/appview/pages/templates/repo/pulls/new.html b/appview/pages/templates/repo/pulls/new.html index 0dafbab8..86916413 100644 --- a/appview/pages/templates/repo/pulls/new.html +++ b/appview/pages/templates/repo/pulls/new.html @@ -1,6 +1,10 @@ {{ define "title" }}new pull · {{ .RepoInfo.FullName }}{{ end }} {{ define "repoContent" }} +

+ Create new pull request +

+
+ + {{ range .Branches }} - {{ end }} @@ -26,7 +40,9 @@
-

Next, choose a pull strategy.

+

+ Choose pull strategy +

- {{ template "repo/pulls/fragments/pullPatchUpload" . }} + {{ if eq .Strategy "patch" }} + {{ template "repo/pulls/fragments/pullPatchUpload" . }} + {{ else if eq .Strategy "branch" }} + {{ template "repo/pulls/fragments/pullCompareBranches" . }} + {{ else }} + {{ template "repo/pulls/fragments/pullPatchUpload" . }} + {{ end }}
@@ -81,6 +120,7 @@ type="text" name="title" id="title" + value="{{ .Title }}" class="w-full dark:bg-gray-700 dark:text-white dark:border-gray-600" placeholder="One-line summary of your change." /> @@ -97,7 +137,7 @@ rows="6" class="w-full resize-y dark:bg-gray-700 dark:text-white dark:border-gray-600" placeholder="Describe your change. Markdown is supported." - > + >{{ .Body }}
diff --git a/appview/state/pull.go b/appview/state/pull.go index fa332064..eaf7778c 100644 --- a/appview/state/pull.go +++ b/appview/state/pull.go @@ -634,10 +634,21 @@ func (s *State) NewPull(w http.ResponseWriter, r *http.Request) { return } + // can be one of "patch", "branch" or "fork" + strategy := r.URL.Query().Get("strategy") + // ignored if strategy is "patch" + sourceBranch := r.URL.Query().Get("sourceBranch") + targetBranch := r.URL.Query().Get("targetBranch") + s.pages.RepoNewPull(w, pages.RepoNewPullParams{ LoggedInUser: user, RepoInfo: f.RepoInfo(s, user), Branches: result.Branches, + Strategy: strategy, + SourceBranch: sourceBranch, + TargetBranch: targetBranch, + Title: r.URL.Query().Get("title"), + Body: r.URL.Query().Get("body"), }) case http.MethodPost: @@ -1180,6 +1191,7 @@ func (s *State) CompareForksFragment(w http.ResponseWriter, r *http.Request) { s.pages.PullCompareForkFragment(w, pages.PullCompareForkParams{ RepoInfo: f.RepoInfo(s, user), Forks: forks, + Selected: r.URL.Query().Get("fork"), }) } -- 2.51.2