Skip to content

Commit

Permalink
SCALRCORE-28034 Add DraftPrRunsEnabled attr to VcsProvider resource
Browse files Browse the repository at this point in the history
[API_BRANCH]
  • Loading branch information
RomanMytsko committed Sep 27, 2023
1 parent 6aa9155 commit 93eaae8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
51 changes: 27 additions & 24 deletions vcs_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ type OAuth struct {

// VcsProvider represents a Scalr IACP VcsProvider.
type VcsProvider struct {
ID string `jsonapi:"primary,vcs-providers"`
Name string `jsonapi:"attr,name"`
Url string `jsonapi:"attr,url"`
VcsType VcsType `jsonapi:"attr,vcs-type"`
AuthType AuthType `jsonapi:"attr,auth-type"`
OAuth *OAuth `jsonapi:"attr,oauth"`
Token *string `jsonapi:"attr,token"`
Username *string `jsonapi:"attr,username"`
IsShared bool `jsonapi:"attr,is-shared"`
ID string `jsonapi:"primary,vcs-providers"`
Name string `jsonapi:"attr,name"`
Url string `jsonapi:"attr,url"`
VcsType VcsType `jsonapi:"attr,vcs-type"`
AuthType AuthType `jsonapi:"attr,auth-type"`
OAuth *OAuth `jsonapi:"attr,oauth"`
Token *string `jsonapi:"attr,token"`
Username *string `jsonapi:"attr,username"`
IsShared bool `jsonapi:"attr,is-shared"`
DraftPrRunsEnabled bool `jsonapi:"attr,draft-pr-runs-enabled"`

// Relations
Environments []*Environment `jsonapi:"relation,environments"`
Expand Down Expand Up @@ -119,15 +120,16 @@ func (s *vcsProviders) List(ctx context.Context, options VcsProvidersListOptions

// VcsProviderCreateOptions represents the options for creating a new vcs provider.
type VcsProviderCreateOptions struct {
ID string `jsonapi:"primary,vcs-providers"`
Name *string `jsonapi:"attr,name"`
VcsType VcsType `jsonapi:"attr,vcs-type"`
AuthType AuthType `jsonapi:"attr,auth-type"`
OAuth *OAuth `jsonapi:"attr,oauth"`
Token string `jsonapi:"attr,token"`
Url *string `jsonapi:"attr,url"`
Username *string `jsonapi:"attr,username"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
ID string `jsonapi:"primary,vcs-providers"`
Name *string `jsonapi:"attr,name"`
VcsType VcsType `jsonapi:"attr,vcs-type"`
AuthType AuthType `jsonapi:"attr,auth-type"`
OAuth *OAuth `jsonapi:"attr,oauth"`
Token string `jsonapi:"attr,token"`
Url *string `jsonapi:"attr,url"`
Username *string `jsonapi:"attr,username"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
DraftPrRunsEnabled *bool `jsonapi:"attr,draft-pr-runs-enabled,omitempty"`

// Relations
Environments []*Environment `jsonapi:"relation,environments,omitempty"`
Expand Down Expand Up @@ -178,12 +180,13 @@ func (s *vcsProviders) Read(ctx context.Context, vcsProviderID string) (*VcsProv
// VcsProviderUpdateOptions represents the options for updating a vcs provider.
type VcsProviderUpdateOptions struct {
// For internal use only!
ID string `jsonapi:"primary,vcs-providers"`
Name *string `jsonapi:"attr,name,omitempty"`
Token *string `jsonapi:"attr,token,omitempty"`
Url *string `jsonapi:"attr,url,omitempty"`
Username *string `jsonapi:"attr,username,omitempty"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
ID string `jsonapi:"primary,vcs-providers"`
Name *string `jsonapi:"attr,name,omitempty"`
Token *string `jsonapi:"attr,token,omitempty"`
Url *string `jsonapi:"attr,url,omitempty"`
Username *string `jsonapi:"attr,username,omitempty"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
DraftPrRunsEnabled *bool `jsonapi:"attr,draft-pr-runs-enabled,omitempty"`

// Relations
Environments []*Environment `jsonapi:"relation,environments"`
Expand Down
11 changes: 7 additions & 4 deletions vcs_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ func TestVcsProvidersCreate(t *testing.T) {

t.Run("with valid options", func(t *testing.T) {
options := VcsProviderCreateOptions{
Name: String("vcs-" + randomString(t)),
VcsType: Github,
AuthType: PersonalToken,
Token: os.Getenv("GITHUB_TOKEN"),
Name: String("vcs-" + randomString(t)),
VcsType: Github,
AuthType: PersonalToken,
Token: os.Getenv("GITHUB_TOKEN"),
DraftPrRunsEnabled: Bool(true),

Environments: []*Environment{envTest},
Account: &Account{ID: defaultAccountID},
Expand All @@ -91,6 +92,7 @@ func TestVcsProvidersCreate(t *testing.T) {
assert.Equal(t, options.VcsType, item.VcsType)
assert.Equal(t, options.AuthType, item.AuthType)
assert.Equal(t, false, item.IsShared)
assert.Equal(t, true, item.DraftPrRunsEnabled)
}
})

Expand All @@ -113,6 +115,7 @@ func TestVcsProvidersCreate(t *testing.T) {
assert.Equal(t, options.VcsType, vcs.VcsType)
assert.Equal(t, options.AuthType, vcs.AuthType)
assert.Equal(t, *options.IsShared, vcs.IsShared)
assert.Equal(t, false, vcs.DraftPrRunsEnabled)

})

Expand Down

0 comments on commit 93eaae8

Please sign in to comment.