Update GitHub CI Visibility status

PATCH https://api.ap1.datadoghq.com/api/v2/ci/github/accountshttps://api.ap2.datadoghq.com/api/v2/ci/github/accountshttps://api.datadoghq.eu/api/v2/ci/github/accountshttps://api.ddog-gov.com/api/v2/ci/github/accountshttps://api.us2.ddog-gov.com/api/v2/ci/github/accountshttps://api.uk1.datadoghq.com/api/v2/ci/github/accountshttps://api.datadoghq.com/api/v2/ci/github/accountshttps://api.us3.datadoghq.com/api/v2/ci/github/accountshttps://api.us5.datadoghq.com/api/v2/ci/github/accounts

Overview

Enable or disable CI Visibility for a GitHub account, one of its repositories, or both in the same request. The account (and, optionally, repository) are identified by name. Account-level and repository-level changes are independent and may both be supplied in the same request. At least one of enabled or repository.enabled must be provided. If the account name matches installations on more than one host, host must be supplied to disambiguate, otherwise a 409 is returned. Returns a 404 if the CI Visibility GitHub integration is not enabled for this organization, or if the given account or repository cannot be found by name. This endpoint requires the ci_provider_settings_write permission.

OAuth apps require the ci_provider_settings_write authorization scope to access this endpoint.

Request

Body Data (required)

Expand All

Field

Type

Description

data [required]

object

Data object for updating a GitHub account's CI Visibility opt-in status.

attributes [required]

object

Attributes for updating a GitHub account's CI Visibility opt-in status. At least one of enabled or repository.enabled must be provided.

account [required]

string

The GitHub account (organization or user) name to update, identified by name.

enabled

boolean

Whether to enable or disable CI Visibility at the account level.

host

string

The GitHub host (github.com or a GHES hostname) the account belongs to. Required to disambiguate when the same account name exists on more than one host.

repository

object

Repository-level opt-in change to apply, identified by name.

enabled [required]

boolean

Whether to enable or disable CI Visibility for this repository.

name [required]

string

The repository name to update.

type [required]

enum

JSON:API type for the GitHub account resource. The value must always be ci_github_account. Allowed enum values: ci_github_account

{
  "data": {
    "attributes": {
      "account": "datadog",
      "enabled": true,
      "host": "github.com",
      "repository": {
        "enabled": true,
        "name": "shopist"
      }
    },
    "type": "ci_github_account"
  }
}

Response

OK

Response object containing a single GitHub account’s CI Visibility opt-in status.

Expand All

Field

Type

Description

data [required]

object

Data object for a GitHub account.

attributes [required]

object

Attributes describing a GitHub account's CI Visibility opt-in status.

account

string

The GitHub account (organization or user) name.

enabled

boolean

Whether CI Visibility is enabled at the account level.

host

string

The GitHub host (github.com or a GitHub Enterprise Server (GHES) hostname) this account belongs to.

repo_count

int64

The number of repositories known for this account.

repositories

[object]

The repositories belonging to this account, with their individual opt-in status.

enabled

boolean

Whether CI Visibility is enabled for this repository.

name

string

The repository name.

id [required]

string

The account's unique identifier, in the form <host>/<account name> (for example github.com/datadog).

type [required]

enum

JSON:API type for the GitHub account resource. The value must always be ci_github_account. Allowed enum values: ci_github_account

{
  "data": {
    "attributes": {
      "account": "datadog",
      "enabled": true,
      "host": "github.com",
      "repo_count": 12,
      "repositories": [
        {
          "enabled": true,
          "name": "shopist"
        }
      ]
    },
    "id": "github.com/datadog",
    "type": "ci_github_account"
  }
}

Bad Request

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Authorized

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Conflict

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Too many requests

API error response.

Expand All

Field

Type

Description

errors [required]

[string]

A list of errors.

{
  "errors": [
    "Bad Request"
  ]
}

Code Example

                  ## default
# 

