(t *testing.T)
| 253 | } |
| 254 | |
| 255 | func TestTryDetermineDefaultPRHead(t *testing.T) { |
| 256 | t.Parallel() |
| 257 | |
| 258 | baseRepo := ghrepo.New("owner", "repo") |
| 259 | baseRemote := ghContext.Remote{ |
| 260 | Remote: &git.Remote{ |
| 261 | Name: "upstream", |
| 262 | }, |
| 263 | Repo: baseRepo, |
| 264 | } |
| 265 | |
| 266 | forkRepo := ghrepo.New("otherowner", "repo-fork") |
| 267 | forkRemote := ghContext.Remote{ |
| 268 | Remote: &git.Remote{ |
| 269 | Name: "origin", |
| 270 | }, |
| 271 | Repo: forkRepo, |
| 272 | } |
| 273 | forkRepoURL, err := url.Parse("https://github.com/otherowner/repo-fork.git") |
| 274 | require.NoError(t, err) |
| 275 | |
| 276 | t.Run("when the push revision is set, use that", func(t *testing.T) { |
| 277 | t.Parallel() |
| 278 | |
| 279 | repoResolvedFromPushRevisionClient := stubGitConfigClient{ |
| 280 | pushRevisionFn: stubPushRevision(git.RemoteTrackingRef{ |
| 281 | Remote: "origin", |
| 282 | Branch: "remote-feature-branch", |
| 283 | }, nil), |
| 284 | } |
| 285 | |
| 286 | defaultPRHead, err := TryDetermineDefaultPRHead( |
| 287 | repoResolvedFromPushRevisionClient, |
| 288 | stubRemoteToRepoResolver(ghContext.Remotes{&baseRemote, &forkRemote}, nil), |
| 289 | "feature-branch", |
| 290 | ) |
| 291 | require.NoError(t, err) |
| 292 | |
| 293 | require.True(t, ghrepo.IsSame(defaultPRHead.Repo.Unwrap(), forkRepo), "expected repos to be the same") |
| 294 | require.Equal(t, "remote-feature-branch", defaultPRHead.BranchName) |
| 295 | }) |
| 296 | |
| 297 | t.Run("when the branch config push remote is set to a name, use that", func(t *testing.T) { |
| 298 | t.Parallel() |
| 299 | |
| 300 | repoResolvedFromPushRemoteClient := stubGitConfigClient{ |
| 301 | pushRevisionFn: stubPushRevision(git.RemoteTrackingRef{}, errors.New("no push revision")), |
| 302 | readBranchConfigFn: stubBranchConfig(git.BranchConfig{ |
| 303 | PushRemoteName: "origin", |
| 304 | }, nil), |
| 305 | pushDefaultFn: stubPushDefault(git.PushDefaultCurrent, nil), |
| 306 | } |
| 307 | |
| 308 | defaultPRHead, err := TryDetermineDefaultPRHead( |
| 309 | repoResolvedFromPushRemoteClient, |
| 310 | stubRemoteToRepoResolver(ghContext.Remotes{&baseRemote, &forkRemote}, nil), |
| 311 | "feature-branch", |
| 312 | ) |
nothing calls this directly
no test coverage detected