Repository navigation
Remove naked return values from ReadBranchConfig and prSelectorForCurrentBranch
#10197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bf6fdbd
Remove named returns from ReadBranchConfig and surface errors
jtmcg f43da8e
Refactor ReadBranchConfig for test coverage of newly returned erros
jtmcg c83cf32
Remove named return values from prSelectorForCurrentBranch
jtmcg 0137150
Refactor Test_readGitBranchConfig for easier parsing
jtmcg 4575692
Remove private readBranchConfig method and remove parseBranchConfig f…
jtmcg fea46c0
Change ReadBranchConfig error message in gh pr create
jtmcg 527d1db
Add missing test for RemoteURL in parseBranchConfig
jtmcg ec9eaef
Refactor prSelectorForCurrentBranch and tests
jtmcg 94b2d4e
Added tests to cover prSelectorForCurrentBranch for confidence in ref…
jtmcg 15ac566
Remove shadowed errors from prSelectorForCurrentBranch and cover with…
jtmcg d4f7576
Add test for empty BranchConfig in prSelectorForCurrentBranch
jtmcg e1423cd
Refine error handling of ReadBranchConfig
jtmcg 48d45d0
Refactor error handling in ReadBranchConfig to avoid panic
jtmcg e4320cc
Directly stub headBranchConfig in Test_tryDetermineTrackingRef
jtmcg e4f0b79
Surface and handle error from ReadBranchConfig in parseCurrentBranch
jtmcg 100f9b4
Change pr number in test
jtmcg 3d27487
Rename test user in tests
jtmcg 322a43f
Change error handling on ReadBranchConfig to respect git Exit Codes
jtmcg 74cbd50
Restore old error functionality of prSelectorForCurrentBranch
jtmcg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "net/url" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
|
|
@@ -730,14 +731,35 @@ func TestClientReadBranchConfig(t *testing.T) { | |
| cmdExitStatus int | ||
| cmdStdout string | ||
| cmdStderr string | ||
| wantCmdArgs string | ||
| branch string | ||
| wantBranchConfig BranchConfig | ||
| wantError *GitError | ||
| }{ | ||
| { | ||
| name: "read branch config", | ||
| cmdExitStatus: 0, | ||
| cmdStdout: "branch.trunk.remote origin\nbranch.trunk.merge refs/heads/trunk\nbranch.trunk.gh-merge-base trunk", | ||
| wantCmdArgs: `path/to/git config --get-regexp ^branch\.trunk\.(remote|merge|gh-merge-base)$`, | ||
| branch: "trunk", | ||
| wantBranchConfig: BranchConfig{RemoteName: "origin", MergeRef: "refs/heads/trunk", MergeBase: "trunk"}, | ||
| wantError: nil, | ||
| }, | ||
| { | ||
| name: "git config runs successfully but returns no output (Exit Code 1)", | ||
| cmdExitStatus: 1, | ||
| cmdStdout: "", | ||
| cmdStderr: "", | ||
| branch: "trunk", | ||
| wantBranchConfig: BranchConfig{}, | ||
| wantError: nil, | ||
| }, | ||
| { | ||
| name: "output error (Exit Code > 1)", | ||
| cmdExitStatus: 2, | ||
| cmdStdout: "", | ||
| cmdStderr: "git error message", | ||
| branch: "trunk", | ||
| wantBranchConfig: BranchConfig{}, | ||
| wantError: &GitError{}, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
|
|
@@ -747,9 +769,85 @@ func TestClientReadBranchConfig(t *testing.T) { | |
| GitPath: "path/to/git", | ||
| commandContext: cmdCtx, | ||
| } | ||
| branchConfig := client.ReadBranchConfig(context.Background(), "trunk") | ||
| assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " ")) | ||
| branchConfig, err := client.ReadBranchConfig(context.Background(), tt.branch) | ||
| wantCmdArgs := fmt.Sprintf("path/to/git config --get-regexp ^branch\\.%s\\.(remote|merge|gh-merge-base)$", tt.branch) | ||
| assert.Equal(t, wantCmdArgs, strings.Join(cmd.Args[3:], " ")) | ||
| assert.Equal(t, tt.wantBranchConfig, branchConfig) | ||
| if tt.wantError != nil { | ||
| assert.ErrorAs(t, err, &tt.wantError) | ||
| } else { | ||
| assert.NoError(t, err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Test_parseBranchConfig(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| configLines []string | ||
| wantBranchConfig BranchConfig | ||
| }{ | ||
| { | ||
| name: "remote branch", | ||
| configLines: []string{"branch.trunk.remote origin"}, | ||
| wantBranchConfig: BranchConfig{ | ||
| RemoteName: "origin", | ||
| }, | ||
| }, | ||
| { | ||
| name: "merge ref", | ||
| configLines: []string{"branch.trunk.merge refs/heads/trunk"}, | ||
| wantBranchConfig: BranchConfig{ | ||
| MergeRef: "refs/heads/trunk", | ||
| }, | ||
| }, | ||
| { | ||
| name: "merge base", | ||
| configLines: []string{"branch.trunk.gh-merge-base gh-merge-base"}, | ||
| wantBranchConfig: BranchConfig{ | ||
| MergeBase: "gh-merge-base", | ||
| }, | ||
| }, | ||
| { | ||
| name: "remote, merge ref, and merge base all specified", | ||
| configLines: []string{ | ||
| "branch.trunk.remote origin", | ||
| "branch.trunk.merge refs/heads/trunk", | ||
| "branch.trunk.gh-merge-base gh-merge-base", | ||
| }, | ||
| wantBranchConfig: BranchConfig{ | ||
| RemoteName: "origin", | ||
| MergeRef: "refs/heads/trunk", | ||
| MergeBase: "gh-merge-base", | ||
| }, | ||
| }, | ||
| { | ||
| name: "remote URL", | ||
| configLines: []string{ | ||
| "branch.Frederick888/main.remote [email protected]:Frederick888/playground.git", | ||
| "branch.Frederick888/main.merge refs/heads/main", | ||
| }, | ||
| wantBranchConfig: BranchConfig{ | ||
| MergeRef: "refs/heads/main", | ||
| RemoteURL: &url.URL{ | ||
| Scheme: "ssh", | ||
| User: url.User("git"), | ||
| Host: "github.com", | ||
| Path: "/Frederick888/playground.git", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| branchConfig := parseBranchConfig(tt.configLines) | ||
| assert.Equal(t, tt.wantBranchConfig.RemoteName, branchConfig.RemoteName) | ||
| assert.Equal(t, tt.wantBranchConfig.MergeRef, branchConfig.MergeRef) | ||
| assert.Equal(t, tt.wantBranchConfig.MergeBase, branchConfig.MergeBase) | ||
| if tt.wantBranchConfig.RemoteURL != nil { | ||
| assert.Equal(t, tt.wantBranchConfig.RemoteURL.String(), branchConfig.RemoteURL.String()) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.