Skip to content

First commit in history page doesn't have link to user profile #7404

Closed

Description

@Linaro1985

Gogs version

0.13.0

Git version

  • Server: 2.20.1
  • Client: 2.20.1

Operating system

Debian 10

Database

mysql

Describe the bug

First commit on history page (page number doesn't matter) doesn't have link to user profile
commit_history

To reproduce

  1. Create new repository
  2. Make several commits
  3. Open commit history
  4. First commit doesn't have link to user profile

Expected behavior

First commit on history page (page number doesn't matter) have link to user profile

Additional context

Maybe this issue because of:

ed51686
6d22054

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    💊 bug
    on Mar 23, 2023
  2. JerryLiao26 commented on Apr 15, 2023

    @JerryLiao26

    Can confirm it's a bug here

    emailToUsers[oldCommits[i].Author.Email], _ = db.Users.GetByEmail(ctx, oldCommits[i].Author.Email)

    by not giving the value to u
    Should I start a pull request?

  3. njsoftdev commented on Apr 27, 2023

    @njsoftdev

    Same issue and on commits page avatar and profile link doesn't attached to author. But in 0.13.0 all ok.

    It's bug. Regression after upgrade gogs from 0.13.0+dev to 0.14.0+dev.

  4. ivanbogomoloff commented on Sep 18, 2023

    @ivanbogomoloff
    Contributor

    Is it correct solution ?
    I did it, because in my cases it works.

    vi +203 gogs/internal/route/repo/commit.go

    func matchUsersWithCommitEmails(ctx gocontext.Context, oldCommits []*git.Commit) []*userCommit {
            emailToUsers := make(map[string]*db.User)
            newCommits := make([]*userCommit, len(oldCommits))
            for i := range oldCommits {
                    var u *db.User
                    if v, ok := emailToUsers[oldCommits[i].Author.Email]; !ok {
                            u , _ = db.Users.GetByEmail(ctx, oldCommits[i].Author.Email) //<-- Fixed here
                    } else {
                            u = v
                    }
    
                    newCommits[i] = &userCommit{
                            User:   u,
                            Commit: oldCommits[i],
                    }
            }
            return newCommits
    }
  5. athoik commented on Oct 1, 2023

    @athoik
    Contributor

    My guess is that emailToUsers is used as a local cache, to avoid multiple queries to database.
    If it's on emailToUsers, don't bother querying db.

    So the proper fix would be the following:

    func matchUsersWithCommitEmails(ctx gocontext.Context, oldCommits []*git.Commit) []*userCommit {
            emailToUsers := make(map[string]*db.User)
            newCommits := make([]*userCommit, len(oldCommits))
            for i := range oldCommits {
                    var u *db.User
                    if v, ok := emailToUsers[oldCommits[i].Author.Email]; !ok {
                            emailToUsers[oldCommits[i].Author.Email], _ = db.Users.GetByEmail(ctx, oldCommits[i].Author.Email) 
                            u = emailToUsers[oldCommits[i].Author.Email]
                    } else {
                            u = v
                    }
    
                    newCommits[i] = &userCommit{
                            User:   u,
                            Commit: oldCommits[i],
                    }
            }
            return newCommits
    }

    What it's missing is the assignment of user returned from db, both in emailToUsers and in u variable.

  6. added a commit that references this issue on Oct 5, 2023
    dbe8891
  7. locked as resolved and limited conversation to collaborators on Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    💊 bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions