Skip to content

Commit

Permalink
updating for github repository
Browse files Browse the repository at this point in the history
  • Loading branch information
acx1729 committed Dec 20, 2024
1 parent 05211ce commit f285f85
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
19 changes: 16 additions & 3 deletions command/cmd/describer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// describer.go
package cmd

import (
"context"
"encoding/json"
"fmt"
"os"
Expand All @@ -18,7 +20,6 @@ import (
"github.com/opengovern/og-util/pkg/es"
"github.com/spf13/cobra"
"go.uber.org/zap"
"golang.org/x/net/context"
)

var (
Expand All @@ -31,6 +32,18 @@ var describerCmd = &cobra.Command{
Use: "describer",
Short: "A brief description of your command",
RunE: func(cmd *cobra.Command, args []string) error {
// Environment takes priority
orgEnv := os.Getenv("GITHUB_ORG")
patEnv := os.Getenv("GITHUB_PAT")

if orgEnv != "" {
OrganizationName = orgEnv
}

if patEnv != "" {
PatToken = patEnv
}

// Open the output file
file, err := os.Create(outputFile)
if err != nil {
Expand All @@ -47,7 +60,7 @@ var describerCmd = &cobra.Command{
IntegrationType: configs.IntegrationTypeLower,
CipherText: "",
IntegrationLabels: map[string]string{
"OrganizationName": "opengovern",
"OrganizationName": OrganizationName,
},
IntegrationAnnotations: nil,
}
Expand All @@ -56,7 +69,7 @@ var describerCmd = &cobra.Command{
logger, _ := zap.NewProduction()

creds, err := provider.AccountCredentialsFromMap(map[string]any{
"pat_token": "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",
"pat_token": PatToken,
})
if err != nil {
return fmt.Errorf(" account credentials: %w", err)
Expand Down
19 changes: 17 additions & 2 deletions provider/describer/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,15 @@ func GetRepositoryListWithOptions(
return allResources, nil
}

// GetRepositoryDetail returns details for a given repo
func GetRepositoryDetail(ctx context.Context, githubClient GitHubClient, organizationName, repositoryName string) (*models.Resource, error) {
// GetRepository returns details for a given repo
func GetRepository(
ctx context.Context,
githubClient GitHubClient,
organizationName string,
repositoryName string,
resourceID string,
stream *models.StreamSender,
) (*models.Resource, error) {
sdk := resilientbridge.NewResilientBridge()
sdk.RegisterProvider("github", adapters.NewGitHubAdapter(githubClient.Token), &resilientbridge.ProviderConfig{
UseProviderLimits: true,
Expand Down Expand Up @@ -164,6 +171,14 @@ func GetRepositoryDetail(ctx context.Context, githubClient GitHubClient, organiz
Value: finalDetail,
},
}

// If a stream is provided, send the resource through the stream
if stream != nil {
if err := (*stream)(value); err != nil {
return nil, err
}
}

return &value, nil
}

Expand Down
2 changes: 1 addition & 1 deletion provider/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ var ResourceTypes = map[string]model.ResourceType{
Annotations: map[string]string{},

ListDescriber: DescribeByGithub(describer.GetRepositoryList),
GetDescriber: DescribeSingleByRepo(describer.GetRepositoryDetail),
GetDescriber: DescribeSingleByRepo(describer.GetRepository),
},

"Github/Repository/Collaborator": {
Expand Down

0 comments on commit f285f85

Please sign in to comment.