diff --git a/pkg/api/controller.go b/pkg/api/controller.go index 3218b589ec6..20ffb6c3b59 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -2382,12 +2382,11 @@ func (c *Controller) ImportStart(w http.ResponseWriter, r *http.Request, body ap }) } - committer := user.Username importID, err := c.Catalog.Import(r.Context(), repository, branch, catalog.ImportRequest{ Paths: paths, Commit: catalog.ImportCommit{ CommitMessage: body.Commit.Message, - Committer: committer, + Committer: user.Committer(), Metadata: metadata, }, }) @@ -2488,8 +2487,8 @@ func (c *Controller) Commit(w http.ResponseWriter, r *http.Request, body apigen. if body.Metadata != nil { metadata = body.Metadata.AdditionalProperties } - committer := user.Username - newCommit, err := c.Catalog.Commit(ctx, repository, branch, body.Message, committer, metadata, body.Date, params.SourceMetarange) + + newCommit, err := c.Catalog.Commit(ctx, repository, branch, body.Message, user.Committer(), metadata, body.Date, params.SourceMetarange) var hookAbortErr *graveler.HookAbortError if errors.As(err, &hookAbortErr) { c.Logger. @@ -2916,10 +2915,9 @@ func (c *Controller) RevertBranch(w http.ResponseWriter, r *http.Request, body a writeError(w, r, http.StatusUnauthorized, "user not found") return } - committer := user.Username err = c.Catalog.Revert(ctx, repository, branch, catalog.RevertParams{ Reference: body.Ref, - Committer: committer, + Committer: user.Committer(), ParentNumber: body.ParentNumber, }) if c.handleAPIError(ctx, w, r, err) { @@ -2955,10 +2953,9 @@ func (c *Controller) CherryPick(w http.ResponseWriter, r *http.Request, body api writeError(w, r, http.StatusUnauthorized, "user not found") return } - committer := user.Username newCommit, err := c.Catalog.CherryPick(ctx, repository, branch, catalog.CherryPickParams{ Reference: body.Ref, - Committer: committer, + Committer: user.Committer(), ParentNumber: body.ParentNumber, }) if c.handleAPIError(ctx, w, r, err) { @@ -3916,7 +3913,7 @@ func (c *Controller) MergeIntoBranch(w http.ResponseWriter, r *http.Request, bod reference, err := c.Catalog.Merge(ctx, repository, destinationBranch, sourceRef, - user.Username, + user.Committer(), swag.StringValue(body.Message), metadata, swag.StringValue(body.Strategy)) diff --git a/pkg/auth/model/model.go b/pkg/auth/model/model.go index 7ae0af08c65..14ad59bab45 100644 --- a/pkg/auth/model/model.go +++ b/pkg/auth/model/model.go @@ -122,6 +122,13 @@ type User struct { ExternalID *string `db:"external_id" json:"external_id"` } +func (u *User) Committer() string { + if u.Email != nil && *u.Email != "" { + return *u.Email + } + return u.Username +} + type DBUser struct { ID int64 `db:"id"` User