Skip to content

Commit 91f207d

Browse files
committed
Add lots of comments to user.Issues()
1 parent e964c6e commit 91f207d

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

routers/user/home.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ var issueReposQueryPattern = regexp.MustCompile(`^\[\d+(,\d+)*,?\]$`)
322322

323323
// Issues render the user issues page
324324
func Issues(ctx *context.Context) {
325+
326+
// Distinguish Issues from Pulls. (Q: Why not make that distinction during routing and call different functions?)
327+
// Return 404 if feature is disabled.
328+
325329
isPullList := ctx.Params(":type") == "pulls"
326330
unitType := models.UnitTypeIssues
327331
if isPullList {
@@ -357,6 +361,13 @@ func Issues(ctx *context.Context) {
357361
filterMode = models.FilterModeAll
358362
)
359363

364+
// Distinguish User from Organization. Q: Again, why not distinguish during routing?
365+
// Org:
366+
// - Remember pre-determined string for later. Will be posted to ctx.Data.
367+
// User:
368+
// - Use ctx.Query("type") to determine filterMode. Q: Can there even be different values in ctx.Query("type")? How?
369+
// - Remember either this or a fallback. Will be posted to ctx.Data.
370+
360371
if ctxUser.IsOrganization() {
361372
viewType = "your_repositories"
362373
} else {
@@ -374,11 +385,14 @@ func Issues(ctx *context.Context) {
374385
}
375386
}
376387

388+
// Make sure page number is at least 1. Will be posted to ctx.Data.
377389
page := ctx.QueryInt("page")
378390
if page <= 1 {
379391
page = 1
380392
}
381393

394+
// Parse ctx.Query("repos") and remember matched repo IDs for later.
395+
// Q: Where can ctx.Query("repos") be filled? With the given routing, where can a value come from?
382396
reposQuery := ctx.Query("repos")
383397
var repoIDs []int64
384398
if len(reposQuery) != 0 {
@@ -400,9 +414,11 @@ func Issues(ctx *context.Context) {
400414
}
401415
}
402416

417+
// No idea what this means.
403418
isShowClosed := ctx.Query("state") == "closed"
404419

405-
// Get repositories.
420+
// Get repository IDs where User/Org has access.
421+
// Again, the distinction between User and Org could perhaps be handled more elegantly.
406422
var err error
407423
var userRepoIDs []int64
408424
if ctxUser.IsOrganization() {
@@ -432,6 +448,8 @@ func Issues(ctx *context.Context) {
432448
userRepoIDs = []int64{-1}
433449
}
434450

451+
// Build IssuesOptions, which contains filter information.
452+
435453
opts := &models.IssuesOptions{
436454
IsPull: util.OptionalBoolOf(isPullList),
437455
SortType: sortType,
@@ -448,7 +466,11 @@ func Issues(ctx *context.Context) {
448466
opts.MentionedID = ctxUser.ID
449467
}
450468

469+
// Execute keyword search for issues.
470+
471+
// Ensure issue list is emtpy if keyword search didn't produce any results.
451472
var forceEmpty bool
473+
// Required for IssuesOptions.
452474
var issueIDsFromSearch []int64
453475
var keyword = strings.Trim(ctx.Query("q"), " ")
454476

@@ -474,6 +496,7 @@ func Issues(ctx *context.Context) {
474496

475497
opts.IsClosed = util.OptionalBoolOf(isShowClosed)
476498

499+
// Filter repos and count issues in them. Count will be used later.
477500
var counts map[int64]int64
478501
if !forceEmpty {
479502
counts, err = models.CountIssuesByRepo(opts)
@@ -485,6 +508,9 @@ func Issues(ctx *context.Context) {
485508

486509
opts.Page = page
487510
opts.PageSize = setting.UI.IssuePagingNum
511+
512+
// Get IDs for labels. Q: What are labels? Where do they come from?
513+
// Required for IssuesOptions.
488514
var labelIDs []int64
489515
selectLabels := ctx.Query("labels")
490516
if len(selectLabels) > 0 && selectLabels != "0" {
@@ -500,6 +526,7 @@ func Issues(ctx *context.Context) {
500526
opts.RepoIDs = repoIDs
501527
}
502528

529+
// Get issues as defined by opts.
503530
var issues []*models.Issue
504531
if !forceEmpty {
505532
issues, err = models.Issues(opts)
@@ -517,6 +544,7 @@ func Issues(ctx *context.Context) {
517544
return
518545
}
519546

547+
// showReposMap maps repository IDs to their Repository pointers.
520548
showReposMap := make(map[int64]*models.Repository, len(counts))
521549
for repoID := range counts {
522550
if repoID > 0 {
@@ -545,13 +573,15 @@ func Issues(ctx *context.Context) {
545573
}
546574
}
547575

576+
// a RepositoryList
548577
showRepos := models.RepositoryListOfMap(showReposMap)
549578
sort.Sort(showRepos)
550579
if err = showRepos.LoadAttributes(); err != nil {
551580
ctx.ServerError("LoadAttributes", err)
552581
return
553582
}
554583

584+
// maps pull request IDs to their CommitStatus. Will be posted to ctx.Data.
555585
var commitStatus = make(map[int64]*models.CommitStatus, len(issues))
556586
for _, issue := range issues {
557587
issue.Repo = showReposMap[issue.RepoID]
@@ -571,12 +601,15 @@ func Issues(ctx *context.Context) {
571601
if len(repoIDs) > 0 {
572602
userIssueStatsOpts.UserRepoIDs = repoIDs
573603
}
604+
605+
// Will be posted to ctx.Data.
574606
userIssueStats, err := models.GetUserIssueStats(userIssueStatsOpts)
575607
if err != nil {
576608
ctx.ServerError("GetUserIssueStats User", err)
577609
return
578610
}
579611

612+
// Will be posted to ctx.Data.
580613
var shownIssueStats *models.IssueStats
581614
if !forceEmpty {
582615
statsOpts := models.UserIssueStatsOptions{
@@ -599,6 +632,7 @@ func Issues(ctx *context.Context) {
599632
shownIssueStats = &models.IssueStats{}
600633
}
601634

635+
// Will be posted to ctx.Data.
602636
var allIssueStats *models.IssueStats
603637
if !forceEmpty {
604638
allIssueStats, err = models.GetUserIssueStats(models.UserIssueStatsOptions{
@@ -617,6 +651,7 @@ func Issues(ctx *context.Context) {
617651
allIssueStats = &models.IssueStats{}
618652
}
619653

654+
// Will be posted to ctx.Data.
620655
var shownIssues int
621656
var totalIssues int
622657
if !isShowClosed {

0 commit comments

Comments
 (0)