From 6b577bcb00f3723cd65448dcf4b447289ed7d959 Mon Sep 17 00:00:00 2001 From: domenicsim1 Date: Tue, 25 Nov 2025 19:02:56 +1100 Subject: [PATCH 1/3] feat: platform hub version control support --- .../resource.go | 90 +++++++++++++++++++ .../service.go | 19 ++++ 2 files changed, 109 insertions(+) create mode 100644 pkg/platformhubversioncontrolsettings/resource.go create mode 100644 pkg/platformhubversioncontrolsettings/service.go diff --git a/pkg/platformhubversioncontrolsettings/resource.go b/pkg/platformhubversioncontrolsettings/resource.go new file mode 100644 index 00000000..74cd3e1e --- /dev/null +++ b/pkg/platformhubversioncontrolsettings/resource.go @@ -0,0 +1,90 @@ +package platformhubversioncontrolsettings + +import ( + "encoding/json" + + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/credentials" +) + +// Resource represents Platform Hub version control settings +type Resource struct { + URL string `json:"Url"` + Credentials credentials.GitCredential `json:"Credentials"` + DefaultBranch string `json:"DefaultBranch"` + BasePath string `json:"BasePath"` +} + +// NewResource creates a new Platform Hub version control settings resource +func NewResource(url string, creds credentials.GitCredential, defaultBranch string, basePath string) *Resource { + return &Resource{ + URL: url, + Credentials: creds, + DefaultBranch: defaultBranch, + BasePath: basePath, + } +} + +// UnmarshalJSON sets the resource to its representation in JSON +func (r *Resource) UnmarshalJSON(b []byte) error { + var fields struct { + URL string `json:"Url"` + DefaultBranch string `json:"DefaultBranch"` + BasePath string `json:"BasePath"` + } + if err := json.Unmarshal(b, &fields); err != nil { + return err + } + + r.URL = fields.URL + r.DefaultBranch = fields.DefaultBranch + r.BasePath = fields.BasePath + + var rawResource map[string]*json.RawMessage + if err := json.Unmarshal(b, &rawResource); err != nil { + return err + } + + var credentialsRaw *json.RawMessage + var credentialsProperties map[string]*json.RawMessage + var credentialType credentials.Type + + if rawResource["Credentials"] != nil { + credentialsValue := rawResource["Credentials"] + + if err := json.Unmarshal(*credentialsValue, &credentialsRaw); err != nil { + return err + } + + if err := json.Unmarshal(*credentialsRaw, &credentialsProperties); err != nil { + return err + } + + if credentialsProperties["Type"] != nil { + t := credentialsProperties["Type"] + json.Unmarshal(*t, &credentialType) + } + } + + switch credentialType { + case credentials.GitCredentialTypeAnonymous: + var anonymousCredential *credentials.Anonymous + if err := json.Unmarshal(*credentialsRaw, &anonymousCredential); err != nil { + return err + } + r.Credentials = anonymousCredential + case credentials.GitCredentialTypeUsernamePassword: + var usernamePasswordCredential *credentials.UsernamePassword + if err := json.Unmarshal(*credentialsRaw, &usernamePasswordCredential); err != nil { + return err + } + r.Credentials = usernamePasswordCredential + case credentials.GitCredentialTypeReference: + var referenceCredential *credentials.Reference + if err := json.Unmarshal(*credentialsRaw, &referenceCredential); err != nil { + return err + } + r.Credentials = referenceCredential + } + + return nil +} diff --git a/pkg/platformhubversioncontrolsettings/service.go b/pkg/platformhubversioncontrolsettings/service.go new file mode 100644 index 00000000..0bb3717e --- /dev/null +++ b/pkg/platformhubversioncontrolsettings/service.go @@ -0,0 +1,19 @@ +package platformhubversioncontrolsettings + +import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient" +) + +const ( + path = "/api/platformhub/versioncontrol" +) + +// Get returns the Platform Hub version control settings. +func Get(client newclient.Client) (*Resource, error) { + return newclient.Get[Resource](client.HttpSession(), path) +} + +// Update modifies the Platform Hub version control settings. +func Update(client newclient.Client, resource *Resource) (*Resource, error) { + return newclient.Put[Resource](client.HttpSession(), path, resource) +} From 0a001d6f3fd3b719b236e40403e08ca539c0466b Mon Sep 17 00:00:00 2001 From: domenicsim1 Date: Wed, 26 Nov 2025 09:52:42 +1100 Subject: [PATCH 2/3] chore: fix tests that is no longer valid for service account --- test/e2e/account_service_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/e2e/account_service_test.go b/test/e2e/account_service_test.go index 10127156..15e721ef 100644 --- a/test/e2e/account_service_test.go +++ b/test/e2e/account_service_test.go @@ -221,8 +221,11 @@ func CreateTestUsernamePasswordAccount(t *testing.T, client *client.Client) acco require.NotNil(t, client) name := internal.GetRandomName() + username := internal.GetRandomName() - account, err := accounts.NewUsernamePasswordAccount(name) + account, err := accounts.NewUsernamePasswordAccount(name, func(a *accounts.UsernamePasswordAccount) { + a.Username = username + }) require.NotNil(t, account) require.NoError(t, err) require.NoError(t, account.Validate()) From cd174335e24a4e57319d6582b235a62b5b53fd80 Mon Sep 17 00:00:00 2001 From: domenicsim1 Date: Wed, 26 Nov 2025 11:10:16 +1100 Subject: [PATCH 3/3] chore: removed GitCredentialTypeReference --- pkg/platformhubversioncontrolsettings/resource.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/platformhubversioncontrolsettings/resource.go b/pkg/platformhubversioncontrolsettings/resource.go index 74cd3e1e..79a4efe5 100644 --- a/pkg/platformhubversioncontrolsettings/resource.go +++ b/pkg/platformhubversioncontrolsettings/resource.go @@ -78,12 +78,6 @@ func (r *Resource) UnmarshalJSON(b []byte) error { return err } r.Credentials = usernamePasswordCredential - case credentials.GitCredentialTypeReference: - var referenceCredential *credentials.Reference - if err := json.Unmarshal(*credentialsRaw, &referenceCredential); err != nil { - return err - } - r.Credentials = referenceCredential } return nil