Skip to content

Commit

Permalink
Merge pull request #14 from opengovern/fix_models_data
Browse files Browse the repository at this point in the history
fix: updated models
  • Loading branch information
mohamadch91 authored Dec 25, 2024
2 parents 41468bd + 7fbdfb0 commit 39f8afd
Show file tree
Hide file tree
Showing 10 changed files with 1,370 additions and 317 deletions.
29 changes: 17 additions & 12 deletions provider/describer/action_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/opengovern/og-describer-github/pkg/sdk/models"
"github.com/opengovern/og-describer-github/provider/model"
"strconv"
"time"
)

func GetAllArtifacts(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
Expand Down Expand Up @@ -37,20 +38,22 @@ func GetRepositoryArtifacts(ctx context.Context, githubClient GitHubClient, stre
return nil, err
}
for _, artifact := range artifacts.Artifacts {
createdAt := artifact.GetCreatedAt().Format(time.RFC3339)
expiresAt := artifact.GetExpiresAt().Format(time.RFC3339)
value := models.Resource{
ID: strconv.Itoa(int(artifact.GetID())),
Name: artifact.GetName(),
Description: JSONAllFieldsMarshaller{
Value: model.ArtifactDescription{
ID: artifact.GetID(),
NodeID: artifact.GetNodeID(),
Name: artifact.GetName(),
NodeID: artifact.NodeID,
Name: artifact.Name,
SizeInBytes: artifact.GetSizeInBytes(),
ArchiveDownloadURL: artifact.GetArchiveDownloadURL(),
ArchiveDownloadURL: artifact.ArchiveDownloadURL,
Expired: artifact.GetExpired(),
CreatedAt: artifact.GetCreatedAt(),
ExpiresAt: artifact.GetExpiresAt(),
RepoFullName: repoFullName,
CreatedAt: &createdAt,
ExpiresAt: &expiresAt,
RepoFullName: &repoFullName,
},
},
}
Expand Down Expand Up @@ -81,20 +84,22 @@ func GetArtifact(ctx context.Context, githubClient GitHubClient, organizationNam
if err != nil {
return nil, err
}
createdAt := artifact.GetCreatedAt().Format(time.RFC3339)
expiresAt := artifact.GetExpiresAt().Format(time.RFC3339)
value := models.Resource{
ID: strconv.Itoa(int(artifact.GetID())),
Name: artifact.GetName(),
Description: JSONAllFieldsMarshaller{
Value: model.ArtifactDescription{
ID: artifact.GetID(),
NodeID: artifact.GetNodeID(),
Name: artifact.GetName(),
NodeID: artifact.NodeID,
Name: artifact.Name,
SizeInBytes: artifact.GetSizeInBytes(),
ArchiveDownloadURL: artifact.GetArchiveDownloadURL(),
ArchiveDownloadURL: artifact.ArchiveDownloadURL,
Expired: artifact.GetExpired(),
CreatedAt: artifact.GetCreatedAt(),
ExpiresAt: artifact.GetExpiresAt(),
RepoFullName: repoFullName,
CreatedAt: &createdAt,
ExpiresAt: &expiresAt,
RepoFullName: &repoFullName,
},
},
}
Expand Down
24 changes: 20 additions & 4 deletions provider/describer/action_repository_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func GetRepositoryRunners(ctx context.Context, githubClient GitHubClient, stream
return nil, err
}
for _, runner := range runners.Runners {
var labels []*model.RunnerLabels
for _, runnerLabel := range runner.Labels {
labels = append(labels, &model.RunnerLabels{
ID: runnerLabel.ID,
Name: runnerLabel.Name,
Type: runnerLabel.Type,
})
}
value := models.Resource{
ID: strconv.Itoa(int(runner.GetID())),
Name: runner.GetName(),
Expand All @@ -47,8 +55,8 @@ func GetRepositoryRunners(ctx context.Context, githubClient GitHubClient, stream
OS: runner.OS,
Status: runner.Status,
Busy: runner.Busy,
Labels: runner.Labels,
RepoFullName: repoFullName,
Labels: labels,
RepoFullName: &repoFullName,
},
},
}
Expand Down Expand Up @@ -79,6 +87,14 @@ func GetActionRunner(ctx context.Context, githubClient GitHubClient, organizatio
if err != nil {
return nil, err
}
var labels []*model.RunnerLabels
for _, runnerLabel := range runner.Labels {
labels = append(labels, &model.RunnerLabels{
ID: runnerLabel.ID,
Name: runnerLabel.Name,
Type: runnerLabel.Type,
})
}
value := models.Resource{
ID: strconv.Itoa(int(runner.GetID())),
Name: runner.GetName(),
Expand All @@ -89,8 +105,8 @@ func GetActionRunner(ctx context.Context, githubClient GitHubClient, organizatio
OS: runner.OS,
Status: runner.Status,
Busy: runner.Busy,
Labels: runner.Labels,
RepoFullName: repoFullName,
Labels: labels,
RepoFullName: &repoFullName,
},
},
}
Expand Down
28 changes: 16 additions & 12 deletions provider/describer/action_repository_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ func GetRepositorySecrets(ctx context.Context, githubClient GitHubClient, stream
}
for _, secret := range secrets.Secrets {
id := fmt.Sprintf("%s/%s/%s", owner, repo, secret.Name)
createdAt := secret.CreatedAt.Format(time.RFC3339)
updatedAt := secret.UpdatedAt.Format(time.RFC3339)
value := models.Resource{
ID: id,
Name: secret.Name,
Description: JSONAllFieldsMarshaller{
Value: model.SecretDescription{
Name: secret.Name,
CreatedAt: secret.CreatedAt.Format(time.RFC3339),
UpdatedAt: secret.UpdatedAt.Format(time.RFC3339),
Visibility: secret.Visibility,
SelectedRepositoriesURL: secret.SelectedRepositoriesURL,
RepoFullName: repoFullName,
Name: &secret.Name,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Visibility: &secret.Visibility,
SelectedRepositoriesURL: &secret.SelectedRepositoriesURL,
RepoFullName: &repoFullName,
},
},
}
Expand Down Expand Up @@ -77,17 +79,19 @@ func GetRepoActionSecret(ctx context.Context, githubClient GitHubClient, organiz
return nil, err
}
id := fmt.Sprintf("%s/%s/%s", organizationName, repositoryName, secret.Name)
createdAt := secret.CreatedAt.Format(time.RFC3339)
updatedAt := secret.UpdatedAt.Format(time.RFC3339)
value := models.Resource{
ID: id,
Name: secret.Name,
Description: JSONAllFieldsMarshaller{
Value: model.SecretDescription{
Name: secret.Name,
CreatedAt: secret.CreatedAt.Format(time.RFC3339),
UpdatedAt: secret.UpdatedAt.Format(time.RFC3339),
Visibility: secret.Visibility,
SelectedRepositoriesURL: secret.SelectedRepositoriesURL,
RepoFullName: repoFullName,
Name: &secret.Name,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Visibility: &secret.Visibility,
SelectedRepositoriesURL: &secret.SelectedRepositoriesURL,
RepoFullName: &repoFullName,
},
},
}
Expand Down
45 changes: 33 additions & 12 deletions provider/describer/action_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,14 @@ func GetRepositoryWorkflowRuns(ctx context.Context, sdk *resilientbridge.Resilie
}
runDetail.ArtifactCount = artifactCount
runDetail.Artifacts = artifacts
var name string
if runDetail.Name != nil {
name = *runDetail.Name
}

value := models.Resource{
ID: strconv.Itoa(runDetail.ID),
Name: runDetail.Name,
Name: name,
Description: JSONAllFieldsMarshaller{
Value: runDetail,
},
Expand Down Expand Up @@ -441,19 +445,19 @@ func fetchRunDetails(sdk *resilientbridge.ResilientBridge, owner, repo string, r

return model.WorkflowRunDescription{
ID: fullDetail.ID,
Name: fullDetail.Name,
HeadBranch: fullDetail.HeadBranch,
HeadSHA: fullDetail.HeadSHA,
Status: fullDetail.Status,
Conclusion: fullDetail.Conclusion,
HTMLURL: fullDetail.HTMLURL,
Name: &fullDetail.Name,
HeadBranch: &fullDetail.HeadBranch,
HeadSHA: &fullDetail.HeadSHA,
Status: &fullDetail.Status,
Conclusion: &fullDetail.Conclusion,
HTMLURL: &fullDetail.HTMLURL,
WorkflowID: fullDetail.WorkflowID,
RunNumber: fullDetail.RunNumber,
Event: fullDetail.Event,
CreatedAt: fullDetail.CreatedAt,
UpdatedAt: fullDetail.UpdatedAt,
Event: &fullDetail.Event,
CreatedAt: &fullDetail.CreatedAt,
UpdatedAt: &fullDetail.UpdatedAt,
RunAttempt: fullDetail.RunAttempt,
RunStartedAt: fullDetail.RunStartedAt,
RunStartedAt: &fullDetail.RunStartedAt,
Actor: fullDetail.Actor,
HeadCommit: fullDetail.HeadCommit,
Repository: fullDetail.Repository,
Expand Down Expand Up @@ -484,5 +488,22 @@ func fetchArtifactsForRun(sdk *resilientbridge.ResilientBridge, owner, repo stri
return 0, nil, fmt.Errorf("error decoding artifacts response: %w", err)
}

return artResp.TotalCount, artResp.Artifacts, nil
var artifacts []model.WorkflowArtifact

for _, artifact := range artResp.Artifacts {
artifacts = append(artifacts, model.WorkflowArtifact{
ID: artifact.ID,
NodeID: &artifact.NodeID,
Name: &artifact.Name,
SizeInBytes: artifact.SizeInBytes,
URL: &artifact.URL,
ArchiveDownloadURL: &artifact.ArchiveDownloadURL,
Expired: artifact.Expired,
CreatedAt: &artifact.CreatedAt,
UpdatedAt: &artifact.UpdatedAt,
ExpiresAt: &artifact.ExpiresAt,
})
}

return artResp.TotalCount, artifacts, nil
}
33 changes: 21 additions & 12 deletions provider/describer/audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/google/go-github/v55/github"
"github.com/opengovern/og-describer-github/pkg/sdk/models"
"github.com/opengovern/og-describer-github/provider/model"
"time"
)

func GetAllAuditLogs(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
Expand Down Expand Up @@ -33,23 +34,31 @@ func GetRepositoryAuditLog(ctx context.Context, githubClient GitHubClient, strea
return nil, err
}
for _, audit := range auditResults {
createdAt := audit.CreatedAt.Format(time.RFC3339)
actorLocation := model.ActorLocation{
CountryCode: audit.ActorLocation.CountryCode,
}
data := model.AuditEntryData{
OldName: audit.Data.OldName,
OldLogin: audit.Data.OldLogin,
}
value := models.Resource{
ID: audit.GetDocumentID(),
Name: audit.GetName(),
Description: JSONAllFieldsMarshaller{
Value: model.AuditLogDescription{
ID: audit.GetDocumentID(),
CreatedAt: audit.GetCreatedAt(),
Organization: org,
Phrase: phrase,
Include: include,
Action: audit.GetAction(),
Actor: audit.GetActor(),
ActorLocation: audit.GetActorLocation(),
Team: audit.GetTeam(),
UserLogin: audit.GetUser(),
Repo: audit.GetRepository(),
Data: audit.GetData(),
ID: audit.DocumentID,
CreatedAt: &createdAt,
Organization: &org,
Phrase: &phrase,
Include: &include,
Action: audit.Action,
Actor: audit.Actor,
ActorLocation: &actorLocation,
Team: audit.Team,
UserLogin: audit.User,
Repo: audit.Repository,
Data: &data,
},
},
}
Expand Down
Loading

0 comments on commit 39f8afd

Please sign in to comment.