+40
-15
appview/state/pull.go
+40
-15
appview/state/pull.go
···
563
return
564
}
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
// Determine PR type based on input parameters
581
isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed()
582
isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == ""
583
isForkBased := fromFork != "" && sourceBranch != ""
584
isPatchBased := patch != "" && !isBranchBased && !isForkBased
585
586
// Validate we have at least one valid PR creation method
587
if !isBranchBased && !isPatchBased && !isForkBased {
588
s.pages.Notice(w, "pull", "Neither source branch nor patch supplied.")
···
595
return
596
}
597
598
// Handle the PR creation based on the type
599
if isBranchBased {
600
if !caps.PullRequests.BranchSubmissions {
···
761
}
762
defer tx.Rollback()
763
764
rkey := s.TID()
765
initialSubmission := db.PullSubmission{
766
Patch: patch,
···
1159
1160
if err = validateResubmittedPatch(pull, patch); err != nil {
1161
s.pages.Notice(w, "resubmit-error", err.Error())
1162
}
1163
1164
if sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev {
···
1373
return fmt.Errorf("Patch is identical to previous submission.")
1374
}
1375
1376
-
if patchutil.IsPatchValid(patch) {
1377
return fmt.Errorf("Invalid patch format. Please provide a valid diff.")
1378
}
1379
···
563
return
564
}
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.")
···
588
return
589
}
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
+
605
// Handle the PR creation based on the type
606
if isBranchBased {
607
if !caps.PullRequests.BranchSubmissions {
···
768
}
769
defer tx.Rollback()
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
+
788
rkey := s.TID()
789
initialSubmission := db.PullSubmission{
790
Patch: patch,
···
1183
1184
if err = validateResubmittedPatch(pull, patch); err != nil {
1185
s.pages.Notice(w, "resubmit-error", err.Error())
1186
+
return
1187
}
1188
1189
if sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev {
···
1398
return fmt.Errorf("Patch is identical to previous submission.")
1399
}
1400
1401
+
if !patchutil.IsPatchValid(patch) {
1402
return fmt.Errorf("Invalid patch format. Please provide a valid diff.")
1403
}
1404