Monorepo for Tangled tangled.org

appview: state: better title/body checks

authored by anirudh.fi and committed by oppi.li 3d8db920 f8b1abee

Changed files
+40 -15
appview
state
+40 -15
appview/state/pull.go
··· 563 563 return 564 564 } 565 565 566 - us, err := NewUnsignedClient(f.Knot, s.config.Dev) 567 - if err != nil { 568 - log.Printf("failed to create unsigned client to %s: %v", f.Knot, err) 569 - s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.") 570 - return 571 - } 572 - 573 - caps, err := us.Capabilities() 574 - if err != nil { 575 - log.Println("error fetching knot caps", f.Knot, err) 576 - s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.") 577 - return 578 - } 579 - 580 566 // Determine PR type based on input parameters 581 567 isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed() 582 568 isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == "" 583 569 isForkBased := fromFork != "" && sourceBranch != "" 584 570 isPatchBased := patch != "" && !isBranchBased && !isForkBased 585 571 572 + if isPatchBased && !patchutil.IsFormatPatch(patch) { 573 + if title == "" { 574 + s.pages.Notice(w, "pull", "Title is required for git-diff patches.") 575 + return 576 + } 577 + } 578 + 586 579 // Validate we have at least one valid PR creation method 587 580 if !isBranchBased && !isPatchBased && !isForkBased { 588 581 s.pages.Notice(w, "pull", "Neither source branch nor patch supplied.") ··· 595 588 return 596 589 } 597 590 591 + us, err := NewUnsignedClient(f.Knot, s.config.Dev) 592 + if err != nil { 593 + log.Printf("failed to create unsigned client to %s: %v", f.Knot, err) 594 + s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.") 595 + return 596 + } 597 + 598 + caps, err := us.Capabilities() 599 + if err != nil { 600 + log.Println("error fetching knot caps", f.Knot, err) 601 + s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.") 602 + return 603 + } 604 + 598 605 // Handle the PR creation based on the type 599 606 if isBranchBased { 600 607 if !caps.PullRequests.BranchSubmissions { ··· 761 768 } 762 769 defer tx.Rollback() 763 770 771 + // We've already checked earlier if it's diff-based and title is empty, 772 + // so if it's still empty now, it's intentionally skipped owing to format-patch. 773 + if title == "" { 774 + formatPatches, err := patchutil.ExtractPatches(patch) 775 + if err != nil { 776 + s.pages.Notice(w, "pull", fmt.Sprintf("Failed to extract patches: %v", err)) 777 + return 778 + } 779 + if len(formatPatches) == 0 { 780 + s.pages.Notice(w, "pull", "No patches found in the supplied format-patch.") 781 + return 782 + } 783 + 784 + title = formatPatches[0].Title 785 + body = formatPatches[0].Body 786 + } 787 + 764 788 rkey := s.TID() 765 789 initialSubmission := db.PullSubmission{ 766 790 Patch: patch, ··· 1159 1183 1160 1184 if err = validateResubmittedPatch(pull, patch); err != nil { 1161 1185 s.pages.Notice(w, "resubmit-error", err.Error()) 1186 + return 1162 1187 } 1163 1188 1164 1189 if sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev { ··· 1373 1398 return fmt.Errorf("Patch is identical to previous submission.") 1374 1399 } 1375 1400 1376 - if patchutil.IsPatchValid(patch) { 1401 + if !patchutil.IsPatchValid(patch) { 1377 1402 return fmt.Errorf("Invalid patch format. Please provide a valid diff.") 1378 1403 } 1379 1404