refactor: remove Ctx field from git.Repository (#38500)

This commit is contained in:
wxiaoguang
2026-07-17 18:44:31 +08:00
committed by GitHub
parent 2c8e99bbf7
commit 5b078f72aa
235 changed files with 1234 additions and 1258 deletions
+2 -2
View File
@@ -48,11 +48,11 @@ func TestCreateCommitStatus_Dedupe(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
gitRepo, err := gitrepo.OpenRepository(repo)
require.NoError(t, err)
defer gitRepo.Close()
commit, err := gitRepo.GetBranchCommit(repo.DefaultBranch)
commit, err := gitRepo.GetBranchCommit(t.Context(), repo.DefaultBranch)
require.NoError(t, err)
run := &actions_model.ActionRun{
+7 -7
View File
@@ -148,7 +148,7 @@ func notify(ctx context.Context, input *notifyInput) error {
return nil
}
gitRepo, err := gitrepo.OpenRepository(context.Background(), input.Repo)
gitRepo, err := gitrepo.OpenRepository(input.Repo)
if err != nil {
return fmt.Errorf("git.OpenRepository: %w", err)
}
@@ -167,13 +167,13 @@ func notify(ctx context.Context, input *notifyInput) error {
ref = git.RefNameFromBranch(input.Repo.DefaultBranch)
}
commitID, err := gitRepo.GetRefCommitID(ref.String())
commitID, err := gitRepo.GetRefCommitID(ctx, ref.String())
if err != nil {
return fmt.Errorf("gitRepo.GetRefCommitID: %w", err)
}
// Get the commit object for the ref
commit, err := gitRepo.GetCommit(commitID)
commit, err := gitRepo.GetCommit(ctx, commitID)
if err != nil {
return fmt.Errorf("gitRepo.GetCommit: %w", err)
}
@@ -227,7 +227,7 @@ func notify(ctx context.Context, input *notifyInput) error {
if input.PullRequest != nil {
// detect pull_request_target workflows
baseRef := git.BranchPrefix + input.PullRequest.BaseBranch
baseCommit, err := gitRepo.GetCommit(baseRef)
baseCommit, err := gitRepo.GetCommit(ctx, baseRef)
if err != nil {
return fmt.Errorf("gitRepo.GetCommit: %w", err)
}
@@ -591,14 +591,14 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
return nil
}
gitRepo, err := gitrepo.OpenRepository(context.Background(), repo)
gitRepo, err := gitrepo.OpenRepository(repo)
if err != nil {
return fmt.Errorf("git.OpenRepository: %w", err)
}
defer gitRepo.Close()
// Only detect schedule workflows on the default branch
commit, err := gitRepo.GetCommit(repo.DefaultBranch)
commit, err := gitRepo.GetCommit(ctx, repo.DefaultBranch)
if err != nil {
return fmt.Errorf("gitRepo.GetCommit: %w", err)
}
@@ -748,6 +748,6 @@ func detectScopedWorkflowsForSource(
if err != nil {
return "", nil, nil, err
}
detected, filtered = actions_module.MatchScopedWorkflows(parsed, consumerGitRepo, consumerCommit, input.Event, input.Payload)
detected, filtered = actions_module.MatchScopedWorkflows(ctx, parsed, consumerGitRepo, consumerCommit, input.Event, input.Payload)
return sourceCommitSHA, detected, filtered, nil
}
+2 -2
View File
@@ -79,13 +79,13 @@ func loadReusableWorkflowSource(ctx context.Context, run *actions_model.ActionRu
// readWorkflowFromRepo loads a workflow file from `repo` at `refOrSHA` and returns its content plus the resolved commit SHA.
func readWorkflowFromRepo(ctx context.Context, repo *repo_model.Repository, refOrSHA, path string) ([]byte, string, error) {
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
gitRepo, err := gitrepo.OpenRepository(repo)
if err != nil {
return nil, "", fmt.Errorf("open repo %s: %w", repo.FullName(), err)
}
defer gitRepo.Close()
commit, err := gitRepo.GetCommit(refOrSHA)
commit, err := gitRepo.GetCommit(ctx, refOrSHA)
if err != nil {
return nil, "", fmt.Errorf("get commit %q in %s: %w", refOrSHA, repo.FullName(), err)
}
+2 -2
View File
@@ -50,13 +50,13 @@ func LoadParsedScopedWorkflows(ctx context.Context, sourceRepo *repo_model.Repos
}
// cache miss: open the source repo at the exact SHA we keyed on
sourceGitRepo, err := gitrepo.OpenRepository(ctx, sourceRepo)
sourceGitRepo, err := gitrepo.OpenRepository(sourceRepo)
if err != nil {
return "", nil, fmt.Errorf("open source repo: %w", err)
}
defer sourceGitRepo.Close()
sourceCommit, err := sourceGitRepo.GetCommit(sha)
sourceCommit, err := sourceGitRepo.GetCommit(ctx, sha)
if err != nil {
return "", nil, fmt.Errorf("get source commit %s: %w", sha, err)
}
+4 -4
View File
@@ -85,12 +85,12 @@ func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, re
var runTargetCommit *git.Commit
var err error
if refName.IsTag() {
runTargetCommit, err = gitRepo.GetTagCommit(refName.TagName())
runTargetCommit, err = gitRepo.GetTagCommit(ctx, refName.TagName())
} else if refName.IsBranch() {
runTargetCommit, err = gitRepo.GetBranchCommit(refName.BranchName())
runTargetCommit, err = gitRepo.GetBranchCommit(ctx, refName.BranchName())
} else {
refName = git.RefNameFromBranch(ref)
runTargetCommit, err = gitRepo.GetBranchCommit(ref)
runTargetCommit, err = gitRepo.GetBranchCommit(ctx, ref)
}
if err != nil {
return 0, util.ErrorWrapTranslatable(
@@ -183,7 +183,7 @@ func resolveDispatchWorkflowContent(ctx reqctx.RequestContext, repo *repo_model.
}
for _, e := range entries {
if e.Name() == workflowID {
return actions.GetContentFromEntry(gitRepo, e)
return actions.GetContentFromEntry(ctx, gitRepo, e)
}
}
return nil, util.ErrorWrapTranslatable(