From 9c220bf23e8a2d1e62862b7f5582b9269ea7e729 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 16 Sep 2023 10:54:39 +0200 Subject: [PATCH] [F3] PR create the pull/N/head from the original PR head It is incorrect to assume they are identical because: * the IDs of a PR may be remapped and pull/N/head will become pull/M/head * the head of a remote fork is a branch named after the fork --- services/f3/driver/pull_request.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) }