Skip to content

Commit

Permalink
Start POC
Browse files Browse the repository at this point in the history
- Can create a GitHub app client
- Can create a GitHub app installation client
- Installation ID is set when the repository is enabled in Vela
- Clone repository step works with installation access token
  • Loading branch information
wsan3 committed Aug 8, 2024
1 parent d47730b commit f0f4876
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 2 deletions.
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"`
}

// 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
35 changes: 33 additions & 2 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Repo is the library representation of a repo.
//
// Deprecated: use Repo from github.com/go-vela/server/api/types instead.
// swagger:model Repo
type Repo struct {
ID *int64 `json:"id,omitempty"`
UserID *int64 `json:"user_id,omitempty"`
Expand All @@ -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 @@ -340,7 +342,8 @@ func (r *Repo) GetPipelineType() string {
// GetPreviousName returns the PreviousName field.
//
// When the provided Repo type is nil, or the field within
//  the type is nil, it returns the zero value for the field.
//
// the type is nil, it returns the zero value for the field.
func (r *Repo) GetPreviousName() string {
// return zero value if Repo type or PreviousName field is nil
if r == nil || r.PreviousName == nil {
Expand All @@ -363,6 +366,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 +652,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 +677,7 @@ func (r *Repo) String() string {
Counter: %d,
FullName: %s,
ID: %d,
InstallID: %d,
Link: %s,
Name: %s,
Org: %s,
Expand All @@ -669,6 +699,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

0 comments on commit f0f4876

Please sign in to comment.