Skip to main content

lib/api/copilot/copilot.ex

# Generated by `mix github.gen` from docs/github-api/api.github.com.json.
# Do not edit by hand; re-run the task instead.

defmodule Noizu.Github.Api.Copilot do
  @moduledoc """
  GitHub `copilot` API.
  """
  import Noizu.Github

  @doc """
  Add teams to the Copilot subscription for an organization

  @see https://docs.github.com/rest/copilot/copilot-user-management#add-teams-to-the-copilot-subscription-for-an-organization
  """
  def add_copilot_seats_for_teams(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/billing/selected_teams"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Add users to the Copilot subscription for an organization

  @see https://docs.github.com/rest/copilot/copilot-user-management#add-users-to-the-copilot-subscription-for-an-organization
  """
  def add_copilot_seats_for_users(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/billing/selected_users"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Add organizations to the enterprise coding agent policy

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#add-organizations-to-the-enterprise-coding-agent-policy
  """
  def add_organizations_to_enterprise_coding_agent_policy(enterprise, body, options \\ nil) do
    url =
      github_base() <> "/enterprises/#{enterprise}/copilot/policies/coding_agent/organizations"

    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove teams from the Copilot subscription for an organization

  @see https://docs.github.com/rest/copilot/copilot-user-management#remove-teams-from-the-copilot-subscription-for-an-organization
  """
  def cancel_copilot_seat_assignment_for_teams(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/billing/selected_teams"
    body = body
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove users from the Copilot subscription for an organization

  @see https://docs.github.com/rest/copilot/copilot-user-management#remove-users-from-the-copilot-subscription-for-an-organization
  """
  def cancel_copilot_seat_assignment_for_users(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/billing/selected_users"
    body = body
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get Copilot content exclusion rules for an organization

  @see https://docs.github.com/rest/copilot/copilot-content-exclusion-management#get-copilot-content-exclusion-rules-for-an-organization
  """
  def copilot_content_exclusion_for_organization(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/content_exclusion"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get Copilot enterprise usage metrics for a specific day

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-enterprise-usage-metrics-for-a-specific-day
  """
  def copilot_enterprise_one_day_usage_metrics(enterprise, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:day, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")

        github_base() <>
          "/enterprises/#{enterprise}/copilot/metrics/reports/enterprise-1-day" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics1DayReport, options)
  end

  @doc """
  Get Copilot enterprise usage metrics

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-enterprise-usage-metrics
  """
  def copilot_enterprise_usage_metrics(enterprise, options \\ nil) do
    url =
      github_base() <>
        "/enterprises/#{enterprise}/copilot/metrics/reports/enterprise-28-day/latest"

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics28DayReport, options)
  end

  @doc """
  Get Copilot enterprise user-teams report for a specific day

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-enterprise-user-teams-report-for-a-specific-day
  """
  def copilot_enterprise_user_teams_one_day_report(enterprise, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:day, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")

        github_base() <>
          "/enterprises/#{enterprise}/copilot/metrics/reports/user-teams-1-day" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics1DayReport, options)
  end

  @doc """
  Get Copilot organization usage metrics for a specific day

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-organization-usage-metrics-for-a-specific-day
  """
  def copilot_organization_one_day_usage_metrics(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:day, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/copilot/metrics/reports/organization-1-day" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics1DayReport, options)
  end

  @doc """
  Get Copilot organization usage metrics

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-organization-usage-metrics
  """
  def copilot_organization_usage_metrics(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/metrics/reports/organization-28-day/latest"
    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics28DayReport, options)
  end

  @doc """
  Get Copilot organization user-teams report for a specific day

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-organization-user-teams-report-for-a-specific-day
  """
  def copilot_organization_user_teams_one_day_report(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:day, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/copilot/metrics/reports/user-teams-1-day" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics1DayReport, options)
  end

  @doc """
  Get Copilot organization users usage metrics for a specific day

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-organization-users-usage-metrics-for-a-specific-day
  """
  def copilot_organization_users_one_day_usage_metrics(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:day, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/copilot/metrics/reports/users-1-day" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics1DayReport, options)
  end

  @doc """
  Get Copilot organization users usage metrics

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-organization-users-usage-metrics
  """
  def copilot_organization_users_usage_metrics(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/metrics/reports/users-28-day/latest"
    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics28DayReport, options)
  end

  @doc """
  Get Copilot users usage metrics for a specific day

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-users-usage-metrics-for-a-specific-day
  """
  def copilot_users_one_day_usage_metrics(enterprise, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:day, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/enterprises/#{enterprise}/copilot/metrics/reports/users-1-day" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics1DayReport, options)
  end

  @doc """
  Get Copilot users usage metrics

  @see https://docs.github.com/rest/copilot/copilot-usage-metrics#get-copilot-users-usage-metrics
  """
  def copilot_users_usage_metrics(enterprise, options \\ nil) do
    url =
      github_base() <> "/enterprises/#{enterprise}/copilot/metrics/reports/users-28-day/latest"

    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotUsageMetrics28DayReport, options)
  end

  @doc """
  Disable a repository for Copilot cloud agent in an organization

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#disable-a-repository-for-copilot-cloud-agent-in-an-organization
  """
  def disable_copilot_coding_agent_for_repository_in_organization(
        org,
        repository_id,
        options \\ nil
      ) do
    url =
      github_base() <>
        "/orgs/#{org}/copilot/coding-agent/permissions/repositories/#{repository_id}"

    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Enable a repository for Copilot cloud agent in an organization

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#enable-a-repository-for-copilot-cloud-agent-in-an-organization
  """
  def enable_copilot_coding_agent_for_repository_in_organization(
        org,
        repository_id,
        body,
        options \\ nil
      ) do
    url =
      github_base() <>
        "/orgs/#{org}/copilot/coding-agent/permissions/repositories/#{repository_id}"

    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get Copilot cloud agent configuration for a repository

  @see https://docs.github.com/rest/copilot/copilot-cloud-agent-management#get-copilot-cloud-agent-configuration-for-a-repository
  """
  def get_copilot_cloud_agent_configuration(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/repos/#{owner}/#{repo}/copilot/cloud-agent/configuration"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get Copilot cloud agent permissions for an organization

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#get-copilot-cloud-agent-permissions-for-an-organization
  """
  def get_copilot_coding_agent_permissions_organization(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/coding-agent/permissions"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get Copilot seat information and settings for an organization

  @see https://docs.github.com/rest/copilot/copilot-user-management#get-copilot-seat-information-and-settings-for-an-organization
  """
  def get_copilot_organization_details(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/billing"
    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotOrganizationDetails, options)
  end

  @doc """
  Get Copilot seat assignment details for a user

  @see https://docs.github.com/rest/copilot/copilot-user-management#get-copilot-seat-assignment-details-for-a-user
  """
  def get_copilot_seat_details_for_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/members/#{username}/copilot"
    body = %{}
    api_call(:get, url, body, Noizu.Github.CopilotSeatDetails, options)
  end

  @doc """
  List repositories enabled for Copilot cloud agent in an organization

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#list-repositories-enabled-for-copilot-cloud-agent-in-an-organization
  """
  def list_copilot_coding_agent_selected_repositories_for_organization(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/copilot/coding-agent/permissions/repositories" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  List all Copilot seat assignments for an organization

  @see https://docs.github.com/rest/copilot/copilot-user-management#list-all-copilot-seat-assignments-for-an-organization
  """
  def list_copilot_seats(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:page, options, nil),
            get_field(:per_page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/copilot/billing/seats" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove organizations from the enterprise coding agent policy

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#remove-organizations-from-the-enterprise-coding-agent-policy
  """
  def remove_organizations_from_enterprise_coding_agent_policy(enterprise, body, options \\ nil) do
    url =
      github_base() <> "/enterprises/#{enterprise}/copilot/policies/coding_agent/organizations"

    body = body
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set Copilot cloud agent permissions for an organization

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#set-copilot-cloud-agent-permissions-for-an-organization
  """
  def set_copilot_coding_agent_permissions_organization(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/coding-agent/permissions"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set selected repositories for Copilot cloud agent in an organization

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#set-selected-repositories-for-copilot-cloud-agent-in-an-organization
  """
  def set_copilot_coding_agent_selected_repositories_for_organization(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/coding-agent/permissions/repositories"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set Copilot content exclusion rules for an organization

  @see https://docs.github.com/rest/copilot/copilot-content-exclusion-management#set-copilot-content-exclusion-rules-for-an-organization
  """
  def set_copilot_content_exclusion_for_organization(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/copilot/content_exclusion"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set the coding agent policy for an enterprise

  @see https://docs.github.com/rest/copilot/copilot-coding-agent-management#set-the-coding-agent-policy-for-an-enterprise
  """
  def set_enterprise_coding_agent_policy(enterprise, body, options \\ nil) do
    url = github_base() <> "/enterprises/#{enterprise}/copilot/policies/coding_agent"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end
end