Skip to content

Commit

Permalink
use HasMergedPullRequestInRepo
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Aug 23, 2023
1 parent 503701c commit 6a31b74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions models/issues/pull_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,15 @@ func (prs PullRequestList) GetIssueIDs() []int64 {
return issueIDs
}

// CountMergedPullRequestInRepo return the count the user merged into the repository via pull request
func CountMergedPullRequestInRepo(ctx context.Context, repoID, posterID int64) (int64, error) {
// HasMergedPullRequestInRepo returns whether the user(poster) has merged pull-request in the repo
func HasMergedPullRequestInRepo(ctx context.Context, repoID, posterID int64) (bool, error) {
return db.GetEngine(ctx).
Join("INNER", "pull", "pull.issue_id = issue.id").
Join("INNER", "pull_request", "pull_request.issue_id = issue.id").
Where("repo_id=?", repoID).
And("poster_id=?", posterID).
And("is_pull=?", true).
And("pull.has_merged=?", true).
Count(new(Issue))
And("pull_request.has_merged=?", true).
Select("issue.id").
Limit(1).
Get(new(Issue))
}
6 changes: 3 additions & 3 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,12 +1284,12 @@ func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *use
return roleDescriptor, nil
}

total, err := issues_model.CountMergedPullRequestInRepo(ctx, repo.ID, poster.ID)
hasMergedPR, err := issues_model.HasMergedPullRequestInRepo(ctx, repo.ID, poster.ID)
if err != nil {
return roleDescriptor, err
} else if total > 0 {
} else if hasMergedPR {
roleDescriptor.RoleInRepo = issues_model.RoleRepoContributor
} else if total == 0 {
} else {
// only display first time contributor in the first opening pull request
roleDescriptor.RoleInRepo = issues_model.RoleRepoFirstTimeContributor
}
Expand Down

0 comments on commit 6a31b74

Please sign in to comment.