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

tablerow in templates truncates strings #6524

Closed
NickVolynkin opened this issue Oct 27, 2022 · 2 comments · Fixed by #6421
Closed

tablerow in templates truncates strings #6524

NickVolynkin opened this issue Oct 27, 2022 · 2 comments · Fixed by #6421
Labels
bug Something isn't working p3 Affects a small number of users or is largely cosmetic

Comments

@NickVolynkin
Copy link

NickVolynkin commented Oct 27, 2022

Describe the bug

A clear and concise description of what the bug is. Include version by typing gh --version.

I have this code that makes a table of repo's issues:

start_timestamp=$(gdate --date="$(gdate +'%Y-%m-%d') - 1 month" +'%Y-%m-%d')
echo "Looking for issues closed since $start_timestamp -> closed.log"
gh issue list --search "is:closed closed:>$start_timestamp" --json 'title,url' \
  --template '{{range .}}{{tablerow .title .url}}{{end}}' > closed.log

(Here gdate is the GNU implementation of date from the coreutils package)

Just a month ago it used to make a table with full titles and URLs. But now gh truncates the strings, making the output basically useless:

Docs: table of content and language ...  https://github.com/tarantool/taranto...
Make separate customer zone pages fo...  https://github.com/tarantool/taranto...

I haven't found a way to revert to the previous behaviour in the following docs:

gh version:

gh version 2.17.0 (2022-10-04)

Steps to reproduce the behavior

  1. Run the code above on a repository with at least a few closed issues.
  2. View the output in closed.log
  3. See the title and URL strings truncated.

Expected vs actual behavior

Same but in 3. you get full titles and URLs.

Logs

(no extra logs needed)

@NickVolynkin NickVolynkin added the bug Something isn't working label Oct 27, 2022
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Oct 27, 2022
@LangLangBart
Copy link

LangLangBart commented Oct 30, 2022

Bisecting suggests the change came with 6a8deb1


To alleviate the problem, you could experiment with --jq or an environment variable.

  1. --jq
gh issue list --search "is:closed closed:>$start_timestamp" --json 'title,url' --jq '.[] | .title + "\t" + .url' > closed.log
  1. Environment Variable
GH_FORCE_TTY=100% gh issue list --search "is:closed closed:>$start_timestamp" --json 'title,url' \
  --template '{{range .}}{{tablerow .title .url}}{{end}}' > closed.log

EDIT:
3. printf

gh issue list --search "is:closed closed:>$start_timestamp" --json 'title,url' --template '{{range .}}{{ printf "%s\t%s\n" .title .url}}{{end}}' > closed.log

@mislav
Copy link
Contributor

mislav commented Oct 31, 2022

Thanks @NickVolynkin for reporting and @LangLangBart for tracking down. This is indeed a bug from #6084 and will be fixed by #6421.

Note that tablerow will still truncate table columns to make the whole table fit in the current terminal viewport. The bug is that the terminal width was incorrectly measured when stdout was redirected. But, with tablerow you are never safe from truncation. If you don't want truncation, you might want to avoid using tablerow and just output values directly.

The workaround to avoid truncation is to force a really wide terminal with GH_FORCE_TTY=10000

@mislav mislav added p3 Affects a small number of users or is largely cosmetic and removed needs-triage needs to be reviewed labels Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p3 Affects a small number of users or is largely cosmetic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants