Monorepo for Tangled tangled.org

nicer errors

Changed files
+39 -22
appview
pages
templates
state
+23 -12
appview/pages/templates/repo/pulls/new.html
··· 8 8 <ul class="list-decimal pl-10 space-y-2 text-gray-700 dark:text-gray-300"> 9 9 <li class="leading-relaxed">Clone this repository.</li> 10 10 <li class="leading-relaxed">Make your changes in your local repository.</li> 11 - <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> 11 + <li class="leading-relaxed">Grab the diff using <code>git diff</code>.</li> 12 12 <li class="leading-relaxed">Paste the diff output in the form below.</li> 13 13 </ul> 14 14 </p> ··· 39 39 <label for="targetBranch" class="dark:text-white">configure branches</label> 40 40 <div class="flex flex-wrap gap-2 items-center"> 41 41 <select 42 + required 42 43 name="targetBranch" 43 44 class="p-1 border border-gray-200 bg-white dark:bg-gray-700 dark:text-white dark:border-gray-600" 44 45 > ··· 69 70 </div> 70 71 71 72 <div class="mt-4"> 72 - <label for="patch" class="dark:text-white">paste your patch here</label> 73 - <textarea 74 - name="patch" 75 - id="patch" 76 - rows="10" 77 - class="w-full resize-y font-mono dark:bg-gray-700 dark:text-white dark:border-gray-600" 78 - placeholder="Paste your git diff output here." 79 - ></textarea> 73 + {{ $label := "paste your patch here" }} 74 + {{ $rows := 10 }} 75 + {{ if .RepoInfo.Roles.IsPushAllowed }} 76 + {{ $label = "or paste your patch here" }} 77 + {{ $rows = 4 }} 78 + {{ end }} 79 + 80 + <label for="patch" class="dark:text-white">{{ $label }}</label> 81 + <textarea 82 + name="patch" 83 + id="patch" 84 + rows="{{$rows}}" 85 + class="w-full resize-y font-mono dark:bg-gray-700 dark:text-white dark:border-gray-600" 86 + placeholder="Paste your git diff output here." 87 + ></textarea> 80 88 </div> 81 89 82 - <div class="flex items-center gap-2"> 83 - <button type="submit" class="btn">create</button> 84 - <button class="btn">TODO preview</button> 90 + <div class="flex justify-end items-center gap-2"> 91 + <button type="submit" class="btn">create</button> 85 92 </div> 86 93 87 94 </div> 88 95 <div id="pull" class="error dark:text-red-300"></div> 89 96 </form> 90 97 {{ end }} 98 + 99 + {{ define "repoAfter" }} 100 + <div id="patch-preview" class="error dark:text-red-300"></div> 101 + {{ end }}
+2 -1
appview/pages/templates/repo/pulls/pull.html
··· 39 39 <span class="select-none before:content-['\00B7']"></span> 40 40 <time>{{ .Pull.Created | timeFmt }}</time> 41 41 <span class="select-none before:content-['\00B7']"></span> 42 - <span>targeting 42 + <span> 43 + patch targeting 43 44 <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"> 44 45 {{ .Pull.TargetBranch }} 45 46 </span>
+1 -1
appview/pages/templates/repo/pulls/pulls.html
··· 73 73 </span> 74 74 75 75 <span class="before:content-['·']"> 76 - targeting 76 + patch targeting 77 77 <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"> 78 78 {{ .TargetBranch }} 79 79 </span>
+13 -8
appview/state/pull.go
··· 450 450 Branches: result.Branches, 451 451 }) 452 452 case http.MethodPost: 453 + isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed() 453 454 title := r.FormValue("title") 454 455 body := r.FormValue("body") 455 456 targetBranch := r.FormValue("targetBranch") 456 457 sourceBranch := r.FormValue("sourceBranch") 457 458 patch := r.FormValue("patch") 458 459 459 - if sourceBranch == "" && patch == "" { 460 - s.pages.Notice(w, "pull", "neither sourceBranch nor patch supplied") 460 + if patch == "" { 461 + if isPushAllowed && sourceBranch == "" { 462 + s.pages.Notice(w, "pull", "Neither source branch nor patch supplied.") 463 + return 464 + } 465 + s.pages.Notice(w, "pull", "Patch is empty.") 466 + return 467 + } 468 + 469 + if patch != "" && sourceBranch != "" { 470 + s.pages.Notice(w, "pull", "Cannot select both patch and source branch.") 461 471 return 462 472 } 463 473 464 474 if title == "" || body == "" || targetBranch == "" { 465 - s.pages.Notice(w, "pull", "Title, body and patch diff are required.") 475 + s.pages.Notice(w, "pull", "Title, body and target branch are required.") 466 476 return 467 477 } 468 - 469 - isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed() 470 478 471 479 // TODO: check if knot has this capability 472 480 var pullSource *db.PullSource ··· 579 587 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId)) 580 588 return 581 589 } 582 - } 583 - 584 - func (s *State) RenderDiffFragment(w http.ResponseWriter, r *http.Request) { 585 590 } 586 591 587 592 func (s *State) ResubmitPull(w http.ResponseWriter, r *http.Request) {