Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: state: better title/body checks

authored by

Anirudh Oppiliappan and committed by
Akshay
3d8db920 f8b1abee

+44 -19
+44 -19
appview/state/pull.go
··· 563 563 return 564 564 } 565 565 566 + // Determine PR type based on input parameters 567 + isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed() 568 + isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == "" 569 + isForkBased := fromFork != "" && sourceBranch != "" 570 + isPatchBased := patch != "" && !isBranchBased && !isForkBased 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 + 579 + // Validate we have at least one valid PR creation method 580 + if !isBranchBased && !isPatchBased && !isForkBased { 581 + s.pages.Notice(w, "pull", "Neither source branch nor patch supplied.") 582 + return 583 + } 584 + 585 + // Can't mix branch-based and patch-based approaches 586 + if isBranchBased && patch != "" { 587 + s.pages.Notice(w, "pull", "Cannot select both patch and source branch.") 588 + return 589 + } 590 + 566 591 us, err := NewUnsignedClient(f.Knot, s.config.Dev) 567 592 if err != nil { 568 593 log.Printf("failed to create unsigned client to %s: %v", f.Knot, err) ··· 599 574 if err != nil { 600 575 log.Println("error fetching knot caps", f.Knot, err) 601 576 s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.") 602 - return 603 - } 604 - 605 - // Determine PR type based on input parameters 606 - isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed() 607 - isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == "" 608 - isForkBased := fromFork != "" && sourceBranch != "" 609 - isPatchBased := patch != "" && !isBranchBased && !isForkBased 610 - 611 - // Validate we have at least one valid PR creation method 612 - if !isBranchBased && !isPatchBased && !isForkBased { 613 - s.pages.Notice(w, "pull", "Neither source branch nor patch supplied.") 614 - return 615 - } 616 - 617 - // Can't mix branch-based and patch-based approaches 618 - if isBranchBased && patch != "" { 619 - s.pages.Notice(w, "pull", "Cannot select both patch and source branch.") 620 577 return 621 578 } 622 579 ··· 767 760 return 768 761 } 769 762 defer tx.Rollback() 763 + 764 + // We've already checked earlier if it's diff-based and title is empty, 765 + // so if it's still empty now, it's intentionally skipped owing to format-patch. 766 + if title == "" { 767 + formatPatches, err := patchutil.ExtractPatches(patch) 768 + if err != nil { 769 + s.pages.Notice(w, "pull", fmt.Sprintf("Failed to extract patches: %v", err)) 770 + return 771 + } 772 + if len(formatPatches) == 0 { 773 + s.pages.Notice(w, "pull", "No patches found in the supplied format-patch.") 774 + return 775 + } 776 + 777 + title = formatPatches[0].Title 778 + body = formatPatches[0].Body 779 + } 770 780 771 781 rkey := s.TID() 772 782 initialSubmission := db.PullSubmission{ ··· 1183 1159 1184 1160 if err = validateResubmittedPatch(pull, patch); err != nil { 1185 1161 s.pages.Notice(w, "resubmit-error", err.Error()) 1162 + return 1186 1163 } 1187 1164 1188 1165 if sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev { ··· 1398 1373 return fmt.Errorf("Patch is identical to previous submission.") 1399 1374 } 1400 1375 1401 - if patchutil.IsPatchValid(patch) { 1376 + if !patchutil.IsPatchValid(patch) { 1402 1377 return fmt.Errorf("Invalid patch format. Please provide a valid diff.") 1403 1378 } 1404 1379