Skip to content

Commit c0f82bc

Browse files
committed
first working example if ...
you replace "ctx.Data["Authors"], err = repo.GetIssueAuthors()" with "ctx.Data["Authors"], err = repo.GetAssignees()"
1 parent c9639e1 commit c0f82bc

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

models/repo.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,22 +616,25 @@ func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
616616
return users, nil
617617
}
618618

619-
func (repo *Repository) getIssueAuthors(e Engine) (authors []*User, err error) {
620-
err = e.Where("issue.repo_id = ?", repo.ID).
621-
Join("LEFT", "user", "user.id = issue.poster_id").OrderBy("user.id").
622-
GroupBy("user.id").Select("user.id, user.name, user.full_name").Find(authors)
623-
624-
return
619+
func (repo *Repository) getIssueAuthors(e Engine, lim int, keyword string) (authors []*User, err error) {
620+
var authorIDs []int64
621+
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).
622+
Limit(lim, 0).Find(&authorIDs); err != nil {
623+
return nil, err
624+
}
625+
return GetUsersByIDs(authorIDs)
625626
}
626627

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

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

637640
// GetMilestoneByID returns the milestone belongs to repository by given ID.

routers/repo/issue.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
115115

116116
var (
117117
assigneeID = ctx.QueryInt64("assignee")
118-
posterID int64
118+
posterID = ctx.QueryInt64("author")
119+
authorID = posterID
119120
mentionedID int64
120121
forceEmpty bool
121122
)
@@ -248,6 +249,13 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
248249
return
249250
}
250251

252+
// Get issue authors
253+
ctx.Data["Authors"], err = repo.GetIssueAuthors("")
254+
if err != nil {
255+
ctx.ServerError("GetIssueAuthors", err)
256+
return
257+
}
258+
251259
labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
252260
if err != nil {
253261
ctx.ServerError("GetLabelsByRepoID", err)
@@ -270,6 +278,7 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
270278
ctx.Data["SortType"] = sortType
271279
ctx.Data["MilestoneID"] = milestoneID
272280
ctx.Data["AssigneeID"] = assigneeID
281+
ctx.Data["AuthorID"] = authorID
273282
ctx.Data["IsShowClosed"] = isShowClosed
274283
ctx.Data["Keyword"] = keyword
275284
if isShowClosed {

0 commit comments

Comments
 (0)