Skip to content

Commit

Permalink
feat: updated repository, commit, team and deleted some other resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ArshiaBP committed Dec 21, 2024
1 parent 1b251fc commit 986e1eb
Show file tree
Hide file tree
Showing 21 changed files with 805 additions and 1,187 deletions.
742 changes: 172 additions & 570 deletions pkg/sdk/es/resources_clients.go

Large diffs are not rendered by default.

File renamed without changes.
44 changes: 25 additions & 19 deletions provider/describer/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"strconv"
"strings"
"sync"

"github.com/opengovern/og-describer-github/pkg/sdk/models"
Expand All @@ -21,7 +22,11 @@ import (
// Otherwise, commits are collected and returned as a slice.
func ListCommits(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
// Retrieve repositories while excluding archived and disabled ones
repos, err := GetRepositoryListWithOptions(ctx, githubClient, organizationName, nil, true, true)
//repos, err := GetRepositoryListWithOptions(ctx, githubClient, organizationName, nil, true, true)
//if err != nil {
// return nil, err
//}
repos, err := getRepositories(ctx, githubClient.RestClient, organizationName)
if err != nil {
return nil, err
}
Expand All @@ -31,7 +36,7 @@ func ListCommits(ctx context.Context, githubClient GitHubClient, organizationNam
var values []models.Resource
for _, r := range repos {
// r.Name should correspond to the repository name
repoValues, err := GetRepositoryCommits(ctx, sdk, stream, organizationName, r.Name)
repoValues, err := GetRepositoryCommits(ctx, sdk, stream, organizationName, r.GetName())
if err != nil {
return nil, err
}
Expand All @@ -47,10 +52,18 @@ func GetRepositoryCommits(ctx context.Context, sdk *resilientbridge.ResilientBri
maxCommits := 10
commits, err := fetchCommitList(sdk, owner, repo, maxCommits)
if err != nil {
if strings.Contains(err.Error(), "client error: 409") {
return []models.Resource{}, nil
}
return nil, fmt.Errorf("error fetching commits list for %s/%s: %w", owner, repo, err)
}

// Determine concurrency level from env or default to 5
if len(commits) == 0 {
log.Printf("No commits found for %s/%s (possibly empty default branch).", owner, repo)
return nil, nil
}

// Determine concurrency level from env or default to 3
concurrency := 3
if cStr := os.Getenv("CONCURRENCY"); cStr != "" {
if cVal, err := strconv.Atoi(cStr); err == nil && cVal > 0 {
Expand Down Expand Up @@ -82,10 +95,9 @@ func GetRepositoryCommits(ctx context.Context, sdk *resilientbridge.ResilientBri
log.Printf("Error unmarshaling JSON for commit %s: %v", j.sha, err)
continue
}

value := models.Resource{
ID: commit.ID,
Name: commit.ID,
ID: commit.SHA,
Name: commit.SHA,
Description: JSONAllFieldsMarshaller{
Value: commit,
},
Expand All @@ -106,22 +118,16 @@ func GetRepositoryCommits(ctx context.Context, sdk *resilientbridge.ResilientBri

wg.Wait()

if stream != nil {
for _, res := range results {
if res.ID == "" {
continue
}
if err := (*stream)(res); err != nil {
return nil, err
}
}
return nil, nil
}

var finalResults []models.Resource
for _, res := range results {
if res.ID != "" {
finalResults = append(finalResults, res)
if stream != nil {
if err := (*stream)(res); err != nil {
return nil, err
}
} else {
finalResults = append(finalResults, res)
}
}
}
return finalResults, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
)

func GetTeamList(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
func GetOrganizationTeamList(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
client := githubClient.GraphQLClient
var query struct {
RateLimit steampipemodels.RateLimit
Expand Down
Loading

0 comments on commit 986e1eb

Please sign in to comment.