Skip to content

Commit 4c2441b

Browse files
GiteaBotlunny
andauthored
Fix ghost user in feeds when pushing in an actions, it should be gitea-actions (go-gitea#34703) (go-gitea#34756)
Backport go-gitea#34703 by @lunny Fix go-gitea#34688 This PR will store the `publisher_id` of `release`(tag) table as pusher's id. It could be a real userID or a system user id. If the user is deleted, ghost will be replaced. This PR will also correct the wrong user `Ghost` in the feeds and wrong committer on tag list page if pushing a tag from an actions. Now the behavior is the same as Github. Some codes are deleted because it tries to get commit author as pusher which is not right. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 6f5f0be commit 4c2441b

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
lines changed

models/activities/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (a *Action) LoadActUser(ctx context.Context) {
191191
return
192192
}
193193
var err error
194-
a.ActUser, err = user_model.GetUserByID(ctx, a.ActUserID)
194+
a.ActUser, err = user_model.GetPossibleUserByID(ctx, a.ActUserID)
195195
if err == nil {
196196
return
197197
} else if user_model.IsErrUserNotExist(err) {

routers/web/repo/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func getReleaseInfos(ctx *context.Context, opts *repo_model.FindReleasesOptions)
103103
releaseInfos := make([]*ReleaseInfo, 0, len(releases))
104104
for _, r := range releases {
105105
if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok {
106-
r.Publisher, err = user_model.GetUserByID(ctx, r.PublisherID)
106+
r.Publisher, err = user_model.GetPossibleUserByID(ctx, r.PublisherID)
107107
if err != nil {
108108
if user_model.IsErrUserNotExist(err) {
109109
r.Publisher = user_model.NewGhostUser()

services/repository/push.go

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
232232
}
233233

234234
if len(addTags)+len(delTags) > 0 {
235-
if err := PushUpdateAddDeleteTags(ctx, repo, gitRepo, addTags, delTags); err != nil {
235+
if err := PushUpdateAddDeleteTags(ctx, repo, gitRepo, pusher, addTags, delTags); err != nil {
236236
return fmt.Errorf("PushUpdateAddDeleteTags: %w", err)
237237
}
238238
}
@@ -342,17 +342,17 @@ func pushDeleteBranch(ctx context.Context, repo *repo_model.Repository, pusher *
342342
}
343343

344344
// PushUpdateAddDeleteTags updates a number of added and delete tags
345-
func PushUpdateAddDeleteTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, addTags, delTags []string) error {
345+
func PushUpdateAddDeleteTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pusher *user_model.User, addTags, delTags []string) error {
346346
return db.WithTx(ctx, func(ctx context.Context) error {
347347
if err := repo_model.PushUpdateDeleteTags(ctx, repo, delTags); err != nil {
348348
return err
349349
}
350-
return pushUpdateAddTags(ctx, repo, gitRepo, addTags)
350+
return pushUpdateAddTags(ctx, repo, gitRepo, pusher, addTags)
351351
})
352352
}
353353

354354
// pushUpdateAddTags updates a number of add tags
355-
func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, tags []string) error {
355+
func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pusher *user_model.User, tags []string) error {
356356
if len(tags) == 0 {
357357
return nil
358358
}
@@ -378,8 +378,6 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
378378

379379
newReleases := make([]*repo_model.Release, 0, len(lowerTags)-len(relMap))
380380

381-
emailToUser := make(map[string]*user_model.User)
382-
383381
for i, lowerTag := range lowerTags {
384382
tag, err := gitRepo.GetTag(tags[i])
385383
if err != nil {
@@ -397,21 +395,9 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
397395
if sig == nil {
398396
sig = commit.Committer
399397
}
400-
var author *user_model.User
401-
createdAt := time.Unix(1, 0)
402398

399+
createdAt := time.Unix(1, 0)
403400
if sig != nil {
404-
var ok bool
405-
author, ok = emailToUser[sig.Email]
406-
if !ok {
407-
author, err = user_model.GetUserByEmail(ctx, sig.Email)
408-
if err != nil && !user_model.IsErrUserNotExist(err) {
409-
return fmt.Errorf("GetUserByEmail: %w", err)
410-
}
411-
if author != nil {
412-
emailToUser[sig.Email] = author
413-
}
414-
}
415401
createdAt = sig.When
416402
}
417403

@@ -435,11 +421,9 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
435421
IsDraft: false,
436422
IsPrerelease: false,
437423
IsTag: true,
424+
PublisherID: pusher.ID,
438425
CreatedUnix: timeutil.TimeStamp(createdAt.Unix()),
439426
}
440-
if author != nil {
441-
rel.PublisherID = author.ID
442-
}
443427

444428
newReleases = append(newReleases, rel)
445429
} else {
@@ -448,12 +432,10 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
448432
if rel.IsTag {
449433
rel.Title = parts[0]
450434
rel.Note = note
451-
if author != nil {
452-
rel.PublisherID = author.ID
453-
}
454435
} else {
455436
rel.IsDraft = false
456437
}
438+
rel.PublisherID = pusher.ID
457439
if err = repo_model.UpdateRelease(ctx, rel); err != nil {
458440
return fmt.Errorf("Update: %w", err)
459441
}

templates/repo/release/list.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
{{svg (MigrationIcon $release.Repo.GetOriginalURLHostname) 20 "tw-mr-1"}}{{$release.OriginalAuthor}}
5151
{{else if $release.Publisher}}
5252
{{ctx.AvatarUtils.Avatar $release.Publisher 20 "tw-mr-1"}}
53-
<a href="{{$release.Publisher.HomeLink}}">{{$release.Publisher.GetDisplayName}}</a>
53+
{{if gt $release.PublisherID 0}}
54+
<a href="{{$release.Publisher.HomeLink}}">{{$release.Publisher.GetDisplayName}}</a>
55+
{{else}}
56+
{{$release.Publisher.GetDisplayName}}
57+
{{end}}
5458
{{else}}
5559
Ghost
5660
{{end}}

0 commit comments

Comments
 (0)