Skip to content

Commit

Permalink
Always display repo name 🏷
Browse files Browse the repository at this point in the history
Before:

	$ gh collab-scanner --verbose
	(current repo)

	  - a README ☑️
	  - topics ☑️
	  - 1 collaborator 👤  - a community profile score of 33 💯%
	$ gh collab-scanner --user nicokosi --verbose
	nicokosi/adapted-drugs-searcher:
	  - a README ☑️
	  - no topics 😇
	  - 1 collaborator 👤  - a community profile score of 33 💯
	nicokosi/adr-tools:
	  - a README ☑️
	  - no topics 😇
	  - 1 collaborator 👤

Now:

	$ go run main.go --verbose
	(current repo)
	nicokosi/gh-collab-scanner has:
	  - a README ☑️
	  - topics ☑️
	  - 1 collaborator 👤
	  - a community profile score of 33 💯

	$ go run main.go --user nicokosi --verbose
	nicokosi/adapted-drugs-searcher has:
	  - a README ☑️
	  - no topics 😇
	  - 1 collaborator 👤
	  - a community profile score of 33 💯
  • Loading branch information
nicokosi committed Mar 24, 2022
1 parent 80f3f7a commit 087c945
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
40 changes: 23 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type repo struct {
Description string
Topics []string
Visibility string
Fork bool
Fork bool
}

