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