Skip to content

[WIP] Try to fix issue-dashboard + some refactor usw. #9236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ type IssueStats struct {
// Filter modes.
const (
FilterModeAll = iota
FilterModeOwn
FilterModeAssign
FilterModeCreate
FilterModeMention
Expand Down
18 changes: 18 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,24 @@ func GetUserRepositories(userID int64, private bool, page, pageSize int, orderBy
return repos, sess.Find(&repos)
}

// GetUserRepositoryIDs return int64 list if all repos a user/org has
func GetUserRepositoryIDs(userID int64) (repoIDs []int64, err error){
sess := x.NewSession()
defer sess.Close()

idSlice := make([]*struct {
RepoID int64
}, 0, 10)
if err := sess.Table("repository").And("owner_id=?", userID).Find(&idSlice); err != nil {
return nil, err
}

for _, c := range idSlice {
repoIDs = append(repoIDs, c.RepoID)
}
return
}

// GetUserMirrorRepositories returns a list of mirror repositories of given user.
func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
repos := make([]*Repository, 0, 10)
Expand Down
51 changes: 34 additions & 17 deletions routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ func Issues(ctx *context.Context) {
} else {
viewType = ctx.Query("type")
switch viewType {
case "your_repositories":
filterMode = models.FilterModeOwn
case "assigned":
filterMode = models.FilterModeAssign
case "created_by":
Expand Down Expand Up @@ -220,21 +222,18 @@ func Issues(ctx *context.Context) {

isShowClosed := ctx.Query("state") == "closed"

// Get repositories.
var err error
var userRepoIDs []int64
var userRepoIDs []int64 // TO REMOVE
var err error // TO REMOVE

// Get repository id's for FilterModeAll and FilterModeOwn
var ownRepoIDs []int64
var allRepoIDs []int64
if ctxUser.IsOrganization() {
env, err := ctxUser.AccessibleReposEnv(ctx.User.ID)
if err != nil {
ctx.ServerError("AccessibleReposEnv", err)
return
}
userRepoIDs, err = env.RepoIDs(1, ctxUser.NumRepos)
if err != nil {
ctx.ServerError("env.RepoIDs", err)
return
}
ownRepoIDs, _ := models.GetUserRepositoryIDs(ctxUser.ID)
fmt.Println("BBBBBBBBBBs: ", ownRepoIDs)
allRepoIDs = ownRepoIDs
} else {
/*
unitType := models.UnitTypeIssues
if isPullList {
unitType = models.UnitTypePullRequests
Expand All @@ -244,9 +243,16 @@ func Issues(ctx *context.Context) {
ctx.ServerError("ctxUser.GetAccessRepoIDs", err)
return
}
}
if len(userRepoIDs) == 0 {
userRepoIDs = []int64{-1}
*/
ownRepoIDs, _ := models.GetUserRepositoryIDs(ctxUser.ID)

unitType := models.UnitTypeIssues
if isPullList {
unitType = models.UnitTypePullRequests
}

allRepoIDs, err = ctxUser.GetAccessRepoIDs(unitType)
fmt.Println("BBBBBBBBBBs: ", ownRepoIDs) // thats how i degugg at runtime for now (not the best wax i know ...)
}

opts := &models.IssuesOptions{
Expand All @@ -257,7 +263,17 @@ func Issues(ctx *context.Context) {

switch filterMode {
case models.FilterModeAll:
opts.RepoIDs = userRepoIDs
if len(allRepoIDs) == 0 {
opts.RepoIDs = []int64{-1}
} else {
opts.RepoIDs = allRepoIDs
}
case models.FilterModeOwn:
if len(ownRepoIDs) == 0 {
opts.RepoIDs = []int64{-1}
} else {
opts.RepoIDs = ownRepoIDs
}
case models.FilterModeAssign:
opts.AssigneeID = ctxUser.ID
case models.FilterModeCreate:
Expand All @@ -266,6 +282,7 @@ func Issues(ctx *context.Context) {
opts.MentionedID = ctxUser.ID
}

fmt.Println("AAAAAAAAAAAAAAAAAAAAa: ", opts.RepoIDs) // thats how i degugg at runtime for now (not the best wax i know ...)
counts, err := models.CountIssuesByRepo(opts)
if err != nil {
ctx.ServerError("CountIssuesByRepo", err)
Expand Down