Skip to content

Commit 19221f0

Browse files
committed
Refac user.Issues(): add func repoIDs
1 parent c2f7acc commit 19221f0

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

routers/user/home.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -392,26 +392,7 @@ func Issues(ctx *context.Context) {
392392
}
393393

394394
// Parse ctx.Query("repos") -- gets set when clicking filters -- and remember matched repo IDs for later.
395-
reposQuery := ctx.Query("repos")
396-
var repoIDs []int64
397-
if len(reposQuery) != 0 {
398-
if issueReposQueryPattern.MatchString(reposQuery) {
399-
// remove "[" and "]" from string
400-
reposQuery = reposQuery[1 : len(reposQuery)-1]
401-
//for each ID (delimiter ",") add to int to repoIDs
402-
for _, rID := range strings.Split(reposQuery, ",") {
403-
// Ensure nonempty string entries
404-
if rID != "" && rID != "0" {
405-
rIDint64, err := strconv.ParseInt(rID, 10, 64)
406-
if err == nil {
407-
repoIDs = append(repoIDs, rIDint64)
408-
}
409-
}
410-
}
411-
} else {
412-
log.Warn("issueReposQueryPattern not match with query")
413-
}
414-
}
395+
repoIDs := repoIDs(ctx.Query("repos"))
415396

416397
// No idea what this means.
417398
isShowClosed := ctx.Query("state") == "closed"
@@ -719,6 +700,29 @@ func Issues(ctx *context.Context) {
719700
ctx.HTML(200, tplIssues)
720701
}
721702

703+
func repoIDs(reposQuery string) []int64 {
704+
var repoIDs []int64
705+
if len(reposQuery) != 0 {
706+
if issueReposQueryPattern.MatchString(reposQuery) {
707+
// remove "[" and "]" from string
708+
reposQuery = reposQuery[1 : len(reposQuery)-1]
709+
//for each ID (delimiter ",") add to int to repoIDs
710+
for _, rID := range strings.Split(reposQuery, ",") {
711+
// Ensure nonempty string entries
712+
if rID != "" && rID != "0" {
713+
rIDint64, err := strconv.ParseInt(rID, 10, 64)
714+
if err == nil {
715+
repoIDs = append(repoIDs, rIDint64)
716+
}
717+
}
718+
}
719+
} else {
720+
log.Warn("issueReposQueryPattern not match with query")
721+
}
722+
}
723+
return repoIDs
724+
}
725+
722726
// ShowSSHKeys output all the ssh keys of user by uid
723727
func ShowSSHKeys(ctx *context.Context, uid int64) {
724728
keys, err := models.ListPublicKeys(uid, models.ListOptions{})

0 commit comments

Comments
 (0)