forked from tangled.org/core
this repo has no description

appview: state: validate pasted patch

Changed files
+39 -12
appview
patchutil
+28 -4
appview/state/pull.go
···
sourceBranch := r.FormValue("sourceBranch")
patch := r.FormValue("patch")
-
// Validate required fields for all PR types
-
if title == "" || body == "" || targetBranch == "" {
-
s.pages.Notice(w, "pull", "Title, body and target branch are required.")
+
if targetBranch == "" {
+
s.pages.Notice(w, "pull", "Target branch is required.")
return
}
us, err := NewUnsignedClient(f.Knot, s.config.Dev)
if err != nil {
-
log.Println("failed to create unsigned client to %s: %v", f.Knot, err)
+
log.Printf("failed to create unsigned client to %s: %v", f.Knot, err)
s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.")
return
}
···
}
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId))
+
}
+
+
func (s *State) ValidatePatch(w http.ResponseWriter, r *http.Request) {
+
_, err := fullyResolvedRepo(r)
+
if err != nil {
+
log.Println("failed to get repo and knot", err)
+
return
+
}
+
+
patch := r.FormValue("patch")
+
if patch == "" {
+
s.pages.Notice(w, "patch-error", "Patch is required.")
+
return
+
}
+
+
if patch == "" || !patchutil.IsPatchValid(patch) {
+
s.pages.Notice(w, "patch-error", "Invalid patch format. Please provide a valid git diff or format-patch.")
+
return
+
}
+
+
if patchutil.IsFormatPatch(patch) {
+
s.pages.Notice(w, "patch-preview", "Format patch detected. Title and description are optional; if left out, they will be extracted from the first commit.")
+
} else {
+
s.pages.Notice(w, "patch-preview", "Regular diff detected. Please provide a title and description.")
+
}
}
func (s *State) PatchUploadFragment(w http.ResponseWriter, r *http.Request) {
+1
appview/state/router.go
···
r.With(AuthMiddleware(s)).Route("/new", func(r chi.Router) {
r.Get("/", s.NewPull)
r.Get("/patch-upload", s.PatchUploadFragment)
+
r.Post("/validate-patch", s.ValidatePatch)
r.Get("/compare-branches", s.CompareBranchesFragment)
r.Get("/compare-forks", s.CompareForksFragment)
r.Get("/fork-branches", s.CompareForksBranchesFragment)
+10 -5
input.css
···
font-size: 15px;
}
@supports (font-variation-settings: normal) {
-
html {
-
font-feature-settings: 'ss01' 1, 'kern' 1, 'liga' 1, 'cv05' 1, 'tnum' 1;
-
}
+
html {
+
font-feature-settings:
+
"ss01" 1,
+
"kern" 1,
+
"liga" 1,
+
"cv05" 1,
+
"tnum" 1;
+
}
}
a {
···
@apply block mb-2 text-gray-900 text-sm font-bold py-2 uppercase dark:text-gray-100;
}
input {
-
@apply bg-white border border-gray-400 rounded-sm focus:ring-black p-3 dark:bg-gray-800 dark:border-gray-600 dark:text-white dark:focus:ring-gray-400;
+
@apply border border-gray-400 block rounded bg-gray-50 focus:ring-black p-3 dark:bg-gray-800 dark:border-gray-600 dark:text-white dark:focus:ring-gray-400;
}
textarea {
-
@apply bg-white border border-gray-400 rounded-sm focus:ring-black p-3 dark:bg-gray-800 dark:border-gray-600 dark:text-white dark:focus:ring-gray-400;
+
@apply border border-gray-400 block rounded bg-gray-50 focus:ring-black p-3 dark:bg-gray-800 dark:border-gray-600 dark:text-white dark:focus:ring-gray-400;
}
details summary::-webkit-details-marker {
display: none;
-3
patchutil/patchutil.go
···
strings.HasPrefix(line, "commit ") {
headerCount++
}
-
if strings.HasPrefix(line, "diff --git ") {
-
return true
-
}
}
return headerCount >= 2