Skip to content

Commit 202d77d

Browse files
authored
Merge pull request github#16726 from github/mbg/go/log-one-line-for-stray-sources
Go: Only log one line for stray .go files
2 parents 24c9062 + 20b7def commit 202d77d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

go/extractor/util/util.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package util
22

33
import (
44
"errors"
5+
"fmt"
56
"io/fs"
67
"log"
78
"net/url"
@@ -185,12 +186,39 @@ func GoFilesOutsideDirs(root string, dirsToSkip ...string) []string {
185186
return filepath.SkipDir
186187
}
187188
if filepath.Ext(d.Name()) == ".go" {
188-
log.Printf("Found stray Go source file in %s.\n", path)
189189
result = append(result, path)
190190
}
191191
return nil
192192
})
193193

194+
if len(result) > 0 {
195+
log.Printf(
196+
"Found %d stray Go source file(s) in %s\n",
197+
len(result),
198+
JoinTruncatedList(result, ", ", 5),
199+
)
200+
}
201+
202+
return result
203+
}
204+
205+
// Joins the `elements` into one string, up to `maxElements`, separated by `sep`.
206+
// If the length of `elements` exceeds `maxElements`, the string "and %d more" is
207+
// appended where `%d` is the number of `elements` that were omitted.
208+
func JoinTruncatedList(elements []string, sep string, maxElements int) string {
209+
num := len(elements)
210+
numIncluded := num
211+
truncated := false
212+
if num > maxElements {
213+
numIncluded = maxElements
214+
truncated = true
215+
}
216+
217+
result := strings.Join(elements[0:numIncluded], sep)
218+
if truncated {
219+
result += fmt.Sprintf(", and %d more", num-maxElements)
220+
}
221+
194222
return result
195223
}
196224

0 commit comments

Comments
 (0)