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

Pluralize headers according to number of available entries #7

Merged
merged 1 commit into from Sep 4, 2021

Conversation

zMoooooritz
Copy link
Contributor

@zMoooooritz zMoooooritz commented Sep 3, 2021

Makes it easier to read the repository 'report'.

Edit:
Just thought about to add the date of the last tag / creation of the repo.

I think it would add some valuable information but introduces the problem of date formatting, what do you think?

@muesli
Copy link
Owner

muesli commented Sep 4, 2021

I feel like this might benefit from a little pluralize helper function. Something like:

func pluralize(count int, singular string, plural string) string {
    if count > 1 {
        return fmt.Sprintf("%d %s", count, plural)
    }
    return fmt.Sprintf("1 %s", singular)
}

Then we can basically get rid of all the if-then-else blocks. What do you think?

@muesli
Copy link
Owner

muesli commented Sep 4, 2021

Could even add a check for count being 0:

...
if count == 0 {
    return fmt.Sprintf("No %s", plural)
}
...

@zMoooooritz
Copy link
Contributor Author

Then we can basically get rid of all the if-then-else blocks. What do you think?

Yes, don't know why I didn't make it that way in the first place.
In case you don't want to have the function in main.go feel free to move it.

Take care, I did remove the early return in commit.go as far as I understand the code this should change nothing in terms of functionality (maybe a tiny amount of runtime).

@muesli
Copy link
Owner

muesli commented Sep 4, 2021

Perfect, looks good to me! Another project, another contribution from you, thank you so much!

@muesli muesli added the enhancement New feature or request label Sep 4, 2021
@muesli muesli changed the title Singularize headers for special case 1 Pluralize headers according to number of available entries Sep 4, 2021
@muesli muesli merged commit 23bb654 into muesli:main Sep 4, 2021
@zMoooooritz zMoooooritz deleted the singularize branch September 4, 2021 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants