(headPath, basePath, headBranch, baseBranch string)
| 20 | } |
| 21 | |
| 22 | func (module) PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error) { |
| 23 | tmpRemoteBranch := baseBranch |
| 24 | |
| 25 | // We need to create a temporary remote when the pull request is sent from a forked repository. |
| 26 | if headPath != basePath { |
| 27 | tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10) |
| 28 | err := Module.RemoteAdd(headPath, tmpRemote, basePath, git.RemoteAddOptions{Fetch: true}) |
| 29 | if err != nil { |
| 30 | return nil, errors.Newf("add remote: %v", err) |
| 31 | } |
| 32 | defer func() { |
| 33 | err := Module.RemoteRemove(headPath, tmpRemote) |
| 34 | if err != nil { |
| 35 | log.Error("Failed to remove remote %q [path: %s]: %v", tmpRemote, headPath, err) |
| 36 | return |
| 37 | } |
| 38 | }() |
| 39 | |
| 40 | tmpRemoteBranch = "remotes/" + tmpRemote + "/" + baseBranch |
| 41 | } |
| 42 | |
| 43 | mergeBase, err := Module.MergeBase(headPath, tmpRemoteBranch, headBranch) |
| 44 | if err != nil { |
| 45 | return nil, errors.Wrap(err, "get merge base") |
| 46 | } |
| 47 | |
| 48 | commits, err := Module.Log(headPath, mergeBase+"..."+headBranch) |
| 49 | if err != nil { |
| 50 | return nil, errors.Wrap(err, "get commits") |
| 51 | } |
| 52 | |
| 53 | // Count number of changed files |
| 54 | names, err := Module.DiffNameOnly(headPath, tmpRemoteBranch, headBranch, git.DiffNameOnlyOptions{NeedsMergeBase: true}) |
| 55 | if err != nil { |
| 56 | return nil, errors.Wrap(err, "get changed files") |
| 57 | } |
| 58 | |
| 59 | return &PullRequestMeta{ |
| 60 | MergeBase: mergeBase, |
| 61 | Commits: commits, |
| 62 | NumFiles: len(names), |
| 63 | }, nil |
| 64 | } |
nothing calls this directly
no test coverage detected