diff --git a/services/f3/driver/pull_request.go b/services/f3/driver/pull_request.go index f6ec82b122..cb8d7df488 100644 --- a/services/f3/driver/pull_request.go +++ b/services/f3/driver/pull_request.go @@ -220,6 +220,7 @@ func (o *PullRequest) FromFormat(pullRequest *format.PullRequest) { *o = PullRequest{ PullRequest: pr, + FetchFunc: pullRequest.FetchFunc, } } @@ -336,6 +337,21 @@ func (o *PullRequestProvider) Put(ctx context.Context, user *User, project *Proj } } + if pullRequest.FetchFunc != nil { + repoPath := repo_model.RepoPath(user.Name, project.Name) + fromHead := pullRequest.FetchFunc(repoPath) + gitRepo, err := git.OpenRepository(ctx, repoPath) + if err != nil { + panic(err) + } + defer gitRepo.Close() + + toHead := fmt.Sprintf("%s%d/head", git.PullPrefix, pullRequest.GetID()) + if err := git.NewCommand(ctx, "update-ref").AddDynamicArguments(toHead, fromHead).Run(&git.RunOpts{Dir: repoPath}); err != nil { + panic(err) + } + } + return o.Get(ctx, user, project, pullRequest) }