type collaborator struct {
Expand Down Expand Up @@ -73,7 +73,7 @@ func main() {
for _, repo := range repos {
repoMessage, repo, validRepo := scanRepo(config, repo.Full_name)
if validRepo {
fmt.Printf(repo.Full_name + ": " + repoMessage)
fmt.Printf(repoMessage)
collaboratorsMessage := scanCollaborators(config, repo.Full_name)
fmt.Printf(collaboratorsMessage)
if strings.Compare(repo.Visibility, "public") == 0 {
Expand Down Expand Up @@ -158,17 +158,23 @@ func scanRepo(config config, repoWithOrg string) (message string, repository rep
err = client.Get(
"repos/"+repoWithOrg+"/readme",
&readme)
if config.verbose {
message += repoWithOrg + " has: "
}
if !config.verbose && (len(config.repo) > 1 || len(config.user) > 1) {
message += repoWithOrg + ": "
}
if len(readme.Name) > 0 {
if config.verbose {
message = "\n" + message + " - a README ☑️\n"
message += "\n - a README ☑️"
} else {
message = message + "README ☑️, "
message += "README ☑️, "
}
} else if strings.HasPrefix(err.Error(), "HTTP 404: Not Found") {
if config.verbose {
message = "\n" + message + " - no README 😇, \n"
message += "\n - no README 😇"
} else {
message = message + "no README 😇, "
message += "no README 😇, "
}
} else {
fmt.Print(err)
Expand All @@ -181,7 +187,7 @@ func scanRepo(config config, repoWithOrg string) (message string, repository rep
Description string
Topics []string
Visibility string
Fork bool
Fork bool
}{}
errRepo := client.Get(
"repos/"+repoWithOrg,
Expand All @@ -192,15 +198,15 @@ func scanRepo(config config, repoWithOrg string) (message string, repository rep
}
if len(repo.Topics) > 0 {
if config.verbose {
message = message + " - topics ☑️\n"
message += "\n - topics ☑️"
} else {
message = message + "topics ☑️, "
message += "topics ☑️, "
}
} else {
if config.verbose {
message = message + " - no topics 😇\n"
message += "\n - no topics 😇"
} else {
message = message + "no topics 😇, "
message += "no topics 😇, "
}
}
return message, repo, true
Expand All @@ -226,15 +232,15 @@ func scanCollaborators(config config, repoWithOrg string) string {
}
} else if len(collaborators) <= 1 {
if config.verbose {
message = message + fmt.Sprintf(" - %d collaborator 👤", len(collaborators))
message += fmt.Sprintf("\n - %d collaborator 👤", len(collaborators))
} else {
message = message + fmt.Sprintf("%d collaborator 👤", len(collaborators))
message += fmt.Sprintf("%d collaborator 👤", len(collaborators))
}
} else {
if config.verbose {
message = message + fmt.Sprintf(" - %d collaborators 👥", len(collaborators))
message += fmt.Sprintf("\n - %d collaborators 👥", len(collaborators))
} else {
message = message + fmt.Sprintf("%d collaborators 👥", len(collaborators))
message += fmt.Sprintf("%d collaborators 👥", len(collaborators))
}
}
return message
Expand All @@ -259,9 +265,9 @@ func scanCommunityScore(config config, repoWithOrg string) string {
}
message := ""
if config.verbose {
message = message + fmt.Sprintf(" - a community profile score of %d 💯", communityProfile.Health_percentage)
message += fmt.Sprintf("\n - a community profile score of %d 💯", communityProfile.Health_percentage)
} else {
message = message + fmt.Sprintf("community profile score: %d 💯", communityProfile.Health_percentage)
message += fmt.Sprintf("community profile score: %d 💯", communityProfile.Health_percentage)
}
return message
}
Expand Down
16 changes: 8 additions & 8 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestScanRepo(t *testing.T) {

assert.True(t, validRepo)
assert.Equal(t, repo{Name: "buzz", Owner: owner{Login: "Coyote"}, Description: "Beep, beep", Topics: []string{"old", "cartoon"}, Visibility: "public"}, repository)
assert.Equal(t, "README ☑️, topics ☑️, ", message)
assert.Equal(t, "acme/buzz: README ☑️, topics ☑️, ", message)
}

func TestGetRepos_for_org(t *testing.T) {
Expand Down Expand Up @@ -92,10 +92,10 @@ func TestScanRepo_Verbose(t *testing.T) {

assert.True(t, validRepo)
assert.Equal(t, repo{Name: "buzz", Owner: owner{Login: "Coyote"}, Description: "Beep, beep", Topics: []string{"old", "cartoon"}, Visibility: "public"}, repository)
assert.Equal(t, "\n - a README ☑️\n - topics ☑️\n", message)
assert.Equal(t, "acme/buzz has: \n - a README ☑️\n - topics ☑️", message)
}

func TestScanRepo_ReadmeError(t *testing.T) {
func TestScanRepo_Verbose_ReadmeError(t *testing.T) {
defer gock.Off()
defer gock.DisableNetworking()
gock.New("https://api.github.com").
Expand All @@ -110,10 +110,10 @@ func TestScanRepo_ReadmeError(t *testing.T) {

assert.True(t, validRepo)
assert.Equal(t, repo{Name: "buzz", Owner: owner{Login: "Coyote"}, Description: "Beep, beep", Topics: []string{"old", "cartoon"}, Visibility: "public"}, repository)
assert.Equal(t, " - topics ☑️\n", message)
assert.Equal(t, "acme/buzz has: \n - topics ☑️", message)
}

func TestScanRepo_RepoError(t *testing.T) {
func TestScanRepo_Verbose_RepoError(t *testing.T) {
defer gock.Off()
defer gock.DisableNetworking()
gock.New("https://api.github.com").
Expand All @@ -127,7 +127,7 @@ func TestScanRepo_RepoError(t *testing.T) {
message, _, validRepo := scanRepo(config{repo: "acme/buzz", verbose: true}, "acme/buzz")

assert.False(t, validRepo)
assert.Equal(t, "\n - a README ☑️\n", message)
assert.Equal(t, "acme/buzz has: \n - a README ☑️", message)
}

func TestScanCollaborators(t *testing.T) {
Expand All @@ -153,7 +153,7 @@ func TestScanCollaborators_Verbose(t *testing.T) {

message := scanCollaborators(config{repo: "acme/buzz", verbose: true}, "acme/buzz")

assert.Equal(t, " - 1 collaborator 👤", message)
assert.Equal(t, "\n - 1 collaborator 👤", message)
}

func TestScanCommunityScore(t *testing.T) {
Expand All @@ -179,7 +179,7 @@ func TestScanCommunityScore_Verbose(t *testing.T) {

message := scanCommunityScore(config{repo: "acme/buzz", verbose: true}, "acme/buzz")

assert.Equal(t, " - a community profile score of 42 💯", message)
assert.Equal(t, "\n - a community profile score of 42 💯", message)
}

func TestVersion(t *testing.T) {
Expand Down

0 comments on commit 087c945

Please sign in to comment.