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