Monorepo for Tangled tangled.org

appview/pulls: combine patch, pull and interdiff views #972

merged opened by oppi.li targeting master from op/vyrymqtwolsn

all 3 pages are presented in one page now.

Signed-off-by: oppiliappan me@oppi.li

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:qfpnj4og54vl56wngdriaxug/sh.tangled.repo.pull/3mcjiyey6wp22
+51 -100
Diff #0
+3 -1
appview/pages/pages.go
··· 1106 MergeCheck types.MergeCheckResponse 1107 ResubmitCheck ResubmitResult 1108 Pipelines map[string]models.Pipeline 1109 - Diff *types.NiceDiff 1110 DiffOpts types.DiffOpts 1111 1112 OrderedReactionKinds []models.ReactionKind 1113 Reactions map[models.ReactionKind]models.ReactionDisplayData
··· 1106 MergeCheck types.MergeCheckResponse 1107 ResubmitCheck ResubmitResult 1108 Pipelines map[string]models.Pipeline 1109 + Diff types.DiffRenderer 1110 DiffOpts types.DiffOpts 1111 + ActiveRound int 1112 + IsInterdiff bool 1113 1114 OrderedReactionKinds []models.ReactionKind 1115 Reactions map[models.ReactionKind]models.ReactionDisplayData
+48 -99
appview/pulls/pulls.go
··· 145 } 146 } 147 148 - func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { 149 user := s.oauth.GetUser(r) 150 f, err := s.repoResolver.Resolve(r) 151 if err != nil { ··· 167 return 168 } 169 170 // can be nil if this pull is not stacked 171 stack, _ := r.Context().Value("stack").(models.Stack) 172 abandonedPulls, _ := r.Context().Value("abandonedPulls").([]*models.Pull) ··· 235 defs[l.AtUri().String()] = &l 236 } 237 238 - patch := pull.LatestSubmission().CombinedPatch() 239 - diff := patchutil.AsNiceDiff(patch, pull.TargetBranch) 240 - var diffOpts types.DiffOpts 241 - if d := r.URL.Query().Get("diff"); d == "split" { 242 - diffOpts.Split = true 243 } 244 245 - log.Println(s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{ 246 LoggedInUser: user, 247 RepoInfo: s.repoResolver.GetRepoInfo(r, user), 248 Pull: pull, ··· 253 MergeCheck: mergeCheckResponse, 254 ResubmitCheck: resubmitResult, 255 Pipelines: m, 256 - Diff: &diff, 257 DiffOpts: diffOpts, 258 259 OrderedReactionKinds: models.OrderedReactionKinds, 260 Reactions: reactionMap, 261 UserReacted: userReactions, 262 263 LabelDefs: defs, 264 - })) 265 } 266 267 func (s *Pulls) mergeCheck(r *http.Request, f *models.Repo, pull *models.Pull, stack models.Stack) types.MergeCheckResponse { ··· 446 } 447 448 func (s *Pulls) RepoPullPatch(w http.ResponseWriter, r *http.Request) { 449 - user := s.oauth.GetUser(r) 450 - 451 - var diffOpts types.DiffOpts 452 - if d := r.URL.Query().Get("diff"); d == "split" { 453 - diffOpts.Split = true 454 - } 455 - 456 - pull, ok := r.Context().Value("pull").(*models.Pull) 457 - if !ok { 458 - log.Println("failed to get pull") 459 - s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") 460 - return 461 - } 462 - 463 - stack, _ := r.Context().Value("stack").(models.Stack) 464 - 465 - roundId := chi.URLParam(r, "round") 466 - roundIdInt, err := strconv.Atoi(roundId) 467 - if err != nil || roundIdInt >= len(pull.Submissions) { 468 - http.Error(w, "bad round id", http.StatusBadRequest) 469 - log.Println("failed to parse round id", err) 470 - return 471 - } 472 - 473 - patch := pull.Submissions[roundIdInt].CombinedPatch() 474 - diff := patchutil.AsNiceDiff(patch, pull.TargetBranch) 475 - 476 - s.pages.RepoPullPatchPage(w, pages.RepoPullPatchParams{ 477 - LoggedInUser: user, 478 - RepoInfo: s.repoResolver.GetRepoInfo(r, user), 479 - Pull: pull, 480 - Stack: stack, 481 - Round: roundIdInt, 482 - Submission: pull.Submissions[roundIdInt], 483 - Diff: &diff, 484 - DiffOpts: diffOpts, 485 - }) 486 - 487 } 488 489 func (s *Pulls) RepoPullInterdiff(w http.ResponseWriter, r *http.Request) { 490 - user := s.oauth.GetUser(r) 491 - 492 - var diffOpts types.DiffOpts 493 - if d := r.URL.Query().Get("diff"); d == "split" { 494 - diffOpts.Split = true 495 - } 496 - 497 - pull, ok := r.Context().Value("pull").(*models.Pull) 498 - if !ok { 499 - log.Println("failed to get pull") 500 - s.pages.Notice(w, "pull-error", "Failed to get pull.") 501 - return 502 - } 503 - 504 - roundId := chi.URLParam(r, "round") 505 - roundIdInt, err := strconv.Atoi(roundId) 506 - if err != nil || roundIdInt >= len(pull.Submissions) { 507 - http.Error(w, "bad round id", http.StatusBadRequest) 508 - log.Println("failed to parse round id", err) 509 - return 510 - } 511 - 512 - if roundIdInt == 0 { 513 - http.Error(w, "bad round id", http.StatusBadRequest) 514 - log.Println("cannot interdiff initial submission") 515 - return 516 - } 517 - 518 - currentPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt].CombinedPatch()) 519 - if err != nil { 520 - log.Println("failed to interdiff; current patch malformed") 521 - s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; current patch is invalid.") 522 - return 523 - } 524 - 525 - previousPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt-1].CombinedPatch()) 526 - if err != nil { 527 - log.Println("failed to interdiff; previous patch malformed") 528 - s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; previous patch is invalid.") 529 - return 530 - } 531 - 532 - interdiff := patchutil.Interdiff(previousPatch, currentPatch) 533 - 534 - s.pages.RepoPullInterdiffPage(w, pages.RepoPullInterdiffParams{ 535 - LoggedInUser: s.oauth.GetUser(r), 536 - RepoInfo: s.repoResolver.GetRepoInfo(r, user), 537 - Pull: pull, 538 - Round: roundIdInt, 539 - Interdiff: interdiff, 540 - DiffOpts: diffOpts, 541 - }) 542 } 543 544 func (s *Pulls) RepoPullPatchRaw(w http.ResponseWriter, r *http.Request) {
··· 145 } 146 } 147 148 + func (s *Pulls) repoPullHelper(w http.ResponseWriter, r *http.Request, interdiff bool) { 149 user := s.oauth.GetUser(r) 150 f, err := s.repoResolver.Resolve(r) 151 if err != nil { ··· 167 return 168 } 169 170 + roundId := chi.URLParam(r, "round") 171 + roundIdInt := pull.LastRoundNumber() 172 + if r, err := strconv.Atoi(roundId); err == nil { 173 + roundIdInt = r 174 + } 175 + if roundIdInt >= len(pull.Submissions) { 176 + http.Error(w, "bad round id", http.StatusBadRequest) 177 + log.Println("failed to parse round id", err) 178 + return 179 + } 180 + 181 + var diffOpts types.DiffOpts 182 + if d := r.URL.Query().Get("diff"); d == "split" { 183 + diffOpts.Split = true 184 + } 185 + 186 // can be nil if this pull is not stacked 187 stack, _ := r.Context().Value("stack").(models.Stack) 188 abandonedPulls, _ := r.Context().Value("abandonedPulls").([]*models.Pull) ··· 251 defs[l.AtUri().String()] = &l 252 } 253 254 + patch := pull.Submissions[roundIdInt].CombinedPatch() 255 + var diff types.DiffRenderer 256 + diff = patchutil.AsNiceDiff(patch, pull.TargetBranch) 257 + 258 + if interdiff { 259 + currentPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt].CombinedPatch()) 260 + if err != nil { 261 + log.Println("failed to interdiff; current patch malformed") 262 + s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; current patch is invalid.") 263 + return 264 + } 265 + 266 + previousPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt-1].CombinedPatch()) 267 + if err != nil { 268 + log.Println("failed to interdiff; previous patch malformed") 269 + s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; previous patch is invalid.") 270 + return 271 + } 272 + 273 + diff = patchutil.Interdiff(previousPatch, currentPatch) 274 } 275 276 + s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{ 277 LoggedInUser: user, 278 RepoInfo: s.repoResolver.GetRepoInfo(r, user), 279 Pull: pull, ··· 284 MergeCheck: mergeCheckResponse, 285 ResubmitCheck: resubmitResult, 286 Pipelines: m, 287 + Diff: diff, 288 DiffOpts: diffOpts, 289 + ActiveRound: roundIdInt, 290 + IsInterdiff: interdiff, 291 292 OrderedReactionKinds: models.OrderedReactionKinds, 293 Reactions: reactionMap, 294 UserReacted: userReactions, 295 296 LabelDefs: defs, 297 + }) 298 + } 299 + 300 + func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { 301 + s.repoPullHelper(w, r, false) 302 } 303 304 func (s *Pulls) mergeCheck(r *http.Request, f *models.Repo, pull *models.Pull, stack models.Stack) types.MergeCheckResponse { ··· 483 } 484 485 func (s *Pulls) RepoPullPatch(w http.ResponseWriter, r *http.Request) { 486 + s.repoPullHelper(w, r, false) 487 } 488 489 func (s *Pulls) RepoPullInterdiff(w http.ResponseWriter, r *http.Request) { 490 + s.repoPullHelper(w, r, true) 491 } 492 493 func (s *Pulls) RepoPullPatchRaw(w http.ResponseWriter, r *http.Request) {

History

2 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview/pulls: combine patch, pull and interdiff views
3/3 success
expand
expand 0 comments
pull request successfully merged
oppi.li submitted #0
1 commit
expand
appview/pulls: combine patch, pull and interdiff views
3/3 success
expand
expand 0 comments