Skip to content

Commit 6a31b74

Browse files
committed
use HasMergedPullRequestInRepo
1 parent 503701c commit 6a31b74

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

models/issues/pull_list.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,15 @@ func (prs PullRequestList) GetIssueIDs() []int64 {
200200
return issueIDs
201201
}
202202

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) {
203+
// HasMergedPullRequestInRepo returns whether the user(poster) has merged pull-request in the repo
204+
func HasMergedPullRequestInRepo(ctx context.Context, repoID, posterID int64) (bool, error) {
205205
return db.GetEngine(ctx).
206-
Join("INNER", "pull", "pull.issue_id = issue.id").
206+
Join("INNER", "pull_request", "pull_request.issue_id = issue.id").
207207
Where("repo_id=?", repoID).
208208
And("poster_id=?", posterID).
209209
And("is_pull=?", true).
210-
And("pull.has_merged=?", true).
211-
Count(new(Issue))
210+
And("pull_request.has_merged=?", true).
211+
Select("issue.id").
212+
Limit(1).
213+
Get(new(Issue))
212214
}

routers/web/repo/issue.go

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

1287-
total, err := issues_model.CountMergedPullRequestInRepo(ctx, repo.ID, poster.ID)
1287+
hasMergedPR, err := issues_model.HasMergedPullRequestInRepo(ctx, repo.ID, poster.ID)
12881288
if err != nil {
12891289
return roleDescriptor, err
1290-
} else if total > 0 {
1290+
} else if hasMergedPR {
12911291
roleDescriptor.RoleInRepo = issues_model.RoleRepoContributor
1292-
} else if total == 0 {
1292+
} else {
12931293
// only display first time contributor in the first opening pull request
12941294
roleDescriptor.RoleInRepo = issues_model.RoleRepoFirstTimeContributor
12951295
}

0 commit comments

Comments
 (0)