Skip to content

Commit 7fbdfb0

Browse files
committed
fix: updated models
1 parent 41468bd commit 7fbdfb0

File tree

10 files changed

+1370
-317
lines changed

10 files changed

+1370
-317
lines changed

provider/describer/action_artifact.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/opengovern/og-describer-github/pkg/sdk/models"
77
"github.com/opengovern/og-describer-github/provider/model"
88
"strconv"
9+
"time"
910
)
1011

1112
func GetAllArtifacts(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
@@ -37,20 +38,22 @@ func GetRepositoryArtifacts(ctx context.Context, githubClient GitHubClient, stre
3738
return nil, err
3839
}
3940
for _, artifact := range artifacts.Artifacts {
41+
createdAt := artifact.GetCreatedAt().Format(time.RFC3339)
42+
expiresAt := artifact.GetExpiresAt().Format(time.RFC3339)
4043
value := models.Resource{
4144
ID: strconv.Itoa(int(artifact.GetID())),
4245
Name: artifact.GetName(),
4346
Description: JSONAllFieldsMarshaller{
4447
Value: model.ArtifactDescription{
4548
ID: artifact.GetID(),
46-
NodeID: artifact.GetNodeID(),
47-
Name: artifact.GetName(),
49+
NodeID: artifact.NodeID,
50+
Name: artifact.Name,
4851
SizeInBytes: artifact.GetSizeInBytes(),
49-
ArchiveDownloadURL: artifact.GetArchiveDownloadURL(),
52+
ArchiveDownloadURL: artifact.ArchiveDownloadURL,
5053
Expired: artifact.GetExpired(),
51-
CreatedAt: artifact.GetCreatedAt(),
52-
ExpiresAt: artifact.GetExpiresAt(),
53-
RepoFullName: repoFullName,
54+
CreatedAt: &createdAt,
55+
ExpiresAt: &expiresAt,
56+
RepoFullName: &repoFullName,
5457
},
5558
},
5659
}
@@ -81,20 +84,22 @@ func GetArtifact(ctx context.Context, githubClient GitHubClient, organizationNam
8184
if err != nil {
8285
return nil, err
8386
}
87+
createdAt := artifact.GetCreatedAt().Format(time.RFC3339)
88+
expiresAt := artifact.GetExpiresAt().Format(time.RFC3339)
8489
value := models.Resource{
8590
ID: strconv.Itoa(int(artifact.GetID())),
8691
Name: artifact.GetName(),
8792
Description: JSONAllFieldsMarshaller{
8893
Value: model.ArtifactDescription{
8994
ID: artifact.GetID(),
90-
NodeID: artifact.GetNodeID(),
91-
Name: artifact.GetName(),
95+
NodeID: artifact.NodeID,
96+
Name: artifact.Name,
9297
SizeInBytes: artifact.GetSizeInBytes(),
93-
ArchiveDownloadURL: artifact.GetArchiveDownloadURL(),
98+
ArchiveDownloadURL: artifact.ArchiveDownloadURL,
9499
Expired: artifact.GetExpired(),
95-
CreatedAt: artifact.GetCreatedAt(),
96-
ExpiresAt: artifact.GetExpiresAt(),
97-
RepoFullName: repoFullName,
100+
CreatedAt: &createdAt,
101+
ExpiresAt: &expiresAt,
102+
RepoFullName: &repoFullName,
98103
},
99104
},
100105
}

provider/describer/action_repository_runner.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func GetRepositoryRunners(ctx context.Context, githubClient GitHubClient, stream
3737
return nil, err
3838
}
3939
for _, runner := range runners.Runners {
40+
var labels []*model.RunnerLabels
41+
for _, runnerLabel := range runner.Labels {
42+
labels = append(labels, &model.RunnerLabels{
43+
ID: runnerLabel.ID,
44+
Name: runnerLabel.Name,
45+
Type: runnerLabel.Type,
46+
})
47+
}
4048
value := models.Resource{
4149
ID: strconv.Itoa(int(runner.GetID())),
4250
Name: runner.GetName(),
@@ -47,8 +55,8 @@ func GetRepositoryRunners(ctx context.Context, githubClient GitHubClient, stream
4755
OS: runner.OS,
4856
Status: runner.Status,
4957
Busy: runner.Busy,
50-
Labels: runner.Labels,
51-
RepoFullName: repoFullName,
58+
Labels: labels,
59+
RepoFullName: &repoFullName,
5260
},
5361
},
5462
}
@@ -79,6 +87,14 @@ func GetActionRunner(ctx context.Context, githubClient GitHubClient, organizatio
7987
if err != nil {
8088
return nil, err
8189
}
90+
var labels []*model.RunnerLabels
91+
for _, runnerLabel := range runner.Labels {
92+
labels = append(labels, &model.RunnerLabels{
93+
ID: runnerLabel.ID,
94+
Name: runnerLabel.Name,
95+
Type: runnerLabel.Type,
96+
})
97+
}
8298
value := models.Resource{
8399
ID: strconv.Itoa(int(runner.GetID())),
84100
Name: runner.GetName(),
@@ -89,8 +105,8 @@ func GetActionRunner(ctx context.Context, githubClient GitHubClient, organizatio
89105
OS: runner.OS,
90106
Status: runner.Status,
91107
Busy: runner.Busy,
92-
Labels: runner.Labels,
93-
RepoFullName: repoFullName,
108+
Labels: labels,
109+
RepoFullName: &repoFullName,
94110
},
95111
},
96112
}

provider/describer/action_repository_secret.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ func GetRepositorySecrets(ctx context.Context, githubClient GitHubClient, stream
3939
}
4040
for _, secret := range secrets.Secrets {
4141
id := fmt.Sprintf("%s/%s/%s", owner, repo, secret.Name)
42+
createdAt := secret.CreatedAt.Format(time.RFC3339)
43+
updatedAt := secret.UpdatedAt.Format(time.RFC3339)
4244
value := models.Resource{
4345
ID: id,
4446
Name: secret.Name,
4547
Description: JSONAllFieldsMarshaller{
4648
Value: model.SecretDescription{
47-
Name: secret.Name,
48-
CreatedAt: secret.CreatedAt.Format(time.RFC3339),
49-
UpdatedAt: secret.UpdatedAt.Format(time.RFC3339),
50-
Visibility: secret.Visibility,
51-
SelectedRepositoriesURL: secret.SelectedRepositoriesURL,
52-
RepoFullName: repoFullName,
49+
Name: &secret.Name,
50+
CreatedAt: &createdAt,
51+
UpdatedAt: &updatedAt,
52+
Visibility: &secret.Visibility,
53+
SelectedRepositoriesURL: &secret.SelectedRepositoriesURL,
54+
RepoFullName: &repoFullName,
5355
},
5456
},
5557
}
@@ -77,17 +79,19 @@ func GetRepoActionSecret(ctx context.Context, githubClient GitHubClient, organiz
7779
return nil, err
7880
}
7981
id := fmt.Sprintf("%s/%s/%s", organizationName, repositoryName, secret.Name)
82+
createdAt := secret.CreatedAt.Format(time.RFC3339)
83+
updatedAt := secret.UpdatedAt.Format(time.RFC3339)
8084
value := models.Resource{
8185
ID: id,
8286
Name: secret.Name,
8387
Description: JSONAllFieldsMarshaller{
8488
Value: model.SecretDescription{
85-
Name: secret.Name,
86-
CreatedAt: secret.CreatedAt.Format(time.RFC3339),
87-
UpdatedAt: secret.UpdatedAt.Format(time.RFC3339),
88-
Visibility: secret.Visibility,
89-
SelectedRepositoriesURL: secret.SelectedRepositoriesURL,
90-
RepoFullName: repoFullName,
89+
Name: &secret.Name,
90+
CreatedAt: &createdAt,
91+
UpdatedAt: &updatedAt,
92+
Visibility: &secret.Visibility,
93+
SelectedRepositoriesURL: &secret.SelectedRepositoriesURL,
94+
RepoFullName: &repoFullName,
9195
},
9296
},
9397
}

provider/describer/action_workflow_run.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,14 @@ func GetRepositoryWorkflowRuns(ctx context.Context, sdk *resilientbridge.Resilie
183183
}
184184
runDetail.ArtifactCount = artifactCount
185185
runDetail.Artifacts = artifacts
186+
var name string
187+
if runDetail.Name != nil {
188+
name = *runDetail.Name
189+
}
186190

187191
value := models.Resource{
188192
ID: strconv.Itoa(runDetail.ID),
189-
Name: runDetail.Name,
193+
Name: name,
190194
Description: JSONAllFieldsMarshaller{
191195
Value: runDetail,
192196
},
@@ -441,19 +445,19 @@ func fetchRunDetails(sdk *resilientbridge.ResilientBridge, owner, repo string, r
441445

442446
return model.WorkflowRunDescription{
443447
ID: fullDetail.ID,
444-
Name: fullDetail.Name,
445-
HeadBranch: fullDetail.HeadBranch,
446-
HeadSHA: fullDetail.HeadSHA,
447-
Status: fullDetail.Status,
448-
Conclusion: fullDetail.Conclusion,
449-
HTMLURL: fullDetail.HTMLURL,
448+
Name: &fullDetail.Name,
449+
HeadBranch: &fullDetail.HeadBranch,
450+
HeadSHA: &fullDetail.HeadSHA,
451+
Status: &fullDetail.Status,
452+
Conclusion: &fullDetail.Conclusion,
453+
HTMLURL: &fullDetail.HTMLURL,
450454
WorkflowID: fullDetail.WorkflowID,
451455
RunNumber: fullDetail.RunNumber,
452-
Event: fullDetail.Event,
453-
CreatedAt: fullDetail.CreatedAt,
454-
UpdatedAt: fullDetail.UpdatedAt,
456+
Event: &fullDetail.Event,
457+
CreatedAt: &fullDetail.CreatedAt,
458+
UpdatedAt: &fullDetail.UpdatedAt,
455459
RunAttempt: fullDetail.RunAttempt,
456-
RunStartedAt: fullDetail.RunStartedAt,
460+
RunStartedAt: &fullDetail.RunStartedAt,
457461
Actor: fullDetail.Actor,
458462
HeadCommit: fullDetail.HeadCommit,
459463
Repository: fullDetail.Repository,
@@ -484,5 +488,22 @@ func fetchArtifactsForRun(sdk *resilientbridge.ResilientBridge, owner, repo stri
484488
return 0, nil, fmt.Errorf("error decoding artifacts response: %w", err)
485489
}
486490

487-
return artResp.TotalCount, artResp.Artifacts, nil
491+
var artifacts []model.WorkflowArtifact
492+
493+
for _, artifact := range artResp.Artifacts {
494+
artifacts = append(artifacts, model.WorkflowArtifact{
495+
ID: artifact.ID,
496+
NodeID: &artifact.NodeID,
497+
Name: &artifact.Name,
498+
SizeInBytes: artifact.SizeInBytes,
499+
URL: &artifact.URL,
500+
ArchiveDownloadURL: &artifact.ArchiveDownloadURL,
501+
Expired: artifact.Expired,
502+
CreatedAt: &artifact.CreatedAt,
503+
UpdatedAt: &artifact.UpdatedAt,
504+
ExpiresAt: &artifact.ExpiresAt,
505+
})
506+
}
507+
508+
return artResp.TotalCount, artifacts, nil
488509
}

provider/describer/audit_log.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/google/go-github/v55/github"
66
"github.com/opengovern/og-describer-github/pkg/sdk/models"
77
"github.com/opengovern/og-describer-github/provider/model"
8+
"time"
89
)
910

1011
func GetAllAuditLogs(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
@@ -33,23 +34,31 @@ func GetRepositoryAuditLog(ctx context.Context, githubClient GitHubClient, strea
3334
return nil, err
3435
}
3536
for _, audit := range auditResults {
37+
createdAt := audit.CreatedAt.Format(time.RFC3339)
38+
actorLocation := model.ActorLocation{
39+
CountryCode: audit.ActorLocation.CountryCode,
40+
}
41+
data := model.AuditEntryData{
42+
OldName: audit.Data.OldName,
43+
OldLogin: audit.Data.OldLogin,
44+
}
3645
value := models.Resource{
3746
ID: audit.GetDocumentID(),
3847
Name: audit.GetName(),
3948
Description: JSONAllFieldsMarshaller{
4049
Value: model.AuditLogDescription{
41-
ID: audit.GetDocumentID(),
42-
CreatedAt: audit.GetCreatedAt(),
43-
Organization: org,
44-
Phrase: phrase,
45-
Include: include,
46-
Action: audit.GetAction(),
47-
Actor: audit.GetActor(),
48-
ActorLocation: audit.GetActorLocation(),
49-
Team: audit.GetTeam(),
50-
UserLogin: audit.GetUser(),
51-
Repo: audit.GetRepository(),
52-
Data: audit.GetData(),
50+
ID: audit.DocumentID,
51+
CreatedAt: &createdAt,
52+
Organization: &org,
53+
Phrase: &phrase,
54+
Include: &include,
55+
Action: audit.Action,
56+
Actor: audit.Actor,
57+
ActorLocation: &actorLocation,
58+
Team: audit.Team,
59+
UserLogin: audit.User,
60+
Repo: audit.Repository,
61+
Data: &data,
5362
},
5463
},
5564
}

0 commit comments

Comments
 (0)