diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index 27a0827a10..e5193d9c66 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -356,6 +356,12 @@ func ReqChangeRepoFileOptionsAndCheck(ctx *context.APIContext) { OldBranch: commonOpts.BranchName, NewBranch: commonOpts.NewBranchName, ForcePush: commonOpts.ForcePush, + ActionsTaskID: func() int64 { + if ctx.Data["ActionsTaskID"] != nil { + return ctx.Data["ActionsTaskID"].(int64) + } + return 0 + }(), Committer: &files_service.IdentityOptions{ GitUserName: commonOpts.Committer.Name, GitUserEmail: commonOpts.Committer.Email, diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go index b605236c03..94d85616cc 100644 --- a/services/repository/files/temp_repo.go +++ b/services/repository/files/temp_repo.go @@ -33,6 +33,8 @@ type TemporaryUploadRepository struct { gitRepo *git.Repository basePath string cleanup func() + + ActionsTaskID int64 } // NewTemporaryUploadRepository creates a new temporary upload repository @@ -362,6 +364,9 @@ func (t *TemporaryUploadRepository) CommitTree(ctx context.Context, opts *Commit func (t *TemporaryUploadRepository) Push(ctx context.Context, doer *user_model.User, commitHash, branch string, force bool) error { // Because calls hooks we need to pass in the environment env := repo_module.PushingEnvironment(doer, t.repo) + if t.ActionsTaskID > 0 { + env = append(env, repo_module.EnvActionsTaskID+"="+fmt.Sprintf("%d", t.ActionsTaskID)) + } if err := gitrepo.PushFromLocal(ctx, t.basePath, t.repo, git.PushOptions{ Branch: strings.TrimSpace(commitHash) + ":" + git.BranchPrefix + strings.TrimSpace(branch), Env: env, diff --git a/services/repository/files/update.go b/services/repository/files/update.go index bd992d06de..88a0652038 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -64,6 +64,7 @@ type ChangeRepoFilesOptions struct { Dates *CommitDateOptions Signoff bool ForcePush bool + ActionsTaskID int64 } type RepoFileOptions struct { @@ -177,6 +178,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use if err != nil { log.Error("NewTemporaryUploadRepository failed: %v", err) } + t.ActionsTaskID = opts.ActionsTaskID defer t.Close() hasOldBranch := true if err := t.Clone(ctx, opts.OldBranch, true); err != nil {