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

Migrate to go-gh text package #6236

Merged
merged 1 commit into from
Sep 14, 2022
Merged

Migrate to go-gh text package #6236

merged 1 commit into from
Sep 14, 2022

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented Sep 11, 2022

This PR replaces existing uses of text utilities with the go-gh text package. Similar to how I have done other replacements I created an internal text package which lightly wraps the go-gh text package in order to simplify call sites and consolidate text utility functions outside of the utils package. The utils package was very sparse so I also consolidated that into one file with the two functions that are still left in it (excluding table printer).

follow up to cli/go-gh#69
cc #5544

@samcoe samcoe force-pushed the integrate-text-package branch 6 times, most recently from e4bde1f to 48ba566 Compare September 13, 2022 09:15
return updaterEnabled != "" && !isCI() && isTerminal(os.Stdout) && isTerminal(os.Stderr)
}

func isTerminal(f *os.File) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function also exists unexported in the iostreams package, I had inlined it here from the utils package. Should we export it from iostreams to prevent this duplication?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine like this. I will take care of this when I start dogfooding iostreams stuff from go-gh; thanks!

@@ -498,3 +498,12 @@ func buildDisplayName(displayName string, prebuildAvailability string) string {
return displayName
}
}

func stringInSlice(a string, slice []string) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined from utils.

}

// RemoveExcessiveWhitespace returns a copy of the string s with excessive whitespace removed.
func RemoveExcessiveWhitespace(s string) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This used to be called ReplaceExcessiveWhitespace but RemoveExcessiveWhitespace seemed more descriptive.

return text.Pluralize(num, thing)
}

func FuzzyAgo(a, b time.Time) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FuzzyAgo used to take in a time.Duration argument but I changed it to take in two time.Time arguments to match FuzzyAgoAbbr. Also the call sites were using time.Since or time.Sub to create the time.Duration argument so that is now simplified and taken care of by the function.

@@ -764,4 +764,16 @@ func generateCompareURL(ctx CreateContext, state shared.IssueMetadataState) (str
return url, nil
}

// Humanize returns a copy of the string s that replaces all instance of '-' and '_' with spaces.
func humanize(s string) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined from utils.

@@ -44,6 +44,11 @@ func WithPrAndIssueQueryParams(client *api.Client, baseRepo ghrepo.Interface, ba
return u.String(), nil
}

// Maximum length of a URL: 8192 bytes
func ValidURL(urlStr string) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined from utils.

@@ -330,3 +329,7 @@ func forkRun(opts *ForkOptions) error {

return nil
}

func isURL(s string) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined from utils.

@@ -140,3 +139,29 @@ func formatKeywords(ks []string) []string {
}
return ks
}

// CamelToKebab returns a copy of the string s that is converted from camel case form to '-' separated form.
func camelToKebab(s string) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined from utils.

@samcoe samcoe marked this pull request as ready for review September 13, 2022 13:51
@samcoe samcoe requested review from a team as code owners September 13, 2022 13:51
@samcoe samcoe requested review from vilmibm and removed request for a team September 13, 2022 13:51
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Sep 13, 2022
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.

Awesome! :shipit:

The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Sep 13, 2022
@samcoe samcoe merged commit e7102f9 into trunk Sep 14, 2022
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Sep 14, 2022
@samcoe samcoe deleted the integrate-text-package branch September 14, 2022 05:23
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Sep 21, 2022
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.

None yet

2 participants