···
"github.com/go-chi/chi/v5"
···
"tangled.sh/tangled.sh/core/appview/auth"
"tangled.sh/tangled.sh/core/appview/db"
"tangled.sh/tangled.sh/core/appview/pages"
"tangled.sh/tangled.sh/core/types"
comatproto "github.com/bluesky-social/indigo/api/atproto"
···
latestSubmission := pull.Submissions[pull.LastRoundNumber()]
if latestSubmission.SourceRev != result.Branch.Hash {
return pages.ShouldResubmit
···
-
diffTreeResponse, err := ksClient.Compare(f.OwnerDid(), f.RepoName, targetBranch, sourceBranch)
log.Println("failed to compare", err)
s.pages.Notice(w, "pull", err.Error())
-
sourceRev := diffTreeResponse.DiffTree.Rev2
-
patch := diffTreeResponse.DiffTree.Patch
-
if !isPatchValid(patch) {
s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.")
···
func (s *State) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, f *FullyResolvedRepo, user *auth.User, title, body, targetBranch, patch string) {
-
if !isPatchValid(patch) {
s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.")
···
// hiddenRef: hidden/feature-1/main (on repo-fork)
// targetBranch: main (on repo-1)
// sourceBranch: feature-1 (on repo-fork)
-
diffTreeResponse, err := us.Compare(user.Did, fork.Name, hiddenRef, sourceBranch)
log.Println("failed to compare across branches", err)
s.pages.Notice(w, "pull", err.Error())
-
sourceRev := diffTreeResponse.DiffTree.Rev2
-
patch := diffTreeResponse.DiffTree.Patch
-
if !isPatchValid(patch) {
s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.")
···
}, &tangled.RepoPull_Source{Branch: sourceBranch, Repo: &fork.AtUri})
-
func (s *State) createPullRequest(w http.ResponseWriter, r *http.Request, f *FullyResolvedRepo, user *auth.User, title, body, targetBranch, patch, sourceRev string, pullSource *db.PullSource, recordPullSource *tangled.RepoPull_Source) {
tx, err := s.db.BeginTx(r.Context(), nil)
log.Println("failed to start tx")
···
-
diffTreeResponse, err := ksClient.Compare(f.OwnerDid(), f.RepoName, pull.TargetBranch, pull.PullSource.Branch)
log.Printf("compare request failed: %s", err)
s.pages.Notice(w, "resubmit-error", err.Error())
-
sourceRev := diffTreeResponse.DiffTree.Rev2
-
patch := diffTreeResponse.DiffTree.Patch
if err = validateResubmittedPatch(pull, patch); err != nil {
s.pages.Notice(w, "resubmit-error", err.Error())
···
hiddenRef := url.QueryEscape(fmt.Sprintf("hidden/%s/%s", pull.PullSource.Branch, pull.TargetBranch))
-
diffTreeResponse, err := ksClient.Compare(forkRepo.Did, forkRepo.Name, hiddenRef, pull.PullSource.Branch)
log.Printf("failed to compare branches: %s", err)
s.pages.Notice(w, "resubmit-error", err.Error())
-
sourceRev := diffTreeResponse.DiffTree.Rev2
-
patch := diffTreeResponse.DiffTree.Patch
if err = validateResubmittedPatch(pull, patch); err != nil {
s.pages.Notice(w, "resubmit-error", err.Error())
···
return fmt.Errorf("Patch is identical to previous submission.")
-
if !isPatchValid(patch) {
return fmt.Errorf("Invalid patch format. Please provide a valid diff.")
···
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
-
// Very basic validation to check if it looks like a diff/patch
-
// A valid patch usually starts with diff or --- lines
-
func isPatchValid(patch string) bool {
-
// Basic validation to check if it looks like a diff/patch
-
// A valid patch usually starts with diff or --- lines
-
lines := strings.Split(patch, "\n")
-
// Check for common patch format markers
-
firstLine := strings.TrimSpace(lines[0])
-
return strings.HasPrefix(firstLine, "diff ") ||
-
strings.HasPrefix(firstLine, "--- ") ||
-
strings.HasPrefix(firstLine, "Index: ") ||
-
strings.HasPrefix(firstLine, "+++ ") ||
-
strings.HasPrefix(firstLine, "@@ ")
···
"github.com/go-chi/chi/v5"
···
"tangled.sh/tangled.sh/core/appview/auth"
"tangled.sh/tangled.sh/core/appview/db"
"tangled.sh/tangled.sh/core/appview/pages"
+
"tangled.sh/tangled.sh/core/patchutil"
"tangled.sh/tangled.sh/core/types"
comatproto "github.com/bluesky-social/indigo/api/atproto"
···
latestSubmission := pull.Submissions[pull.LastRoundNumber()]
if latestSubmission.SourceRev != result.Branch.Hash {
+
fmt.Println(latestSubmission.SourceRev, result.Branch.Hash)
return pages.ShouldResubmit
···
+
comparison, err := ksClient.Compare(f.OwnerDid(), f.RepoName, targetBranch, sourceBranch)
log.Println("failed to compare", err)
s.pages.Notice(w, "pull", err.Error())
+
sourceRev := comparison.Rev2
+
patch := comparison.Patch
+
if !patchutil.IsPatchValid(patch) {
s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.")
···
func (s *State) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, f *FullyResolvedRepo, user *auth.User, title, body, targetBranch, patch string) {
+
if !patchutil.IsPatchValid(patch) {
s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.")
···
// hiddenRef: hidden/feature-1/main (on repo-fork)
// targetBranch: main (on repo-1)
// sourceBranch: feature-1 (on repo-fork)
+
comparison, err := us.Compare(user.Did, fork.Name, hiddenRef, sourceBranch)
log.Println("failed to compare across branches", err)
s.pages.Notice(w, "pull", err.Error())
+
sourceRev := comparison.Rev2
+
patch := comparison.Patch
+
if patchutil.IsPatchValid(patch) {
s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.")
···
}, &tangled.RepoPull_Source{Branch: sourceBranch, Repo: &fork.AtUri})
+
func (s *State) createPullRequest(
+
title, body, targetBranch string,
+
pullSource *db.PullSource,
+
recordPullSource *tangled.RepoPull_Source,
tx, err := s.db.BeginTx(r.Context(), nil)
log.Println("failed to start tx")
···
+
comparison, err := ksClient.Compare(f.OwnerDid(), f.RepoName, pull.TargetBranch, pull.PullSource.Branch)
log.Printf("compare request failed: %s", err)
s.pages.Notice(w, "resubmit-error", err.Error())
+
sourceRev := comparison.Rev2
+
patch := comparison.Patch
if err = validateResubmittedPatch(pull, patch); err != nil {
s.pages.Notice(w, "resubmit-error", err.Error())
···
hiddenRef := url.QueryEscape(fmt.Sprintf("hidden/%s/%s", pull.PullSource.Branch, pull.TargetBranch))
+
comparison, err := ksClient.Compare(forkRepo.Did, forkRepo.Name, hiddenRef, pull.PullSource.Branch)
log.Printf("failed to compare branches: %s", err)
s.pages.Notice(w, "resubmit-error", err.Error())
+
sourceRev := comparison.Rev2
+
patch := comparison.Patch
if err = validateResubmittedPatch(pull, patch); err != nil {
s.pages.Notice(w, "resubmit-error", err.Error())
···
return fmt.Errorf("Patch is identical to previous submission.")
+
if patchutil.IsPatchValid(patch) {
return fmt.Errorf("Invalid patch format. Please provide a valid diff.")
···
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))