Skip to content
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

Add :branch placeholder for API calls #1515

Merged
merged 5 commits into from
Aug 12, 2020
Merged

Conversation

fsmiamoto
Copy link
Contributor

As discussed in #1288, this PR allows for the use of the :branch placeholder on the api command.

The placeholder is substituted with the current git branch name.

Closes #1288

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Two tiny points

@@ -298,12 +301,22 @@ func fillPlaceholders(value string, opts *ApiOptions) (string, error) {
return value, err
}

var branch string
if strings.Contains(value, ":branch") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a subtle bug here: the placeholderRE matches only :branch\b (notice the word boundary), but strings.Contains matches ":branch" even when it's not on a word boundary.

So I would move the branch lookup logic to the below case ":branch" block

IO: f.IOStreams,
HttpClient: f.HttpClient,
BaseRepo: f.BaseRepo,
CurrentBranch: git.CurrentBranch,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of git.CurrentBranch, you can pass f.Branch, since this is already what a cmdutil.Factory provides and allows the current branch to be mocked easier in tests

@fsmiamoto
Copy link
Contributor Author

@mislav
Thanks for the review!
I've made the suggested changes 👍

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨✨

@mislav mislav merged commit 55a13a3 into cli:trunk Aug 12, 2020
@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation Aug 13, 2020
@vilmibm vilmibm moved this from Backlog 🗒 to Pending Release 🥚 in The GitHub CLI Aug 13, 2020
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

Add :branch placeholder to api command
3 participants