-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Conversation
e4bde1f
to
48ba566
Compare
48ba566
to
7c2d67e
Compare
return updaterEnabled != "" && !isCI() && isTerminal(os.Stdout) && isTerminal(os.Stderr) | ||
} | ||
|
||
func isTerminal(f *os.File) bool { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined from utils
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
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 internaltext
package which lightly wraps thego-gh
text
package in order to simplify call sites and consolidatetext
utility functions outside of theutils
package. Theutils
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