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

New Pipelines API to give original integrations response without unmarshalling #897

Merged
merged 5 commits into from
Feb 4, 2024
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
- [Get Integration by Id](#get-integration-by-id)
- [Get Integration by Name](#get-integration-by-name)
- [Get All Integrations](#get-all-integrations)
- [Get All Raw Integrations](#get-all-raw-integrations)
- [Delete Integration](#delete-integration)
- [Add Pipeline Source](#add-pipeline-source)
- [Get Recent Pipeline Run Status](#get-recent-pipeline-run-status)
Expand Down Expand Up @@ -2305,6 +2306,12 @@ integration, err := pipelinesManager.GetIntegrationByName("integrationName")
integrations, err := pipelinesManager.GetAllIntegrations()
```
#### Get All Raw Integrations
bhanurp marked this conversation as resolved.
Show resolved Hide resolved
```go
integrations, err := pipelinesManager.GetAllRawIntegrations()
```
#### Delete Integration
```go
Expand Down
7 changes: 4 additions & 3 deletions lifecycle/services/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ type CreateFromBuildsSource struct {
}

type BuildSource struct {
BuildName string `json:"build_name,omitempty"`
BuildNumber string `json:"build_number,omitempty"`
BuildRepository string `json:"build_repository,omitempty"`
BuildName string `json:"build_name,omitempty"`
BuildNumber string `json:"build_number,omitempty"`
BuildRepository string `json:"build_repository,omitempty"`
IncludeDependencies bool `json:"include_dependencies,omitempty"`
}

type CreateFromReleaseBundlesSource struct {
Expand Down
6 changes: 6 additions & 0 deletions pipelines/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func (sm *PipelinesServicesManager) GetAllIntegrations() ([]services.Integration
return integrationsService.GetAllIntegrations()
}

func (sm *PipelinesServicesManager) GetAllRawIntegrations() ([]byte, error) {
integrationsService := services.NewIntegrationsService(sm.client)
integrationsService.ServiceDetails = sm.config.GetServiceDetails()
return integrationsService.GetAllRawIntegrations()
}

func (sm *PipelinesServicesManager) DeleteIntegration(integrationId int) error {
integrationsService := services.NewIntegrationsService(sm.client)
integrationsService.ServiceDetails = sm.config.GetServiceDetails()
Expand Down
16 changes: 13 additions & 3 deletions pipelines/services/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ func (is *IntegrationsService) GetIntegrationByName(name string) (*Integration,
}

func (is *IntegrationsService) GetAllIntegrations() ([]Integration, error) {
rawIntegrations, err := is.GetAllRawIntegrations()
if err != nil {
return nil, err
}
integrations := &[]Integration{}
err = json.Unmarshal(rawIntegrations, integrations)
return *integrations, errorutils.CheckError(err)
}

// GetAllRawIntegrations returns the response returned from integrations api without unmarshalling
// into Integration struct.
func (is *IntegrationsService) GetAllRawIntegrations() ([]byte, error) {
log.Debug("Fetching all integrations...")
httpDetails := is.ServiceDetails.CreateHttpClientDetails()
url := is.ServiceDetails.GetUrl() + integrationsRestApi
Expand All @@ -250,9 +262,7 @@ func (is *IntegrationsService) GetAllIntegrations() ([]Integration, error) {
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil {
return nil, err
}
integrations := &[]Integration{}
err = json.Unmarshal(body, integrations)
return *integrations, errorutils.CheckError(err)
return body, errorutils.CheckError(err)
}

type IntegrationAlreadyExistsError struct {
Expand Down
26 changes: 26 additions & 0 deletions tests/pipelinesintegrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestPipelinesIntegrations(t *testing.T) {
t.Run(services.BitbucketServerName, testCreateBitbucketServerIntegration)
t.Run(services.GitlabName, testCreateGitlabIntegration)
t.Run(services.ArtifactoryName, testCreateArtifactoryIntegration)
t.Run("GetAllIntegrations", getAllIntegrationAndAssert)
}

func testCreateGithubIntegrationAndGetByName(t *testing.T) {
Expand Down Expand Up @@ -104,6 +105,31 @@ func getIntegrationAndAssert(t *testing.T, id int, name, integrationType string)
assert.Equal(t, integrationType, integration.MasterIntegrationName)
}

func getAllIntegrationAndAssert(t *testing.T) {
// Create Artifactory Integration
name := getUniqueIntegrationName(services.ArtifactoryName)
id, err := testsPipelinesIntegrationsService.CreateArtifactoryIntegration(name, testsDummyRtUrl, testsDummyUser, testsDummyApiKey)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, id)

// Create Gitlab Integration
name = getUniqueIntegrationName(services.GitlabName)
gitlabIntegrationId, err := testsPipelinesIntegrationsService.CreateGitlabIntegration(name, testsDummyVcsUrl, testsDummyToken)
if !assert.NoError(t, err) {
return
}
defer deleteIntegrationAndAssert(t, gitlabIntegrationId)

integrations, err := testsPipelinesIntegrationsService.GetAllIntegrations()
if !assert.NoError(t, err) {
return
}
assert.NotNil(t, integrations)
assert.True(t, len(integrations) > 2)
}

func getUniqueIntegrationName(integrationType string) string {
return strings.Join([]string{integrationNamesPrefix, integrationType, getCustomRunId('_')}, "_")
}
Expand Down
Loading