Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: github app #360

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Repo struct {
PipelineType sql.NullString `sql:"pipeline_type"`
PreviousName sql.NullString `sql:"previous_name"`
ApproveBuild sql.NullString `sql:"approve_build"`
InstallID sql.NullInt64 `sql:"install_id"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe GithubInstallID? Or SCMMetadata with a JSON field?

}

// Decrypt will manipulate the existing repo hash by
Expand Down Expand Up @@ -206,6 +207,11 @@ func (r *Repo) Nullify() *Repo {
r.ApproveBuild.Valid = false
}

// check if the InstallID field should be false
if r.InstallID.Int64 == 0 {
r.InstallID.Valid = false
}

return r
}

Expand Down Expand Up @@ -235,6 +241,7 @@ func (r *Repo) ToLibrary() *library.Repo {
repo.SetPipelineType(r.PipelineType.String)
repo.SetPreviousName(r.PreviousName.String)
repo.SetApproveBuild(r.ApproveBuild.String)
repo.SetInstallID(r.InstallID.Int64)

return repo
}
Expand Down Expand Up @@ -327,6 +334,7 @@ func RepoFromLibrary(r *library.Repo) *Repo {
PipelineType: sql.NullString{String: r.GetPipelineType(), Valid: true},
PreviousName: sql.NullString{String: r.GetPreviousName(), Valid: true},
ApproveBuild: sql.NullString{String: r.GetApproveBuild(), Valid: true},
InstallID: sql.NullInt64{Int64: r.GetInstallID(), Valid: true},
}

return repo.Nullify()
Expand Down
8 changes: 8 additions & 0 deletions database/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Step struct {
Host sql.NullString `sql:"host"`
Runtime sql.NullString `sql:"runtime"`
Distribution sql.NullString `sql:"distribution"`
CheckID sql.NullInt64 `sql:"check_id"`
ReportAs sql.NullString `sql:"report_as"`
}

Expand Down Expand Up @@ -143,6 +144,11 @@ func (s *Step) Nullify() *Step {
s.Distribution.Valid = false
}

// check if the CheckID field should be false
if s.CheckID.Int64 == 0 {
s.CheckID.Valid = false
}

// check if the ReportAs field should be false
if len(s.ReportAs.String) == 0 {
s.ReportAs.Valid = false
Expand Down Expand Up @@ -172,6 +178,7 @@ func (s *Step) ToLibrary() *library.Step {
step.SetHost(s.Host.String)
step.SetRuntime(s.Runtime.String)
step.SetDistribution(s.Distribution.String)
step.SetCheckID(s.CheckID.Int64)
step.SetReportAs(s.ReportAs.String)

return step
Expand Down Expand Up @@ -241,6 +248,7 @@ func StepFromLibrary(s *library.Step) *Step {
Host: sql.NullString{String: s.GetHost(), Valid: true},
Runtime: sql.NullString{String: s.GetRuntime(), Valid: true},
Distribution: sql.NullString{String: s.GetDistribution(), Valid: true},
CheckID: sql.NullInt64{Int64: s.GetCheckID(), Valid: true},
ReportAs: sql.NullString{String: s.GetReportAs(), Valid: true},
}

Expand Down
30 changes: 30 additions & 0 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Repo struct {
PipelineType *string `json:"pipeline_type,omitempty"`
PreviousName *string `json:"previous_name,omitempty"`
ApproveBuild *string `json:"approve_build,omitempty"`
InstallID *int64 `json:"install_id,omitempty"`
}

// UnmarshalYAML implements the Unmarshaler interface for the Repo type.
Expand Down Expand Up @@ -73,6 +74,7 @@ func (r *Repo) Environment() map[string]string {
"VELA_REPO_VISIBILITY": ToString(r.GetVisibility()),
"VELA_REPO_PIPELINE_TYPE": ToString(r.GetPipelineType()),
"VELA_REPO_APPROVE_BUILD": ToString(r.GetApproveBuild()),
"VELA_REPO_INSTALL_ID": ToString(r.GetInstallID()),

// deprecated environment variables
"REPOSITORY_ACTIVE": ToString(r.GetActive()),
Expand Down Expand Up @@ -363,6 +365,19 @@ func (r *Repo) GetApproveBuild() string {
return *r.ApproveBuild
}

// GetInstallID returns the InstallID field.
//
// When the provided Repo type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Repo) GetInstallID() int64 {
// return zero value if Repo type or InstallID field is nil
if r == nil || r.InstallID == nil {
return 0
}

return *r.InstallID
}

// SetID sets the ID field.
//
// When the provided Repo type is nil, it
Expand Down Expand Up @@ -636,6 +651,19 @@ func (r *Repo) SetApproveBuild(v string) {
r.ApproveBuild = &v
}

// SetInstallID sets the InstallID field.
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetInstallID(v int64) {
// return if Repo type is nil
if r == nil {
return
}

r.InstallID = &v
}

// String implements the Stringer interface for the Repo type.
func (r *Repo) String() string {
return fmt.Sprintf(`{
Expand All @@ -648,6 +676,7 @@ func (r *Repo) String() string {
Counter: %d,
FullName: %s,
ID: %d,
InstallID: %d,
Link: %s,
Name: %s,
Org: %s,
Expand All @@ -669,6 +698,7 @@ func (r *Repo) String() string {
r.GetCounter(),
r.GetFullName(),
r.GetID(),
r.GetInstallID(),
r.GetLink(),
r.GetName(),
r.GetOrg(),
Expand Down
219 changes: 219 additions & 0 deletions library/report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
// SPDX-License-Identifier: Apache-2.0

package library

type Report struct {
Title *string `json:"title,omitempty"`
Summary *string `json:"summary,omitempty"`
Text *string `json:"text,omitempty"`
AnnotationsCount *int `json:"annotations_count,omitempty"`
AnnotationsURL *string `json:"annotations_url,omitempty"`
Annotations []*Annotation `json:"annotations,omitempty"`
}

type Annotation struct {
Path *string `json:"path,omitempty"`
StartLine *int `json:"start_line,omitempty"`
EndLine *int `json:"end_line,omitempty"`
StartColumn *int `json:"start_column,omitempty"`
EndColumn *int `json:"end_column,omitempty"`
AnnotationLevel *string `json:"annotation_level,omitempty"`
Message *string `json:"message,omitempty"`
Title *string `json:"title,omitempty"`
RawDetails *string `json:"raw_details,omitempty"`
}

// GetTitle returns the Title field.
//
// When the provided Report type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Report) GetTitle() string {
// return zero value if Step type or ID field is nil
if r == nil || r.Title == nil {
return ""
}

return *r.Title
}

// GetSummary returns the Summary field.
//
// When the provided Report type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Report) GetSummary() string {
// return zero value if Step type or ID field is nil
if r == nil || r.Summary == nil {
return ""
}

return *r.Summary
}

// GetText returns the Text field.
//
// When the provided Report type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Report) GetText() string {
// return zero value if Step type or ID field is nil
if r == nil || r.Text == nil {
return ""
}

return *r.Text
}

// GetAnnotationsCount returns the AnnotationsCount field.
//
// When the provided Report type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Report) GetAnnotationsCount() int {
// return zero value if Step type or ID field is nil
if r == nil || r.AnnotationsCount == nil {
return 0
}

return *r.AnnotationsCount
}

