Skip to content

Commit 522a55c

Browse files
authored
Visualize unsupported repos better (#236)
1 parent fd5f1ac commit 522a55c

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

cmd/src/actions_exec.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -476,28 +476,7 @@ fragment repositoryFields on Repository {
476476
for _, repo := range reposByID {
477477
repos = append(repos, repo)
478478
}
479-
for _, r := range skipped {
480-
logger.Infof("Skipping repository %s because we couldn't determine default branch.\n", r)
481-
}
482-
for _, r := range unsupported {
483-
logger.Infof("# Skipping repository %s because it's on a not supported code host.\n", r)
484-
}
485-
matchesStr := fmt.Sprintf("%d repositories match.", len(repos))
486-
unsupportedCount := len(unsupported)
487-
if includeUnsupported {
488-
if unsupportedCount > 0 {
489-
matchesStr += fmt.Sprintf(" (Including %d on unsupported code hosts.)", unsupportedCount)
490-
}
491-
} else {
492-
if unsupportedCount > 0 {
493-
matchesStr += " (Some repositories were filtered out because their code host is not supported by campaigns. Use -include-unsupported to generate patches for them anyways.)"
494-
}
495-
}
496-
logger.Infof("%s\n", matchesStr)
497-
498-
if len(repos) == 0 && !*verbose {
499-
yellow.Fprintf(os.Stderr, "WARNING: No repositories matched by scopeQuery\n")
500-
}
479+
logger.RepoMatches(len(repos), skipped, unsupported)
501480

502481
if content, err := result.Data.Search.Results.Alert.Render(); err != nil {
503482
yellow.Fprint(os.Stderr, err)

internal/campaigns/logger.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,38 @@ func (a *ActionLogger) DockerStepDone(repoName string, step int, elapsed time.Du
242242
a.write(repoName, yellow, "%s Done. (%s)\n", boldBlack.Sprintf("[Step %d]", step), elapsed)
243243
}
244244

245+
func (a *ActionLogger) RepoMatches(repoCount int, skipped, unsupported []string) {
246+
for _, r := range skipped {
247+
a.Infof("Skipping repository %s because we couldn't determine default branch.\n", r)
248+
}
249+
unsupportedCount := len(unsupported)
250+
var matchesStr string
251+
if repoCount == 1 {
252+
matchesStr = fmt.Sprintf("%d repository matches the scopeQuery.", repoCount)
253+
} else {
254+
var warnStr string
255+
if repoCount == 0 {
256+
warnStr = "WARNING: "
257+
}
258+
matchesStr = fmt.Sprintf("%s%d repositories match the scopeQuery.", warnStr, repoCount)
259+
}
260+
if unsupportedCount > 0 {
261+
matchesStr += fmt.Sprintf("\n\n%d repositories were filtered out because they are on a codehost not supported by campaigns. (use -include-unsupported to generate patches for them anyway):\n", unsupportedCount)
262+
for i, repo := range unsupported {
263+
matchesStr += color.HiYellowString("- %s\n", repo)
264+
if i == 10 {
265+
matchesStr += fmt.Sprintf("and %d more.\n", unsupportedCount-10)
266+
break
267+
}
268+
}
269+
}
270+
color := yellow
271+
if repoCount > 0 {
272+
color = boldGreen
273+
}
274+
a.write("", color, "%s\n\n", matchesStr)
275+
}
276+
245277
// write writes to the RepoWriter associated with the given repoName and logs the message using the log method.
246278
func (a *ActionLogger) write(repoName string, c *color.Color, format string, args ...interface{}) {
247279
if w, ok := a.RepoWriter(repoName); ok {
@@ -255,7 +287,7 @@ func (a *ActionLogger) log(repoName string, c *color.Color, format string, args
255287
if len(repoName) > 0 {
256288
format = fmt.Sprintf("%s -> %s", c.Sprint(repoName), format)
257289
}
258-
fmt.Fprintf(a.out, format, args...)
290+
fmt.Fprintf(a.out, c.Sprintf(format, args...))
259291
}
260292

261293
type progress struct {

0 commit comments

Comments
 (0)