fix resubmitting a patch #37

closed
opened by dvjn.dev targeting master

add patch conditions in resubmit logic

Changed files
+24 -19
appview
state
+24 -19
appview/state/pull.go
··· 1021 1021 1022 1022 var ownerDid, repoName, knotName string 1023 1023 var isSameRepo bool = pull.IsSameRepoBranch() 1024 - sourceBranch := pull.PullSource.Branch 1024 + var isPatch bool = pull.IsPatch() 1025 + 1025 1026 targetBranch := pull.TargetBranch 1026 - recordPullSource = &tangled.RepoPull_Source{ 1027 - Branch: sourceBranch, 1028 - } 1027 + sourceBranch := "" 1028 + if !isPatch { 1029 + sourceBranch = pull.PullSource.Branch 1030 + recordPullSource = &tangled.RepoPull_Source{ 1031 + Branch: sourceBranch, 1032 + } 1029 1033 1030 - isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed() 1031 - if isSameRepo && isPushAllowed { 1032 - ownerDid = f.OwnerDid() 1033 - repoName = f.RepoName 1034 - knotName = f.Knot 1035 - } else if !isSameRepo { 1036 - sourceRepo, err := db.GetRepoByAtUri(s.db, pull.PullSource.RepoAt.String()) 1037 - if err != nil { 1038 - log.Println("failed to get source repo", err) 1039 - s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 1040 - return 1034 + isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed() 1035 + if isSameRepo && isPushAllowed { 1036 + ownerDid = f.OwnerDid() 1037 + repoName = f.RepoName 1038 + knotName = f.Knot 1039 + } else if !isSameRepo && !isPatch { 1040 + sourceRepo, err := db.GetRepoByAtUri(s.db, pull.PullSource.RepoAt.String()) 1041 + if err != nil { 1042 + log.Println("failed to get source repo", err) 1043 + s.pages.Notice(w, "pull", "Failed to create pull request. Try again later.") 1044 + return 1045 + } 1046 + ownerDid = sourceRepo.Did 1047 + repoName = sourceRepo.Name 1048 + knotName = sourceRepo.Knot 1041 1049 } 1042 - ownerDid = sourceRepo.Did 1043 - repoName = sourceRepo.Name 1044 - knotName = sourceRepo.Knot 1045 1050 } 1046 1051 1047 1052 if sourceBranch != "" && knotName != "" { ··· 1126 1131 return 1127 1132 } 1128 1133 1129 - if sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev { 1134 + if !isPatch && sourceRev == pull.Submissions[pull.LastRoundNumber()].SourceRev { 1130 1135 s.pages.Notice(w, "resubmit-error", "This branch has not changed since the last submission.") 1131 1136 return 1132 1137 }