Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/pulls: combine patch, pull and interdiff views

all 3 pages are presented in one page now.

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

authored by

oppiliappan and committed by tangled.org a83ffa10 9574058b

+51 -100
+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 { ··· 166 166 log.Println("failed to get pull backlinks", err) 167 167 s.pages.Notice(w, "pull-error", "Failed to get pull. Try again later.") 168 168 return 169 + } 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 169 185 } 170 186 171 187 // can be nil if this pull is not stacked ··· 252 236 defs[l.AtUri().String()] = &l 253 237 } 254 238 255 - patch := pull.LatestSubmission().CombinedPatch() 256 - diff := patchutil.AsNiceDiff(patch, pull.TargetBranch) 257 - var diffOpts types.DiffOpts 258 - if d := r.URL.Query().Get("diff"); d == "split" { 259 - diffOpts.Split = true 239 + patch := pull.Submissions[roundIdInt].CombinedPatch() 240 + var diff types.DiffRenderer 241 + diff = patchutil.AsNiceDiff(patch, pull.TargetBranch) 242 + 243 + if interdiff { 244 + currentPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt].CombinedPatch()) 245 + if err != nil { 246 + log.Println("failed to interdiff; current patch malformed") 247 + s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; current patch is invalid.") 248 + return 249 + } 250 + 251 + previousPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt-1].CombinedPatch()) 252 + if err != nil { 253 + log.Println("failed to interdiff; previous patch malformed") 254 + s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; previous patch is invalid.") 255 + return 256 + } 257 + 258 + diff = patchutil.Interdiff(previousPatch, currentPatch) 260 259 } 261 260 262 - log.Println(s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{ 261 + s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{ 263 262 LoggedInUser: user, 264 263 RepoInfo: s.repoResolver.GetRepoInfo(r, user), 265 264 Pull: pull, ··· 285 254 MergeCheck: mergeCheckResponse, 286 255 ResubmitCheck: resubmitResult, 287 256 Pipelines: m, 288 - Diff: &diff, 257 + Diff: diff, 289 258 DiffOpts: diffOpts, 259 + ActiveRound: roundIdInt, 260 + IsInterdiff: interdiff, 290 261 291 262 OrderedReactionKinds: models.OrderedReactionKinds, 292 263 Reactions: reactionMap, 293 264 UserReacted: userReactions, 294 265 295 266 LabelDefs: defs, 296 - })) 267 + }) 268 + } 269 + 270 + func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { 271 + s.repoPullHelper(w, r, false) 297 272 } 298 273 299 274 func (s *Pulls) mergeCheck(r *http.Request, f *models.Repo, pull *models.Pull, stack models.Stack) types.MergeCheckResponse { ··· 484 447 } 485 448 486 449 func (s *Pulls) RepoPullPatch(w http.ResponseWriter, r *http.Request) { 487 - user := s.oauth.GetMultiAccountUser(r) 488 - 489 - var diffOpts types.DiffOpts 490 - if d := r.URL.Query().Get("diff"); d == "split" { 491 - diffOpts.Split = true 492 - } 493 - 494 - pull, ok := r.Context().Value("pull").(*models.Pull) 495 - if !ok { 496 - log.Println("failed to get pull") 497 - s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.") 498 - return 499 - } 500 - 501 - stack, _ := r.Context().Value("stack").(models.Stack) 502 - 503 - roundId := chi.URLParam(r, "round") 504 - roundIdInt, err := strconv.Atoi(roundId) 505 - if err != nil || roundIdInt >= len(pull.Submissions) { 506 - http.Error(w, "bad round id", http.StatusBadRequest) 507 - log.Println("failed to parse round id", err) 508 - return 509 - } 510 - 511 - patch := pull.Submissions[roundIdInt].CombinedPatch() 512 - diff := patchutil.AsNiceDiff(patch, pull.TargetBranch) 513 - 514 - s.pages.RepoPullPatchPage(w, pages.RepoPullPatchParams{ 515 - LoggedInUser: user, 516 - RepoInfo: s.repoResolver.GetRepoInfo(r, user), 517 - Pull: pull, 518 - Stack: stack, 519 - Round: roundIdInt, 520 - Submission: pull.Submissions[roundIdInt], 521 - Diff: &diff, 522 - DiffOpts: diffOpts, 523 - }) 524 - 450 + s.repoPullHelper(w, r, false) 525 451 } 526 452 527 453 func (s *Pulls) RepoPullInterdiff(w http.ResponseWriter, r *http.Request) { 528 - user := s.oauth.GetMultiAccountUser(r) 529 - 530 - var diffOpts types.DiffOpts 531 - if d := r.URL.Query().Get("diff"); d == "split" { 532 - diffOpts.Split = true 533 - } 534 - 535 - pull, ok := r.Context().Value("pull").(*models.Pull) 536 - if !ok { 537 - log.Println("failed to get pull") 538 - s.pages.Notice(w, "pull-error", "Failed to get pull.") 539 - return 540 - } 541 - 542 - roundId := chi.URLParam(r, "round") 543 - roundIdInt, err := strconv.Atoi(roundId) 544 - if err != nil || roundIdInt >= len(pull.Submissions) { 545 - http.Error(w, "bad round id", http.StatusBadRequest) 546 - log.Println("failed to parse round id", err) 547 - return 548 - } 549 - 550 - if roundIdInt == 0 { 551 - http.Error(w, "bad round id", http.StatusBadRequest) 552 - log.Println("cannot interdiff initial submission") 553 - return 554 - } 555 - 556 - currentPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt].CombinedPatch()) 557 - if err != nil { 558 - log.Println("failed to interdiff; current patch malformed") 559 - s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; current patch is invalid.") 560 - return 561 - } 562 - 563 - previousPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt-1].CombinedPatch()) 564 - if err != nil { 565 - log.Println("failed to interdiff; previous patch malformed") 566 - s.pages.Notice(w, fmt.Sprintf("interdiff-error-%d", roundIdInt), "Failed to calculate interdiff; previous patch is invalid.") 567 - return 568 - } 569 - 570 - interdiff := patchutil.Interdiff(previousPatch, currentPatch) 571 - 572 - s.pages.RepoPullInterdiffPage(w, pages.RepoPullInterdiffParams{ 573 - LoggedInUser: s.oauth.GetMultiAccountUser(r), 574 - RepoInfo: s.repoResolver.GetRepoInfo(r, user), 575 - Pull: pull, 576 - Round: roundIdInt, 577 - Interdiff: interdiff, 578 - DiffOpts: diffOpts, 579 - }) 454 + s.repoPullHelper(w, r, true) 580 455 } 581 456 582 457 func (s *Pulls) RepoPullPatchRaw(w http.ResponseWriter, r *http.Request) {