diff --git a/.apigentools-info b/.apigentools-info index e4eda70a844..0b7b0555fe4 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2025-01-15 18:03:16.492918", - "spec_repo_commit": "e54847a1" + "regenerated": "2025-01-15 20:49:24.757373", + "spec_repo_commit": "05535c9b" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2025-01-15 18:03:16.518844", - "spec_repo_commit": "e54847a1" + "regenerated": "2025-01-15 20:49:24.772527", + "spec_repo_commit": "05535c9b" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 77866cbe38e..99af9ddbdb2 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -3382,6 +3382,9 @@ components: env: description: The Datadog environment. type: string + provider_name: + description: The name of the CI provider. By default, this is "custom". + type: string resource: $ref: '#/components/schemas/CIAppCreatePipelineEventRequestAttributesResource' service: diff --git a/api/datadogV2/model_ci_app_create_pipeline_event_request_attributes.go b/api/datadogV2/model_ci_app_create_pipeline_event_request_attributes.go index 9fdc886ffcb..ea258dc44b6 100644 --- a/api/datadogV2/model_ci_app_create_pipeline_event_request_attributes.go +++ b/api/datadogV2/model_ci_app_create_pipeline_event_request_attributes.go @@ -14,6 +14,8 @@ import ( type CIAppCreatePipelineEventRequestAttributes struct { // The Datadog environment. Env *string `json:"env,omitempty"` + // The name of the CI provider. By default, this is "custom". + ProviderName *string `json:"provider_name,omitempty"` // Details of the CI pipeline event. Resource CIAppCreatePipelineEventRequestAttributesResource `json:"resource"` // If the CI provider is SaaS, use this to differentiate between instances. @@ -69,6 +71,34 @@ func (o *CIAppCreatePipelineEventRequestAttributes) SetEnv(v string) { o.Env = &v } +// GetProviderName returns the ProviderName field value if set, zero value otherwise. +func (o *CIAppCreatePipelineEventRequestAttributes) GetProviderName() string { + if o == nil || o.ProviderName == nil { + var ret string + return ret + } + return *o.ProviderName +} + +// GetProviderNameOk returns a tuple with the ProviderName field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *CIAppCreatePipelineEventRequestAttributes) GetProviderNameOk() (*string, bool) { + if o == nil || o.ProviderName == nil { + return nil, false + } + return o.ProviderName, true +} + +// HasProviderName returns a boolean if a field has been set. +func (o *CIAppCreatePipelineEventRequestAttributes) HasProviderName() bool { + return o != nil && o.ProviderName != nil +} + +// SetProviderName gets a reference to the given string and assigns it to the ProviderName field. +func (o *CIAppCreatePipelineEventRequestAttributes) SetProviderName(v string) { + o.ProviderName = &v +} + // GetResource returns the Resource field value. func (o *CIAppCreatePipelineEventRequestAttributes) GetResource() CIAppCreatePipelineEventRequestAttributesResource { if o == nil { @@ -129,6 +159,9 @@ func (o CIAppCreatePipelineEventRequestAttributes) MarshalJSON() ([]byte, error) if o.Env != nil { toSerialize["env"] = o.Env } + if o.ProviderName != nil { + toSerialize["provider_name"] = o.ProviderName + } toSerialize["resource"] = o.Resource if o.Service != nil { toSerialize["service"] = o.Service @@ -143,9 +176,10 @@ func (o CIAppCreatePipelineEventRequestAttributes) MarshalJSON() ([]byte, error) // UnmarshalJSON deserializes the given payload. func (o *CIAppCreatePipelineEventRequestAttributes) UnmarshalJSON(bytes []byte) (err error) { all := struct { - Env *string `json:"env,omitempty"` - Resource *CIAppCreatePipelineEventRequestAttributesResource `json:"resource"` - Service *string `json:"service,omitempty"` + Env *string `json:"env,omitempty"` + ProviderName *string `json:"provider_name,omitempty"` + Resource *CIAppCreatePipelineEventRequestAttributesResource `json:"resource"` + Service *string `json:"service,omitempty"` }{} if err = datadog.Unmarshal(bytes, &all); err != nil { return datadog.Unmarshal(bytes, &o.UnparsedObject) @@ -155,11 +189,12 @@ func (o *CIAppCreatePipelineEventRequestAttributes) UnmarshalJSON(bytes []byte) } additionalProperties := make(map[string]interface{}) if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { - datadog.DeleteKeys(additionalProperties, &[]string{"env", "resource", "service"}) + datadog.DeleteKeys(additionalProperties, &[]string{"env", "provider_name", "resource", "service"}) } else { return err } o.Env = all.Env + o.ProviderName = all.ProviderName o.Resource = *all.Resource o.Service = all.Service diff --git a/examples/v2/ci-visibility-pipelines/CreateCIAppPipelineEvent_819339921.go b/examples/v2/ci-visibility-pipelines/CreateCIAppPipelineEvent_819339921.go new file mode 100644 index 00000000000..594e21d5f2e --- /dev/null +++ b/examples/v2/ci-visibility-pipelines/CreateCIAppPipelineEvent_819339921.go @@ -0,0 +1,55 @@ +// Send pipeline event with custom provider returns "Request accepted for processing" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + body := datadogV2.CIAppCreatePipelineEventRequest{ + Data: &datadogV2.CIAppCreatePipelineEventRequestData{ + Attributes: &datadogV2.CIAppCreatePipelineEventRequestAttributes{ + ProviderName: datadog.PtrString("example-provider"), + Resource: datadogV2.CIAppCreatePipelineEventRequestAttributesResource{ + CIAppPipelineEventPipeline: &datadogV2.CIAppPipelineEventPipeline{ + CIAppPipelineEventFinishedPipeline: &datadogV2.CIAppPipelineEventFinishedPipeline{ + Level: datadogV2.CIAPPPIPELINEEVENTPIPELINELEVEL_PIPELINE, + UniqueId: "3eacb6f3-ff04-4e10-8a9c-46e6d054024a", + Name: "Deploy to AWS", + Url: "https://my-ci-provider.example/pipelines/my-pipeline/run/1", + Start: time.Now().Add(time.Second * -120), + End: time.Now().Add(time.Second * -30), + Status: datadogV2.CIAPPPIPELINEEVENTPIPELINESTATUS_SUCCESS, + PartialRetry: false, + Git: *datadogV2.NewNullableCIAppGitInfo(&datadogV2.CIAppGitInfo{ + RepositoryUrl: "https://github.com/DataDog/datadog-agent", + Sha: "7f263865994b76066c4612fd1965215e7dcb4cd2", + AuthorEmail: "john.doe@email.com", + }), + }}}, + }, + Type: datadogV2.CIAPPCREATEPIPELINEEVENTREQUESTDATATYPE_CIPIPELINE_RESOURCE_REQUEST.Ptr(), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewCIVisibilityPipelinesApi(apiClient) + resp, r, err := api.CreateCIAppPipelineEvent(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `CIVisibilityPipelinesApi.CreateCIAppPipelineEvent`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `CIVisibilityPipelinesApi.CreateCIAppPipelineEvent`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_CI_Visibility_Pipelines/Scenario_Send_pipeline_event_with_custom_provider_returns_Request_accepted_for_processing_response.freeze b/tests/scenarios/cassettes/TestScenarios/v2/Feature_CI_Visibility_Pipelines/Scenario_Send_pipeline_event_with_custom_provider_returns_Request_accepted_for_processing_response.freeze new file mode 100644 index 00000000000..da0b2504134 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_CI_Visibility_Pipelines/Scenario_Send_pipeline_event_with_custom_provider_returns_Request_accepted_for_processing_response.freeze @@ -0,0 +1 @@ +2025-01-08T08:57:29.599Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v2/Feature_CI_Visibility_Pipelines/Scenario_Send_pipeline_event_with_custom_provider_returns_Request_accepted_for_processing_response.yaml b/tests/scenarios/cassettes/TestScenarios/v2/Feature_CI_Visibility_Pipelines/Scenario_Send_pipeline_event_with_custom_provider_returns_Request_accepted_for_processing_response.yaml new file mode 100644 index 00000000000..5726b6efd5e --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v2/Feature_CI_Visibility_Pipelines/Scenario_Send_pipeline_event_with_custom_provider_returns_Request_accepted_for_processing_response.yaml @@ -0,0 +1,22 @@ +interactions: +- request: + body: | + {"data":{"attributes":{"provider_name":"example-provider","resource":{"end":"2025-01-08T08:56:59.599Z","git":{"author_email":"john.doe@email.com","repository_url":"https://github.com/DataDog/datadog-agent","sha":"7f263865994b76066c4612fd1965215e7dcb4cd2"},"level":"pipeline","name":"Deploy to AWS","partial_retry":false,"start":"2025-01-08T08:55:29.599Z","status":"success","unique_id":"3eacb6f3-ff04-4e10-8a9c-46e6d054024a","url":"https://my-ci-provider.example/pipelines/my-pipeline/run/1"}},"type":"cipipeline_resource_request"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v2/ci/pipeline + response: + body: '{"data":null}' + code: 202 + duration: 0ms + headers: + Content-Type: + - application/vnd.api+json + status: 202 Accepted +version: 2 diff --git a/tests/scenarios/features/v2/ci_visibility_pipelines.feature b/tests/scenarios/features/v2/ci_visibility_pipelines.feature index 7f707950723..81bd36d12d5 100644 --- a/tests/scenarios/features/v2/ci_visibility_pipelines.feature +++ b/tests/scenarios/features/v2/ci_visibility_pipelines.feature @@ -108,6 +108,13 @@ Feature: CI Visibility Pipelines When the request is sent Then the response status is 202 Request accepted for processing + @team:Datadog/ci-app-backend + Scenario: Send pipeline event with custom provider returns "Request accepted for processing" response + Given new "CreateCIAppPipelineEvent" request + And body with value {"data": {"attributes": {"provider_name": "example-provider", "resource": {"level": "pipeline","unique_id": "3eacb6f3-ff04-4e10-8a9c-46e6d054024a","name": "Deploy to AWS","url": "https://my-ci-provider.example/pipelines/my-pipeline/run/1","start": "{{ timeISO('now - 120s') }}","end": "{{ timeISO('now - 30s') }}","status": "success","partial_retry": false,"git": {"repository_url": "https://github.com/DataDog/datadog-agent","sha": "7f263865994b76066c4612fd1965215e7dcb4cd2","author_email": "john.doe@email.com"}}},"type": "cipipeline_resource_request"}} + When the request is sent + Then the response status is 202 Request accepted for processing + @skip @team:Datadog/ci-app-backend Scenario: Send pipeline job event returns "Request accepted for processing" response Given new "CreateCIAppPipelineEvent" request