Skip to content

Commit

Permalink
feat: Add new protos
Browse files Browse the repository at this point in the history
  • Loading branch information
cluttrdev committed May 31, 2024
1 parent 2a9a6b6 commit fc64fd8
Show file tree
Hide file tree
Showing 23 changed files with 3,666 additions and 875 deletions.
92 changes: 64 additions & 28 deletions grpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,25 @@ func (c *Client) MetricsCollector() prometheus.Collector {
return c.metrics
}

func RecordProjects(c *Client, ctx context.Context, data []*typespb.Project) error {
req := &servicepb.RecordProjectsRequest{
func RecordCommits(c *Client, ctx context.Context, data []*typespb.Commit) error {
req := &servicepb.RecordCommitsRequest{
Data: data,
}
_, err := c.stub.RecordProjects(ctx, req /* opts ...grpc.CallOption */)
_, err := c.stub.RecordCommits(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording projects: %w", err)
return fmt.Errorf("error recording commits: %w", err)
}

return nil
}

func RecordPipelines(c *Client, ctx context.Context, data []*typespb.Pipeline) error {
req := &servicepb.RecordPipelinesRequest{
func RecordBridges(c *Client, ctx context.Context, data []*typespb.Bridge) error {
req := &servicepb.RecordBridgesRequest{
Data: data,
}
_, err := c.stub.RecordPipelines(ctx, req /* opts ...grpc.CallOption */)
_, err := c.stub.RecordBridges(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording pipelines: %w", err)
return fmt.Errorf("error recording bridges: %w", err)
}

return nil
Expand All @@ -85,49 +85,61 @@ func RecordJobs(c *Client, ctx context.Context, data []*typespb.Job) error {
return nil
}

func RecordSections(c *Client, ctx context.Context, data []*typespb.Section) error {
req := &servicepb.RecordSectionsRequest{
func RecordMergeRequests(c *Client, ctx context.Context, data []*typespb.MergeRequest) error {
req := &servicepb.RecordMergeRequestsRequest{
Data: data,
}
_, err := c.stub.RecordSections(ctx, req /* opts ...grpc.CallOption */)
_, err := c.stub.RecordMergeRequests(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording sections: %w", err)
return fmt.Errorf("error recording mergerequests: %w", err)
}

return nil
}

func RecordBridges(c *Client, ctx context.Context, data []*typespb.Bridge) error {
req := &servicepb.RecordBridgesRequest{
func RecordMetrics(c *Client, ctx context.Context, data []*typespb.Metric) error {
req := &servicepb.RecordMetricsRequest{
Data: data,
}
_, err := c.stub.RecordBridges(ctx, req /* opts ...grpc.CallOption */)
_, err := c.stub.RecordMetrics(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording brodges: %w", err)
return fmt.Errorf("error recording metrics: %w", err)
}

return nil
}

func RecordTestReports(c *Client, ctx context.Context, data []*typespb.TestReport) error {
req := &servicepb.RecordTestReportsRequest{
func RecordPipelines(c *Client, ctx context.Context, data []*typespb.Pipeline) error {
req := &servicepb.RecordPipelinesRequest{
Data: data,
}
_, err := c.stub.RecordTestReports(ctx, req /* opts ...grpc.CallOption */)
_, err := c.stub.RecordPipelines(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording testreports: %w", err)
return fmt.Errorf("error recording pipelines: %w", err)
}

return nil
}

func RecordTestSuites(c *Client, ctx context.Context, data []*typespb.TestSuite) error {
req := &servicepb.RecordTestSuitesRequest{
func RecordProjects(c *Client, ctx context.Context, data []*typespb.Project) error {
req := &servicepb.RecordProjectsRequest{
Data: data,
}
_, err := c.stub.RecordTestSuites(ctx, req /* opts ...grpc.CallOption */)
_, err := c.stub.RecordProjects(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording testsuites: %w", err)
return fmt.Errorf("error recording projects: %w", err)
}

return nil
}

func RecordSections(c *Client, ctx context.Context, data []*typespb.Section) error {
req := &servicepb.RecordSectionsRequest{
Data: data,
}
_, err := c.stub.RecordSections(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording sections: %w", err)
}

return nil
Expand All @@ -145,13 +157,25 @@ func RecordTestCases(c *Client, ctx context.Context, data []*typespb.TestCase) e
return nil
}

func RecordMetrics(c *Client, ctx context.Context, data []*typespb.Metric) error {
req := &servicepb.RecordMetricsRequest{
func RecordTestReports(c *Client, ctx context.Context, data []*typespb.TestReport) error {
req := &servicepb.RecordTestReportsRequest{
Data: data,
}
_, err := c.stub.RecordMetrics(ctx, req /* opts ...grpc.CallOption */)
_, err := c.stub.RecordTestReports(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording metrics: %w", err)
return fmt.Errorf("error recording testreports: %w", err)
}

return nil
}

func RecordTestSuites(c *Client, ctx context.Context, data []*typespb.TestSuite) error {
req := &servicepb.RecordTestSuitesRequest{
Data: data,
}
_, err := c.stub.RecordTestSuites(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording testsuites: %w", err)
}

return nil
Expand All @@ -168,3 +192,15 @@ func RecordTraces(c *Client, ctx context.Context, data []*typespb.Trace) error {

return nil
}

func RecordUsers(c *Client, ctx context.Context, data []*typespb.User) error {
req := &servicepb.RecordUsersRequest{
Data: data,
}
_, err := c.stub.RecordUsers(ctx, req /* opts ...grpc.CallOption */)
if err != nil {
return fmt.Errorf("error recording users: %w", err)
}

return nil
}
40 changes: 26 additions & 14 deletions internal/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,36 @@ func export[T any](exporter *Exporter, ctx context.Context, data []*T, record re
return errs
}

func (e *Exporter) ExportProjects(ctx context.Context, data []*typespb.Project) error {
return export[typespb.Project](e, ctx, data, grpc_client.RecordProjects)
func (e *Exporter) ExportCommits(ctx context.Context, data []*typespb.Commit) error {
return export[typespb.Commit](e, ctx, data, grpc_client.RecordCommits)
}

func (e *Exporter) ExportPipelines(ctx context.Context, data []*typespb.Pipeline) error {
return export[typespb.Pipeline](e, ctx, data, grpc_client.RecordPipelines)
func (e *Exporter) ExportBridges(ctx context.Context, data []*typespb.Bridge) error {
return export[typespb.Bridge](e, ctx, data, grpc_client.RecordBridges)
}

func (e *Exporter) ExportJobs(ctx context.Context, data []*typespb.Job) error {
return export[typespb.Job](e, ctx, data, grpc_client.RecordJobs)
}

func (e *Exporter) ExportSections(ctx context.Context, data []*typespb.Section) error {
return export[typespb.Section](e, ctx, data, grpc_client.RecordSections)
func (e *Exporter) ExportMergeRequests(ctx context.Context, data []*typespb.MergeRequest) error {
return export[typespb.MergeRequest](e, ctx, data, grpc_client.RecordMergeRequests)
}

func (e *Exporter) ExportBridges(ctx context.Context, data []*typespb.Bridge) error {
return export[typespb.Bridge](e, ctx, data, grpc_client.RecordBridges)
func (e *Exporter) ExportMetrics(ctx context.Context, data []*typespb.Metric) error {
return export[typespb.Metric](e, ctx, data, grpc_client.RecordMetrics)
}

func (e *Exporter) ExportTestReports(ctx context.Context, data []*typespb.TestReport) error {
return export[typespb.TestReport](e, ctx, data, grpc_client.RecordTestReports)
func (e *Exporter) ExportPipelines(ctx context.Context, data []*typespb.Pipeline) error {
return export[typespb.Pipeline](e, ctx, data, grpc_client.RecordPipelines)
}

func (e *Exporter) ExportTestSuites(ctx context.Context, data []*typespb.TestSuite) error {
return export[typespb.TestSuite](e, ctx, data, grpc_client.RecordTestSuites)
func (e *Exporter) ExportProjects(ctx context.Context, data []*typespb.Project) error {
return export[typespb.Project](e, ctx, data, grpc_client.RecordProjects)
}

func (e *Exporter) ExportSections(ctx context.Context, data []*typespb.Section) error {
return export[typespb.Section](e, ctx, data, grpc_client.RecordSections)
}

func (e *Exporter) ExportTestCases(ctx context.Context, data []*typespb.TestCase) error {
Expand All @@ -103,14 +107,22 @@ func (e *Exporter) ExportTestCases(ctx context.Context, data []*typespb.TestCase
return nil
}

func (e *Exporter) ExportMetrics(ctx context.Context, data []*typespb.Metric) error {
return export[typespb.Metric](e, ctx, data, grpc_client.RecordMetrics)
func (e *Exporter) ExportTestReports(ctx context.Context, data []*typespb.TestReport) error {
return export[typespb.TestReport](e, ctx, data, grpc_client.RecordTestReports)
}

func (e *Exporter) ExportTestSuites(ctx context.Context, data []*typespb.TestSuite) error {
return export[typespb.TestSuite](e, ctx, data, grpc_client.RecordTestSuites)
}

func (e *Exporter) ExportTraces(ctx context.Context, data []*typespb.Trace) error {
return export[typespb.Trace](e, ctx, data, grpc_client.RecordTraces)
}

func (e *Exporter) ExportUsers(ctx context.Context, data []*typespb.User) error {
return export[typespb.User](e, ctx, data, grpc_client.RecordUsers)
}

func (e *Exporter) ExportPipelineHierarchy(ctx context.Context, ph *gitlab.PipelineHierarchy) error {
data, err := flattenPipelineHierarchy(ph)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)

func ptr[T any](v T) *T {
func Ptr[T any](v T) *T {
return &v
}

Expand Down
86 changes: 73 additions & 13 deletions internal/gitlab/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,17 @@ func (c *Client) ListPipelineBridges(ctx context.Context, projectID int64, pipel
}

func convertJob(job *gitlab.Job) *typespb.Job {
artifacts := make([]*typespb.JobArtifacts, 0, len(job.Artifacts))
for _, a := range job.Artifacts {
artifacts = append(artifacts, &typespb.JobArtifacts{
Filename: a.Filename,
FileType: a.FileType,
FileFormat: a.FileFormat,
Size: int64(a.Size),
})
}

return &typespb.Job{
// Commit: ConvertCommit(job.Commit),
Id: int64(job.ID),
Name: job.Name,
Pipeline: &typespb.PipelineReference{
Expand All @@ -122,18 +131,69 @@ func convertJob(job *gitlab.Job) *typespb.Job {
Duration: convertDuration(job.Duration),
QueuedDuration: convertDuration(job.QueuedDuration),
Coverage: job.Coverage,
// Artifacts: ?,
// ArtifactsFile: ?,
// Runner: ConvertRunner(job.Runner),
Stage: job.Stage,
Status: job.Status,
AllowFailure: job.AllowFailure,
FailureReason: job.FailureReason,
Tag: job.Tag,
WebUrl: job.WebURL,
TagList: job.TagList,
// Project: ConvertProject(job.Project),
// User: ConvertUser(job.User),
Stage: job.Stage,
Status: job.Status,
AllowFailure: job.AllowFailure,
FailureReason: job.FailureReason,
Tag: job.Tag,
WebUrl: job.WebURL,
TagList: job.TagList,

Commit: convertCommit(job.Commit),
Project: convertProject(job.Project),
User: convertUser(job.User),

Runner: &typespb.JobRunner{
Id: int64(job.Runner.ID),
Name: job.Runner.Name,
Description: job.Runner.Description,
Active: job.Runner.Active,
IsShared: job.Runner.IsShared,
},

Artifacts: artifacts,
ArtifactsFile: &typespb.JobArtifactsFile{
Filename: job.ArtifactsFile.Filename,
Size: int64(job.ArtifactsFile.Size),
},
ArtifactsExpireAt: convertTime(job.ArtifactsExpireAt),
}
}

func convertCommit(commit *gitlab.Commit) *typespb.Commit {
var status string
if commit.Status != nil {
status = string(*commit.Status)
}
return &typespb.Commit{
Id: commit.ID,
ShortId: commit.ShortID,
ParentIds: commit.ParentIDs,
ProjectId: int64(commit.ProjectID),
AuthorName: commit.AuthorName,
AuthorEmail: commit.AuthorEmail,
AuthoredDate: convertTime(commit.AuthoredDate),
CommitterName: commit.CommitterName,
CommitterEmail: commit.CommitterEmail,
CommittedDate: convertTime(commit.CommittedDate),
CreatedAt: convertTime(commit.CreatedAt),
Title: commit.Title,
Message: commit.Message,
Trailers: commit.Trailers,
Stats: convertCommitStats(commit.Stats),
Status: status,
WebUrl: commit.WebURL,
}
}

func convertCommitStats(stats *gitlab.CommitStats) *typespb.CommitStats {
if stats == nil {
return nil
}
return &typespb.CommitStats{
Additions: int64(stats.Additions),
Deletions: int64(stats.Deletions),
Total: int64(stats.Total),
}
}

Expand Down
Loading

0 comments on commit fc64fd8

Please sign in to comment.