# Curl command
curl -X PATCH "https://api.ap1.datadoghq.com"https://api.ap2.datadoghq.com"https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.us2.ddog-gov.com"https://api.uk1.datadoghq.com"https://api.datadoghq.com"https://api.us3.datadoghq.com"https://api.us5.datadoghq.com/api/v2/ci/github/accounts" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \ -d @- << EOF { "data": { "attributes": { "account": "datadog", "enabled": true, "host": "github.com", "repository": { "enabled": true, "name": "shopist" } }, "type": "ci_github_account" } } EOF
"""
Update GitHub CI Visibility status returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.ci_visibility_git_hub_accounts_api import CIVisibilityGitHubAccountsApi
from datadog_api_client.v2.model.ci_app_git_hub_account_type import CIAppGitHubAccountType
from datadog_api_client.v2.model.ci_app_git_hub_account_update_request import CIAppGitHubAccountUpdateRequest
from datadog_api_client.v2.model.ci_app_git_hub_account_update_request_attributes import (
    CIAppGitHubAccountUpdateRequestAttributes,
)
from datadog_api_client.v2.model.ci_app_git_hub_account_update_request_data import CIAppGitHubAccountUpdateRequestData
from datadog_api_client.v2.model.ci_app_git_hub_account_update_request_repository import (
    CIAppGitHubAccountUpdateRequestRepository,
)

body = CIAppGitHubAccountUpdateRequest(
    data=CIAppGitHubAccountUpdateRequestData(
        attributes=CIAppGitHubAccountUpdateRequestAttributes(
            account="datadog",
            enabled=True,
            host="github.com",
            repository=CIAppGitHubAccountUpdateRequestRepository(
                enabled=True,
                name="shopist",
            ),
        ),
        type=CIAppGitHubAccountType.CI_GITHUB_ACCOUNT,
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = CIVisibilityGitHubAccountsApi(api_client)
    response = api_instance.update_ci_app_git_hub_account(body=body)

    print(response)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
# Update GitHub CI Visibility status returns "OK" response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::CIVisibilityGitHubAccountsAPI.new

body = DatadogAPIClient::V2::CIAppGitHubAccountUpdateRequest.new({
  data: DatadogAPIClient::V2::CIAppGitHubAccountUpdateRequestData.new({
    attributes: DatadogAPIClient::V2::CIAppGitHubAccountUpdateRequestAttributes.new({
      account: "datadog",
      enabled: true,
      host: "github.com",
      repository: DatadogAPIClient::V2::CIAppGitHubAccountUpdateRequestRepository.new({
        enabled: true,
        name: "shopist",
      }),
    }),
    type: DatadogAPIClient::V2::CIAppGitHubAccountType::CI_GITHUB_ACCOUNT,
  }),
})
p api_instance.update_ci_app_git_hub_account(body)

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
// Update GitHub CI Visibility status returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.CIAppGitHubAccountUpdateRequest{
		Data: datadogV2.CIAppGitHubAccountUpdateRequestData{
			Attributes: datadogV2.CIAppGitHubAccountUpdateRequestAttributes{
				Account: "datadog",
				Enabled: datadog.PtrBool(true),
				Host:    datadog.PtrString("github.com"),
				Repository: &datadogV2.CIAppGitHubAccountUpdateRequestRepository{
					Enabled: true,
					Name:    "shopist",
				},
			},
			Type: datadogV2.CIAPPGITHUBACCOUNTTYPE_CI_GITHUB_ACCOUNT,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewCIVisibilityGitHubAccountsApi(apiClient)
	resp, r, err := api.UpdateCIAppGitHubAccount(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `CIVisibilityGitHubAccountsApi.UpdateCIAppGitHubAccount`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `CIVisibilityGitHubAccountsApi.UpdateCIAppGitHubAccount`:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
// Update GitHub CI Visibility status returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.CiVisibilityGitHubAccountsApi;
import com.datadog.api.client.v2.model.CIAppGitHubAccountResponse;
import com.datadog.api.client.v2.model.CIAppGitHubAccountType;
import com.datadog.api.client.v2.model.CIAppGitHubAccountUpdateRequest;
import com.datadog.api.client.v2.model.CIAppGitHubAccountUpdateRequestAttributes;
import com.datadog.api.client.v2.model.CIAppGitHubAccountUpdateRequestData;
import com.datadog.api.client.v2.model.CIAppGitHubAccountUpdateRequestRepository;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    CiVisibilityGitHubAccountsApi apiInstance = new CiVisibilityGitHubAccountsApi(defaultClient);

    CIAppGitHubAccountUpdateRequest body =
        new CIAppGitHubAccountUpdateRequest()
            .data(
                new CIAppGitHubAccountUpdateRequestData()
                    .attributes(
                        new CIAppGitHubAccountUpdateRequestAttributes()
                            .account("datadog")
                            .enabled(true)
                            .host("github.com")
                            .repository(
                                new CIAppGitHubAccountUpdateRequestRepository()
                                    .enabled(true)
                                    .name("shopist")))
                    .type(CIAppGitHubAccountType.CI_GITHUB_ACCOUNT));

    try {
      CIAppGitHubAccountResponse result = apiInstance.updateCIAppGitHubAccount(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println(
          "Exception when calling CiVisibilityGitHubAccountsApi#updateCIAppGitHubAccount");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
// Update GitHub CI Visibility status returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_ci_visibility_git_hub_accounts::CIVisibilityGitHubAccountsAPI;
use datadog_api_client::datadogV2::model::CIAppGitHubAccountType;
use datadog_api_client::datadogV2::model::CIAppGitHubAccountUpdateRequest;
use datadog_api_client::datadogV2::model::CIAppGitHubAccountUpdateRequestAttributes;
use datadog_api_client::datadogV2::model::CIAppGitHubAccountUpdateRequestData;
use datadog_api_client::datadogV2::model::CIAppGitHubAccountUpdateRequestRepository;

#[tokio::main]
async fn main() {
    let body = CIAppGitHubAccountUpdateRequest::new(CIAppGitHubAccountUpdateRequestData::new(
        CIAppGitHubAccountUpdateRequestAttributes::new("datadog".to_string())
            .enabled(true)
            .host("github.com".to_string())
            .repository(CIAppGitHubAccountUpdateRequestRepository::new(
                true,
                "shopist".to_string(),
            )),
        CIAppGitHubAccountType::CI_GITHUB_ACCOUNT,
    ));
    let configuration = datadog::Configuration::new();
    let api = CIVisibilityGitHubAccountsAPI::with_config(configuration);
    let resp = api.update_ci_app_git_hub_account(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Instructions

First install the library and its dependencies and then save the example to src/main.rs and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
/**
 * Update GitHub CI Visibility status returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
const apiInstance = new v2.CIVisibilityGitHubAccountsApi(configuration);

const params: v2.CIVisibilityGitHubAccountsApiUpdateCIAppGitHubAccountRequest =
  {
    body: {
      data: {
        attributes: {
          account: "datadog",
          enabled: true,
          host: "github.com",
          repository: {
            enabled: true,
            name: "shopist",
          },
        },
        type: "ci_github_account",
      },
    },
  };

apiInstance
  .updateCIAppGitHubAccount(params)
  .then((data: v2.CIAppGitHubAccountResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));

Instructions

First install the library and its dependencies and then save the example to example.ts and run following commands:

    
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"