// GetAnnotationsURL returns the AnnotationsURL field.
//
// When the provided Report type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Report) GetAnnotationsURL() string {
// return zero value if Step type or ID field is nil
if r == nil || r.AnnotationsURL == nil {
return ""
}

return *r.AnnotationsURL
}

// GetAnnotations returns the Annotations field.
//
// When the provided Report type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Report) GetAnnotations() []*Annotation {
// return zero value if Step type or ID field is nil
if r == nil || r.Annotations == nil {
return []*Annotation{}
}

return r.Annotations
}

// GetPath returns the Path field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetPath() string {
// return zero value if Step type or ID field is nil
if a == nil || a.Path == nil {
return ""
}

return *a.Path
}

// GetStartLine returns the StartLine field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetStartLine() int {
// return zero value if Step type or ID field is nil
if a == nil || a.StartLine == nil {
return 0
}

return *a.StartLine
}

// GetEndLine returns the EndLine field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetEndLine() int {
// return zero value if Step type or ID field is nil
if a == nil || a.EndLine == nil {
return 0
}

return *a.EndLine
}

// GetStartColumn returns the StartColumn field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetStartColumn() int {
// return zero value if Step type or ID field is nil
if a == nil || a.StartColumn == nil {
return 0
}

return *a.StartColumn
}

// GetEndColumn returns the EndColumn field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetEndColumn() int {
// return zero value if Step type or ID field is nil
if a == nil || a.EndColumn == nil {
return 0
}

return *a.EndColumn
}

// GetAnnotationLevel returns the AnnotationLevel field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetAnnotationLevel() string {
// return zero value if Step type or ID field is nil
if a == nil || a.AnnotationLevel == nil {
return ""
}

return *a.AnnotationLevel
}

// GetMessage returns the Message field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetMessage() string {
// return zero value if Step type or ID field is nil
if a == nil || a.Message == nil {
return ""
}

return *a.Message
}

// GetTitle returns the Title field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetTitle() string {
// return zero value if Step type or ID field is nil
if a == nil || a.Title == nil {
return ""
}

return *a.Title
}

// GetRawDetails returns the RawDetails field.
//
// When the provided Annotation type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (a *Annotation) GetRawDetails() string {
// return zero value if Step type or ID field is nil
if a == nil || a.RawDetails == nil {
return ""
}

return *a.RawDetails
}
Loading
Loading