Skip to content

Commit

Permalink
first working example if ...
Browse files Browse the repository at this point in the history
you replace "ctx.Data["Authors"], err = repo.GetIssueAuthors()" with
"ctx.Data["Authors"], err = repo.GetAssignees()"
  • Loading branch information
6543 committed Feb 13, 2020
1 parent c9639e1 commit c0f82bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
21 changes: 12 additions & 9 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,22 +616,25 @@ func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
return users, nil
}

func (repo *Repository) getIssueAuthors(e Engine) (authors []*User, err error) {
err = e.Where("issue.repo_id = ?", repo.ID).
Join("LEFT", "user", "user.id = issue.poster_id").OrderBy("user.id").
GroupBy("user.id").Select("user.id, user.name, user.full_name").Find(authors)

return
func (repo *Repository) getIssueAuthors(e Engine, lim int, keyword string) (authors []*User, err error) {
var authorIDs []int64
if err = e.SQL("SELECT user.id FROM issue,user WHERE user.id = issue.poster_id AND issue.repo_id = ? AND user.name LIKE '%"+keyword+"%' GROUP BY user.id ORDER BY user.id", repo.ID).
Limit(lim, 0).Find(&authorIDs); err != nil {
return nil, err
}
return GetUsersByIDs(authorIDs)
}

// GetAssignees returns all users that have write access and can be assigned to issues
// of the repository,
func (repo *Repository) GetAssignees() (_ []*User, err error) {
func (repo *Repository) GetAssignees() ([]*User, error) {
return repo.getAssignees(x)
}

func (repo *Repository) GetIssueAuthors() (_ []*User, err error) {
return repo.getIssueAuthors(x)
// GetIssueAuthors return the first 15 users who have created an issue in this repo
// the users can be specified by a keyword
func (repo *Repository) GetIssueAuthors(keyword string) ([]*User, error) {
return repo.getIssueAuthors(x, 15, keyword)
}

// GetMilestoneByID returns the milestone belongs to repository by given ID.
Expand Down
11 changes: 10 additions & 1 deletion routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB

var (
assigneeID = ctx.QueryInt64("assignee")
posterID int64
posterID = ctx.QueryInt64("author")
authorID = posterID
mentionedID int64
forceEmpty bool
)
Expand Down Expand Up @@ -248,6 +249,13 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
return
}

// Get issue authors
ctx.Data["Authors"], err = repo.GetIssueAuthors("")
if err != nil {
ctx.ServerError("GetIssueAuthors", err)
return
}

labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
Expand All @@ -270,6 +278,7 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
ctx.Data["SortType"] = sortType
ctx.Data["MilestoneID"] = milestoneID
ctx.Data["AssigneeID"] = assigneeID
ctx.Data["AuthorID"] = authorID
ctx.Data["IsShowClosed"] = isShowClosed
ctx.Data["Keyword"] = keyword
if isShowClosed {
Expand Down

0 comments on commit c0f82bc

Please sign in to comment.