Skip to content

Commit

Permalink
CLI | Handling disabled repos in ADO (#695)
Browse files Browse the repository at this point in the history
* Add Disabled Repo check

* Add unit test

* Change test title

---------

Co-authored-by: AlvoBen <[email protected]>
Co-authored-by: Or Shamir Checkmarx <[email protected]>
  • Loading branch information
3 people authored Apr 4, 2024
1 parent 931e4ed commit 7e6c255
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/commands/util/usercount/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func createRunAzureUserCountFunc(azureWrapper wrappers.AzureWrapper) func(cmd *c
}

log.Println(params.BotCount)
log.Println(params.DisabledReposCount)

return err
}
Expand Down
21 changes: 21 additions & 0 deletions internal/commands/util/usercount/user-count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package usercount
import (
"testing"

"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/spf13/cobra"
"gotest.tools/assert"
)
Expand All @@ -20,3 +21,23 @@ func TestNewUserCountCommand(t *testing.T) {
mockParentCmd.SetArgs([]string{UcCommand, "-h"})
assert.NilError(t, cmd.Execute())
}

func TestGetEnabledRepositories_2Enable1DisableRepo_Success(t *testing.T) {
repos := []wrappers.AzureRepo{
{
Name: "MOCK REPO",
IsDisabled: false,
},
{
Name: "MOCK REPO 2",
IsDisabled: true,
},
{
Name: "MOCK REPO 3",
IsDisabled: false,
},
}
rootRepo := wrappers.AzureRootRepo{Repos: repos}
enabledRepos := rootRepo.GetEnabledRepos()
assert.Equal(t, len(enabledRepos.Repos), 2)
}
1 change: 1 addition & 0 deletions internal/params/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const (
GithubTokenUsage = "GitHub OAuth token. Requires “Repo” scope and organization SSO authorization, if enforced by the organization"
GitLabTokenUsage = "GitLab OAuth token"
BotCount = "Note: dependabot is not counted but other bots might be considered as contributors."
DisabledReposCount = "Note: Disabled repositories are not counted."
URLFlag = "url"
GitLabURLFlag = "url-gitlab"
URLFlagUsage = "API base URL"
Expand Down
2 changes: 1 addition & 1 deletion internal/wrappers/azure-http.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (g *AzureHTTPWrapper) GetRepositories(url, organizationName, projectName, t
if err != nil {
return rootRepo, err
}
return rootRepo, err
return rootRepo.GetEnabledRepos(), err
}

func (g *AzureHTTPWrapper) GetProjects(url, organizationName, token string) (AzureRootProject, error) {
Expand Down
13 changes: 12 additions & 1 deletion internal/wrappers/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ type AzureRootRepo struct {
Repos []AzureRepo `json:"value,omitempty"`
}

func (a *AzureRootRepo) GetEnabledRepos() AzureRootRepo {
var enabledRepos []AzureRepo
for _, repo := range a.Repos {
if !repo.IsDisabled {
enabledRepos = append(enabledRepos, repo)
}
}
return AzureRootRepo{Repos: enabledRepos}
}

type AzureRepo struct {
Name string `json:"name"`
Name string `json:"name"`
IsDisabled bool `json:"isDisabled"`
}

type AzureRootProject struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/wrappers/mock/azure-mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (g AzureMockWrapper) GetRepositories(url, organizationName, projectName, to
if len(projectName) > 0 {
var repos = make([]wrappers.AzureRepo, 1)
repos[0] = wrappers.AzureRepo{
Name: "MOCK REPO",
Name: "MOCK REPO",
IsDisabled: false,
}
return wrappers.AzureRootRepo{Repos: repos}, nil
}
Expand Down

0 comments on commit 7e6c255

Please sign in to comment.