Skip to content

Commit

Permalink
updating for github
Browse files Browse the repository at this point in the history
  • Loading branch information
acx1729 committed Dec 20, 2024
1 parent 2233aa9 commit 5b048f7
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 1,185 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"makefile.configureOnOpen": false
}
13 changes: 7 additions & 6 deletions command/cmd/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package cmd
import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/google/uuid"
"github.com/opengovern/og-describer-github/pkg/describer"
model "github.com/opengovern/og-describer-github/pkg/sdk/models"
Expand All @@ -14,10 +19,6 @@ import (
"github.com/spf13/cobra"
"go.uber.org/zap"
"golang.org/x/net/context"
"os"
"strconv"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -46,7 +47,7 @@ var describerCmd = &cobra.Command{
IntegrationType: configs.IntegrationTypeLower,
CipherText: "",
IntegrationLabels: map[string]string{
"OrganizationName": OrganizationName,
"OrganizationName": "opengovern",
},
IntegrationAnnotations: nil,
}
Expand All @@ -55,7 +56,7 @@ var describerCmd = &cobra.Command{
logger, _ := zap.NewProduction()

creds, err := provider.AccountCredentialsFromMap(map[string]any{
"pat_token": PatToken,
"pat_token": "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",
})
if err != nil {
return fmt.Errorf(" account credentials: %w", err)
Expand Down
35 changes: 10 additions & 25 deletions provider/describer/action_repository_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,29 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/opengovern/og-describer-github/pkg/sdk/models"
"github.com/opengovern/og-describer-github/provider/model"
resilientbridge "github.com/opengovern/resilient-bridge"
"github.com/opengovern/resilient-bridge/adapters"
"log"
"net/url"
"strconv"
"strings"

"github.com/opengovern/og-describer-github/pkg/sdk/models"
"github.com/opengovern/og-describer-github/provider/model"
resilientbridge "github.com/opengovern/resilient-bridge"
)

func GetAllWorkflowRuns(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
client := githubClient.RestClient
owner := organizationName
repositories, err := getRepositories(ctx, client, owner)
// Retrieve only active (non-archived, non-disabled) repositories
repositories, err := GetRepositoryListWithOptions(ctx, githubClient, organizationName, nil, true, true)
if err != nil {
return nil, nil
return nil, fmt.Errorf("error fetching repositories for workflow runs: %w", err)
}

sdk := resilientbridge.NewResilientBridge()
sdk.RegisterProvider("github", adapters.NewGitHubAdapter(githubClient.Token), &resilientbridge.ProviderConfig{
UseProviderLimits: true,
MaxRetries: 3,
BaseBackoff: 0,
})
sdk := newResilientSDK(githubClient.Token)

var values []models.Resource
for _, repo := range repositories {
active, err := checkRepositoryActive(sdk, owner, repo.GetName())
if err != nil {
log.Fatalf("Error checking repository: %v", err)
}

if !active {
// Repository is archived or disabled, return 0 workflow runs
// No output needed, just exit gracefully.
continue
}
repoValues, err := GetRepositoryWorkflowRuns(ctx, sdk, stream, owner, repo.GetName())
// repo.Name should be the repository name field from the returned resources
repoValues, err := GetRepositoryWorkflowRuns(ctx, sdk, stream, organizationName, repo.Name)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 5b048f7

Please sign in to comment.