Skip to content

Commit 503701c

Browse files
lunnywxiaoguang
authored andcommitted
search database to detect whether the user is first time contributors
1 parent 05c4563 commit 503701c

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

models/issues/pull_list.go

+11
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,14 @@ func (prs PullRequestList) GetIssueIDs() []int64 {
199199
}
200200
return issueIDs
201201
}
202+
203+
// CountMergedPullRequestInRepo return the count the user merged into the repository via pull request
204+
func CountMergedPullRequestInRepo(ctx context.Context, repoID, posterID int64) (int64, error) {
205+
return db.GetEngine(ctx).
206+
Join("INNER", "pull", "pull.issue_id = issue.id").
207+
Where("repo_id=?", repoID).
208+
And("poster_id=?", posterID).
209+
And("is_pull=?", true).
210+
And("pull.has_merged=?", true).
211+
Count(new(Issue))
212+
}

routers/web/repo/issue.go

+3-13
Original file line numberDiff line numberDiff line change
@@ -1284,22 +1284,12 @@ func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *use
12841284
return roleDescriptor, nil
12851285
}
12861286

1287-
// If the poster is the contributor of the repo
1288-
searchOpt := &issue_indexer.SearchOptions{
1289-
Paginator: &db.ListOptions{
1290-
Page: 1,
1291-
PageSize: 1,
1292-
},
1293-
RepoIDs: []int64{repo.ID},
1294-
IsClosed: util.OptionalBoolTrue,
1295-
IsPull: util.OptionalBoolTrue,
1296-
PosterID: &poster.ID,
1297-
}
1298-
if _, total, err := issue_indexer.SearchIssues(ctx, searchOpt); err != nil {
1287+
total, err := issues_model.CountMergedPullRequestInRepo(ctx, repo.ID, poster.ID)
1288+
if err != nil {
12991289
return roleDescriptor, err
13001290
} else if total > 0 {
13011291
roleDescriptor.RoleInRepo = issues_model.RoleRepoContributor
1302-
} else if total == 0 && issue.IsPull && !issue.IsClosed {
1292+
} else if total == 0 {
13031293
// only display first time contributor in the first opening pull request
13041294
roleDescriptor.RoleInRepo = issues_model.RoleRepoFirstTimeContributor
13051295
}

0 commit comments

Comments
 (0)