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

feat: Enable issue edit to read body from stdin #619

Merged
merged 3 commits into from
Jun 12, 2023

Conversation

erpel
Copy link
Contributor

@erpel erpel commented May 9, 2023

When working with jira I found that setting the body from stdin is not supported in issue edit. It seemed easy to add.

If you're interested in this feature that does not break anything (as far as I can tell) please feel free to accept this MR. I'm of course open to suggestions for anything that can be improved.

@erpel
Copy link
Contributor Author

erpel commented May 9, 2023

While working with this I noticed that setting content from stdin only works with pipes/FIFOs. Redirecting a files content to stdin using shell redirection command < file is not treated as "having data in stdin".
Is there any particular reason for this check? It is in https://github.com/ankitpokhrel/jira-cli/blame/eb842e18014303a575fde8e19508b3c7c13982c5/internal/cmdutil/utils.go#L135

if fi.Mode()&os.ModeNamedPipe == 0 {
		return false
	}

With this removed, both of these work:

jira issue edit IN-4 --no-input < upgrade-clusters.md 
cat upgrade-clusters.md | jira issue edit IN-4 --no-input 

@ankitpokhrel
Copy link
Owner

Hi @erpel, apologies for the late response.

I don't exactly remember the reason behind this check, TBH. Perhaps it was overlooked when working on the initial feature. I think we can update the method StdinHasData to something like the one below, so that it considers both stdin and file redirection.

import "golang.org/x/crypto/ssh/terminal"

func StdinHasData() bool {
	if terminal.IsTerminal(int(os.Stdin.Fd())) {
		return false
	}
	return true
}

@erpel
Copy link
Contributor Author

erpel commented Jun 4, 2023

Thanks for looking into this.
I took a look at "golang.org/x/crypto/ssh/terminal" and its IsTerminal function. Since it's just a wrapper around functionality in "golang.org/x/term" which was an indirect dependency already I opted to use this instead. Let me know what you think.

Copy link
Owner

@ankitpokhrel ankitpokhrel left a comment

Choose a reason for hiding this comment

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

This works fine. Thank you!

@ankitpokhrel ankitpokhrel merged commit 4167b1f into ankitpokhrel:main Jun 12, 2023
2 checks passed
@erpel erpel deleted the feat_edit_issue_stdin branch June 13, 2023 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants