Skip to content

Commit 04d89a0

Browse files
committed
change the logic of
detecting first time contributor
1 parent 40335f1 commit 04d89a0

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

modules/git/commit.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,10 @@ func (c *Commit) CommitsBeforeUntil(commitID string) ([]*Commit, error) {
258258

259259
// SearchCommitsOptions specify the parameters for SearchCommits
260260
type SearchCommitsOptions struct {
261-
CommitID SHA1
262261
Keywords []string
263262
Authors, Committers []string
264263
After, Before string
265264
All bool
266-
Limit int
267265
}
268266

269267
// NewSearchCommitsOptions construct a SearchCommitsOption from a space-delimited search string
@@ -299,8 +297,7 @@ func NewSearchCommitsOptions(searchString string, forAllRefs bool) SearchCommits
299297

300298
// SearchCommits returns the commits match the keyword before current revision
301299
func (c *Commit) SearchCommits(opts SearchCommitsOptions) ([]*Commit, error) {
302-
opts.CommitID = c.ID
303-
return c.repo.SearchCommits(opts)
300+
return c.repo.searchCommits(c.ID, opts)
304301
}
305302

306303
// GetFilesChangedSinceCommit get all changed file names between pastCommit to current revision

modules/git/repo_commit.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (repo *Repository) commitsByRange(id SHA1, page, pageSize int, not string)
109109
return repo.parsePrettyFormatLogToList(stdout)
110110
}
111111

112-
func (repo *Repository) SearchCommits(opts SearchCommitsOptions) ([]*Commit, error) {
112+
func (repo *Repository) searchCommits(id SHA1, opts SearchCommitsOptions) ([]*Commit, error) {
113113
// add common arguments to git command
114114
addCommonSearchArgs := func(c *Command) {
115115
// ignore case
@@ -138,19 +138,8 @@ func (repo *Repository) SearchCommits(opts SearchCommitsOptions) ([]*Commit, err
138138
}
139139
}
140140

141-
// create new git log command
142-
cmd := NewCommand(repo.Ctx, "log")
143-
144-
// By default, limit 100 commits
145-
limit := 100
146-
if opts.Limit > 0 {
147-
limit = opts.Limit
148-
}
149-
cmd = cmd.AddOptionFormat("-%d", limit).AddArguments(prettyLogFormat)
150-
151-
if !opts.CommitID.IsZero() {
152-
cmd = cmd.AddDynamicArguments(opts.CommitID.String())
153-
}
141+
// create new git log command with limit of 100 commits
142+
cmd := NewCommand(repo.Ctx, "log", "-100", prettyLogFormat).AddDynamicArguments(id.String())
154143

155144
// pretend that all refs along with HEAD were listed on command line as <commis>
156145
// https://git-scm.com/docs/git-log#Documentation/git-log.txt---all

routers/web/repo/issue.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ func NewIssuePost(ctx *context.Context) {
12291229
}
12301230

12311231
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
1232-
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue, gitRepo *git.Repository, hasOriginalAuthor bool) (issues_model.RoleDescriptor, error) {
1232+
func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue, hasOriginalAuthor bool) (issues_model.RoleDescriptor, error) {
12331233
if hasOriginalAuthor {
12341234
return issues_model.RoleDescriptorNone, nil
12351235
}
@@ -1287,15 +1287,21 @@ func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *use
12871287
return roleDescriptor, nil
12881288
}
12891289

1290-
if commits, err := gitRepo.SearchCommits(git.SearchCommitsOptions{
1291-
Authors: []string{poster.Name},
1292-
All: true,
1293-
Limit: 2,
1294-
}); err != nil {
1290+
// If the poster is the contributor of the repo
1291+
searchOpt := &issue_indexer.SearchOptions{
1292+
Paginator: &db.ListOptions{
1293+
Page: 1,
1294+
PageSize: 2,
1295+
},
1296+
RepoIDs: []int64{repo.ID},
1297+
IsPull: util.OptionalBoolTrue,
1298+
PosterID: &poster.ID,
1299+
}
1300+
if _, total, err := issue_indexer.SearchIssues(ctx, searchOpt); err != nil {
12951301
return issues_model.RoleDescriptorNone, err
1296-
} else if len(commits) == 1 {
1302+
} else if total == 1 {
12971303
roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorFirstTimeContributor)
1298-
} else if len(commits) > 1 {
1304+
} else if total > 1 {
12991305
roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorContributor)
13001306
}
13011307

@@ -1554,7 +1560,7 @@ func ViewIssue(ctx *context.Context) {
15541560
// check if dependencies can be created across repositories
15551561
ctx.Data["AllowCrossRepositoryDependencies"] = setting.Service.AllowCrossRepositoryDependencies
15561562

1557-
if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue, ctx.Repo.GitRepo, issue.HasOriginalAuthor()); err != nil {
1563+
if issue.ShowRole, err = roleDescriptor(ctx, repo, issue.Poster, issue, issue.HasOriginalAuthor()); err != nil {
15581564
ctx.ServerError("roleDescriptor", err)
15591565
return
15601566
}
@@ -1593,7 +1599,7 @@ func ViewIssue(ctx *context.Context) {
15931599
continue
15941600
}
15951601

1596-
comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue, ctx.Repo.GitRepo, comment.HasOriginalAuthor())
1602+
comment.ShowRole, err = roleDescriptor(ctx, repo, comment.Poster, issue, comment.HasOriginalAuthor())
15971603
if err != nil {
15981604
ctx.ServerError("roleDescriptor", err)
15991605
return
@@ -1692,7 +1698,7 @@ func ViewIssue(ctx *context.Context) {
16921698
continue
16931699
}
16941700

1695-
c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue, ctx.Repo.GitRepo, c.HasOriginalAuthor())
1701+
c.ShowRole, err = roleDescriptor(ctx, repo, c.Poster, issue, c.HasOriginalAuthor())
16961702
if err != nil {
16971703
ctx.ServerError("roleDescriptor", err)
16981704
return

0 commit comments

Comments
 (0)