Repository: go-gitea/gitea
File: services/repository/push.go (Go)

Code before:
			if pusher == nil || pusher.ID != opts.PusherID {
				if opts.PusherID == user_model.ActionsUserID {
					pusher = user_model.NewActionsUser()
				} else {
					var err error
					if pusher, err = user_model.GetUserByID(ctx, opts.PusherID); err != nil {
						return err
					}
				}
			}
			tagName := opts.RefFullName.TagName()
			if opts.IsDelRef() {
				notify_service.PushCommits(
					ctx, pusher, repo,
					&repo_module.PushUpdateOptions{
						RefFullName: git.RefNameFromTag(tagName),
						OldCommitID: opts.OldCommitID,
						NewCommitID: objectFormat.EmptyObjectID().String(),
					}, repo_module.NewPushCommits())

				delTags = append(delTags, tagName)
				notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
			} else { // is new tag
				newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
				if err != nil {
					// in case there is dirty data, for example, the "github.com/git/git" repository has tags points to non-existing commits
					if !errors.Is(err, util.ErrNotExist) {
						log.Error("Unable to get tag commit: gitRepo.GetCommit(%s) in %s/%s[%d]: %v", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
					}
				} else {
					commits := repo_module.NewPushCommits()
					commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
					commits.CompareURL = repo.ComposeCompareURL(objectFormat.EmptyObjectID().String(), opts.NewCommitID)

					notify_service.PushCommits(
						ctx, pusher, repo,
						&repo_module.PushUpdateOptions{
							RefFullName: opts.RefFullName,
							OldCommitID: objectFormat.EmptyObjectID().String(),
							NewCommitID: opts.NewCommitID,
						}, commits)

					addTags = append(addTags, tagName)
					notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
				}
			}
		} else if opts.RefFullName.IsBranch() {
			if pusher == nil || pusher.ID != opts.PusherID {
				if opts.PusherID == user_model.ActionsUserID {
					pusher = user_model.NewActionsUser()
				} else {

Review comment (suggestion):
```suggestion
					// in case there is dirty data, for example, the "github.com/git/git" repository has tags pointing to non-existing commits
```

Code after:
			if pusher == nil || pusher.ID != opts.PusherID {
				if opts.PusherID == user_model.ActionsUserID {
					pusher = user_model.NewActionsUser()
				} else {
					var err error
					if pusher, err = user_model.GetUserByID(ctx, opts.PusherID); err != nil {
						return err
					}
				}
			}
			tagName := opts.RefFullName.TagName()
			if opts.IsDelRef() {
				notify_service.PushCommits(
					ctx, pusher, repo,
					&repo_module.PushUpdateOptions{
						RefFullName: git.RefNameFromTag(tagName),
						OldCommitID: opts.OldCommitID,
						NewCommitID: objectFormat.EmptyObjectID().String(),
					}, repo_module.NewPushCommits())

				delTags = append(delTags, tagName)
				notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
			} else { // is new tag
				newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
				if err != nil {
					// in case there is dirty data, for example, the "github.com/git/git" repository has tags pointing to non-existing commits
					if !errors.Is(err, util.ErrNotExist) {
						log.Error("Unable to get tag commit: gitRepo.GetCommit(%s) in %s/%s[%d]: %v", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
					}
				} else {
					commits := repo_module.NewPushCommits()
					commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
					commits.CompareURL = repo.ComposeCompareURL(objectFormat.EmptyObjectID().String(), opts.NewCommitID)

					notify_service.PushCommits(
						ctx, pusher, repo,
						&repo_module.PushUpdateOptions{
							RefFullName: opts.RefFullName,
							OldCommitID: objectFormat.EmptyObjectID().String(),
							NewCommitID: opts.NewCommitID,
						}, commits)

					addTags = append(addTags, tagName)
					notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
				}
			}
		} else if opts.RefFullName.IsBranch() {
			if pusher == nil || pusher.ID != opts.PusherID {
				if opts.PusherID == user_model.ActionsUserID {
					pusher = user_model.NewActionsUser()
				} else {