From 98faae778c953678944996c89ed99307d2f16a3d Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Wed, 27 May 2026 14:16:25 +0200 Subject: [PATCH] Use Gitlab username (#6653) --- cli/exec/exec.go | 9 ++++++--- cli/exec/exec_test.go | 6 ++++-- server/forge/gitlab/convert.go | 14 +++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cli/exec/exec.go b/cli/exec/exec.go index f572ab0a17..1e918538c9 100644 --- a/cli/exec/exec.go +++ b/cli/exec/exec.go @@ -178,18 +178,21 @@ func runExec(ctx context.Context, c *cli.Command, yamls []*builder.YamlFile, rep // configure volumes for local execution volumes := c.StringSlice("volumes") if c.Bool("local") { - compilerOpts = append(compilerOpts, + compilerOpts = append( + compilerOpts, compiler.WithWorkspace( c.String("workspace-base"), c.String("workspace-path"), ), ) - volumes = append(volumes, + volumes = append( + volumes, prefix+"_default:"+c.String("workspace-base"), repoPath+":"+c.String("workspace-base")+"/"+c.String("workspace-path"), ) } else { - compilerOpts = append(compilerOpts, + compilerOpts = append( + compilerOpts, compiler.WithWorkspace( c.String("workspace-base"), c.String("workspace-path"), diff --git a/cli/exec/exec_test.go b/cli/exec/exec_test.go index 27ab99d827..b8a66295f9 100644 --- a/cli/exec/exec_test.go +++ b/cli/exec/exec_test.go @@ -72,12 +72,14 @@ steps: r.Close() stdout := buf.String() - assert.Contains(t, stdout, + assert.Contains( + t, stdout, `[build:L0:0s] StepName: build [build:L1:0s] StepType: commands [build:L2:0s] StepUUID: `, ) - assert.Contains(t, stdout, + assert.Contains( + t, stdout, `[build:L3:0s] StepCommands: [build:L4:0s] ------------------ [build:L5:0s] echo hello diff --git a/server/forge/gitlab/convert.go b/server/forge/gitlab/convert.go index a929565992..69cba5add6 100644 --- a/server/forge/gitlab/convert.go +++ b/server/forge/gitlab/convert.go @@ -224,7 +224,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (mergeI author := lastCommit.Author - pipeline.Author = author.Name + pipeline.Author = hook.User.Username pipeline.Email = author.Email if len(pipeline.Email) != 0 { @@ -279,11 +279,12 @@ func convertPushHook(hook *gitlab.PushEvent) (*model.Repo, *model.Pipeline, erro pipeline.Branch = strings.TrimPrefix(hook.Ref, "refs/heads/") pipeline.Ref = hook.Ref + pipeline.Author = hook.UserUsername + // assume a capacity of 4 changed files per commit files := make([]string, 0, len(hook.Commits)*4) for _, cm := range hook.Commits { if hook.After == cm.ID { - pipeline.Author = cm.Author.Name pipeline.Email = cm.Author.Email pipeline.Message = cm.Message pipeline.Timestamp = cm.Timestamp.Unix() @@ -337,10 +338,10 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Pipeline, string pipeline.Commit = hook.After pipeline.Branch = refTag pipeline.Ref = hook.Ref + pipeline.Author = hook.UserUsername for _, cm := range hook.Commits { if hook.After == cm.ID { - pipeline.Author = cm.Author.Name pipeline.Email = cm.Author.Email pipeline.Message = cm.Message pipeline.Timestamp = cm.Timestamp.Unix() @@ -394,8 +395,11 @@ func convertReleaseHook(hook *gitlab.ReleaseEvent) (*model.Repo, *model.Pipeline ForgeURL: hook.URL, Message: fmt.Sprintf("created release %s", hook.Name), Sender: hook.Commit.Author.Name, - Author: hook.Commit.Author.Name, - Email: hook.Commit.Author.Email, + // Using the commit author here as Gitlab does not send the hook user. + // This is not an issue because releases can be created by users with + // push permissions only anyways. + Author: hook.Commit.Author.Name, + Email: hook.Commit.Author.Email, // Tag name here is the ref. We should add the refs/tags, so // it is known it's a tag (git-plugin looks for it)