forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

nicer errors

Changed files
+39 -22
appview
pages
templates
state
+23 -12
appview/pages/templates/repo/pulls/new.html
···
<ul class="list-decimal pl-10 space-y-2 text-gray-700 dark:text-gray-300">
<li class="leading-relaxed">Clone this repository.</li>
<li class="leading-relaxed">Make your changes in your local repository.</li>
-
<li class="leading-relaxed">Grab the diff using <code class="bg-gray-100 dark:bg-gray-700 px-1 py-0.5 rounded text-gray-800 dark:text-gray-200 font-mono text-sm">git diff</code>.</li>
+
<li class="leading-relaxed">Grab the diff using <code>git diff</code>.</li>
<li class="leading-relaxed">Paste the diff output in the form below.</li>
</ul>
</p>
···
<label for="targetBranch" class="dark:text-white">configure branches</label>
<div class="flex flex-wrap gap-2 items-center">
<select
+
required
name="targetBranch"
class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600"
>
···
</div>
<div class="mt-4">
-
<label for="patch" class="dark:text-white">paste your patch here</label>
-
<textarea
-
name="patch"
-
id="patch"
-
rows="10"
-
class="w-full resize-y font-mono dark:bg-gray-700 dark:text-white dark:border-gray-600"
-
placeholder="Paste your git diff output here."
-
></textarea>
+
{{ $label := "paste your patch here" }}
+
{{ $rows := 10 }}
+
{{ if .RepoInfo.Roles.IsPushAllowed }}
+
{{ $label = "or paste your patch here" }}
+
{{ $rows = 4 }}
+
{{ end }}
+
+
<label for="patch" class="dark:text-white">{{ $label }}</label>
+
<textarea
+
name="patch"
+
id="patch"
+
rows="{{$rows}}"
+
class="w-full resize-y font-mono dark:bg-gray-700 dark:text-white dark:border-gray-600"
+
placeholder="Paste your git diff output here."
+
></textarea>
</div>
-
<div class="flex items-center gap-2">
-
<button type="submit" class="btn">create</button>
-
<button class="btn">TODO preview</button>
+
<div class="flex justify-end items-center gap-2">
+
<button type="submit" class="btn">create</button>
</div>
</div>
<div id="pull" class="error dark:text-red-300"></div>
</form>
{{ end }}
+
+
{{ define "repoAfter" }}
+
<div id="patch-preview" class="error dark:text-red-300"></div>
+
{{ end }}
+2 -1
appview/pages/templates/repo/pulls/pull.html
···
<span class="select-none before:content-['\00B7']"></span>
<time>{{ .Pull.Created | timeFmt }}</time>
<span class="select-none before:content-['\00B7']"></span>
-
<span>targeting
+
<span>
+
patch targeting
<span class="text-xs rounded bg-gray-100 dark:bg-gray-700 text-black dark:text-white font-mono px-2 mx-1/2 inline-flex items-center">
{{ .Pull.TargetBranch }}
</span>
+1 -1
appview/pages/templates/repo/pulls/pulls.html
···
</span>
<span class="before:content-['·']">
-
targeting
+
patch targeting
<span class="text-xs rounded bg-gray-100 dark:bg-gray-600 text-black dark:text-white font-mono px-2 mx-1/2 inline-flex items-center">
{{ .TargetBranch }}
</span>
+13 -8
appview/state/pull.go
···
Branches: result.Branches,
})
case http.MethodPost:
+
isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed()
title := r.FormValue("title")
body := r.FormValue("body")
targetBranch := r.FormValue("targetBranch")
sourceBranch := r.FormValue("sourceBranch")
patch := r.FormValue("patch")
-
if sourceBranch == "" && patch == "" {
-
s.pages.Notice(w, "pull", "neither sourceBranch nor patch supplied")
+
if patch == "" {
+
if isPushAllowed && sourceBranch == "" {
+
s.pages.Notice(w, "pull", "Neither source branch nor patch supplied.")
+
return
+
}
+
s.pages.Notice(w, "pull", "Patch is empty.")
+
return
+
}
+
+
if patch != "" && sourceBranch != "" {
+
s.pages.Notice(w, "pull", "Cannot select both patch and source branch.")
return
}
if title == "" || body == "" || targetBranch == "" {
-
s.pages.Notice(w, "pull", "Title, body and patch diff are required.")
+
s.pages.Notice(w, "pull", "Title, body and target branch are required.")
return
}
-
-
isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed()
// TODO: check if knot has this capability
var pullSource *db.PullSource
···
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId))
return
}
-
}
-
-
func (s *State) RenderDiffFragment(w http.ResponseWriter, r *http.Request) {
}
func (s *State) ResubmitPull(w http.ResponseWriter, r *http.Request) {