Skip to main content

lib/api/orgs/orgs.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.Orgs do
  @moduledoc """
  GitHub `orgs` API.
  """
  import Noizu.Github

  @doc """
  Add a security manager team

  @see https://docs.github.com/rest/orgs/security-managers#add-a-security-manager-team
  """
  def add_security_manager_team(org, team_slug, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/security-managers/teams/#{team_slug}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Assign an organization role to a team

  @see https://docs.github.com/rest/orgs/organization-roles#assign-an-organization-role-to-a-team
  """
  def assign_team_to_org_role(org, team_slug, role_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/organization-roles/teams/#{team_slug}/#{role_id}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Assign an organization role to a user

  @see https://docs.github.com/rest/orgs/organization-roles#assign-an-organization-role-to-a-user
  """
  def assign_user_to_org_role(org, username, role_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/organization-roles/users/#{username}/#{role_id}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Block a user from an organization

  @see https://docs.github.com/rest/orgs/blocking#block-a-user-from-an-organization
  """
  def block_user(org, username, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/blocks/#{username}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Cancel an organization invitation

  @see https://docs.github.com/rest/orgs/members#cancel-an-organization-invitation
  """
  def cancel_invitation(org, invitation_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/invitations/#{invitation_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Check if a user is blocked by an organization

  @see https://docs.github.com/rest/orgs/blocking#check-if-a-user-is-blocked-by-an-organization
  """
  def check_blocked_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/blocks/#{username}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Check organization membership for a user

  @see https://docs.github.com/rest/orgs/members#check-organization-membership-for-a-user
  """
  def check_membership_for_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/members/#{username}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Check public organization membership for a user

  @see https://docs.github.com/rest/orgs/members#check-public-organization-membership-for-a-user
  """
  def check_public_membership_for_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/public_members/#{username}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Convert an organization member to outside collaborator

  @see https://docs.github.com/rest/orgs/outside-collaborators#convert-an-organization-member-to-outside-collaborator
  """
  def convert_member_to_outside_collaborator(org, username, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/outside_collaborators/#{username}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Create an artifact deployment record

  @see https://docs.github.com/rest/orgs/artifact-metadata#create-an-artifact-deployment-record
  """
  def create_artifact_deployment_record(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/artifacts/metadata/deployment-record"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Create artifact metadata storage record

  @see https://docs.github.com/rest/orgs/artifact-metadata#create-artifact-metadata-storage-record
  """
  def create_artifact_storage_record(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/artifacts/metadata/storage-record"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Create an organization invitation

  @see https://docs.github.com/rest/orgs/members#create-an-organization-invitation
  """
  def create_invitation(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/invitations"
    body = body
    api_call(:post, url, body, Noizu.Github.OrganizationInvitation, options)
  end

  @doc """
  Create issue field for an organization

  @see https://docs.github.com/rest/orgs/issue-fields#create-issue-field-for-an-organization
  """
  def create_issue_field(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-fields"
    body = body
    api_call(:post, url, body, Noizu.Github.IssueField, options)
  end

  @doc """
  Create issue type for an organization

  @see https://docs.github.com/rest/orgs/issue-types#create-issue-type-for-an-organization
  """
  def create_issue_type(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-types"
    body = body
    api_call(:post, url, body, Noizu.Github.IssueType, options)
  end

  @doc """
  Create an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#create-an-organization-webhook
  """
  def create_webhook(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks"
    body = body
    api_call(:post, url, body, Noizu.Github.OrgHook, options)
  end

  @doc """
  Create or update a custom property for an organization

  @see https://docs.github.com/rest/orgs/custom-properties#create-or-update-a-custom-property-for-an-organization
  """
  def custom_properties_for_repos_create_or_update_organization_definition(
        org,
        custom_property_name,
        body,
        options \\ nil
      ) do
    url = github_base() <> "/orgs/#{org}/properties/schema/#{custom_property_name}"
    body = body
    api_call(:put, url, body, Noizu.Github.CustomProperty, options)
  end

  @doc """
  Create or update custom properties for an organization

  @see https://docs.github.com/rest/orgs/custom-properties#create-or-update-custom-properties-for-an-organization
  """
  def custom_properties_for_repos_create_or_update_organization_definitions(
        org,
        body,
        options \\ nil
      ) do
    url = github_base() <> "/orgs/#{org}/properties/schema"
    body = body
    api_call(:patch, url, body, Noizu.Github.Collection.CustomProperty, options)
  end

  @doc """
  Create or update custom property values for organization repositories

  @see https://docs.github.com/rest/orgs/custom-properties#create-or-update-custom-property-values-for-organization-repositories
  """
  def custom_properties_for_repos_create_or_update_organization_values(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/properties/values"
    body = body
    api_call(:patch, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove a custom property for an organization

  @see https://docs.github.com/rest/orgs/custom-properties#remove-a-custom-property-for-an-organization
  """
  def custom_properties_for_repos_delete_organization_definition(
        org,
        custom_property_name,
        options \\ nil
      ) do
    url = github_base() <> "/orgs/#{org}/properties/schema/#{custom_property_name}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get a custom property for an organization

  @see https://docs.github.com/rest/orgs/custom-properties#get-a-custom-property-for-an-organization
  """
  def custom_properties_for_repos_get_organization_definition(
        org,
        custom_property_name,
        options \\ nil
      ) do
    url = github_base() <> "/orgs/#{org}/properties/schema/#{custom_property_name}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.CustomProperty, options)
  end

  @doc """
  Get all custom properties for an organization

  @see https://docs.github.com/rest/orgs/custom-properties#get-all-custom-properties-for-an-organization
  """
  def custom_properties_for_repos_get_organization_definitions(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/properties/schema"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.CustomProperty, options)
  end

  @doc """
  List custom property values for organization repositories

  @see https://docs.github.com/rest/orgs/custom-properties#list-custom-property-values-for-organization-repositories
  """
  def custom_properties_for_repos_get_organization_values(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil),
            get_field(:repository_query, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  Delete an organization

  @see https://docs.github.com/rest/orgs/orgs#delete-an-organization
  """
  def delete(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete attestations in bulk

  @see https://docs.github.com/rest/orgs/attestations#delete-attestations-in-bulk
  """
  def delete_attestations_bulk(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/attestations/delete-request"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete attestations by ID

  @see https://docs.github.com/rest/orgs/attestations#delete-attestations-by-id
  """
  def delete_attestations_by_id(org, attestation_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/attestations/#{attestation_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete attestations by subject digest

  @see https://docs.github.com/rest/orgs/attestations#delete-attestations-by-subject-digest
  """
  def delete_attestations_by_subject_digest(org, subject_digest, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/attestations/digest/#{subject_digest}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete issue field for an organization

  @see https://docs.github.com/rest/orgs/issue-fields#delete-issue-field-for-an-organization
  """
  def delete_issue_field(org, issue_field_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-fields/#{issue_field_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete issue type for an organization

  @see https://docs.github.com/rest/orgs/issue-types#delete-issue-type-for-an-organization
  """
  def delete_issue_type(org, issue_type_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-types/#{issue_type_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#delete-an-organization-webhook
  """
  def delete_webhook(org, hook_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Disable a selected repository for immutable releases in an organization

  @see https://docs.github.com/rest/orgs/orgs#disable-a-selected-repository-for-immutable-releases-in-an-organization
  """
  def disable_selected_repository_immutable_releases_organization(
        org,
        repository_id,
        options \\ nil
      ) do
    url =
      github_base() <> "/orgs/#{org}/settings/immutable-releases/repositories/#{repository_id}"

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

  @doc """
  Enable or disable a security feature for an organization

  @see https://docs.github.com/rest/orgs/orgs#enable-or-disable-a-security-feature-for-an-organization
  """
  def enable_or_disable_security_product_on_all_org_repos(
        org,
        security_product,
        enablement,
        body,
        options \\ nil
      ) do
    url = github_base() <> "/orgs/#{org}/#{security_product}/#{enablement}"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Enable a selected repository for immutable releases in an organization

  @see https://docs.github.com/rest/orgs/orgs#enable-a-selected-repository-for-immutable-releases-in-an-organization
  """
  def enable_selected_repository_immutable_releases_organization(
        org,
        repository_id,
        body,
        options \\ nil
      ) do
    url =
      github_base() <> "/orgs/#{org}/settings/immutable-releases/repositories/#{repository_id}"

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

  @doc """
  Get an organization

  @see https://docs.github.com/rest/orgs/orgs#get-an-organization
  """
  def get(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.OrganizationFull, options)
  end

  @doc """
  Get immutable releases settings for an organization

  @see https://docs.github.com/rest/orgs/orgs#get-immutable-releases-settings-for-an-organization
  """
  def get_immutable_releases_settings(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/settings/immutable-releases"
    body = %{}
    api_call(:get, url, body, Noizu.Github.ImmutableReleasesOrganizationSettings, options)
  end

  @doc """
  List selected repositories for immutable releases enforcement

  @see https://docs.github.com/rest/orgs/orgs#list-selected-repositories-for-immutable-releases-enforcement
  """
  def get_immutable_releases_settings_repositories(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}/settings/immutable-releases/repositories" <> qs
      )

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

  @doc """
  Get an organization membership for the authenticated user

  @see https://docs.github.com/rest/orgs/members#get-an-organization-membership-for-the-authenticated-user
  """
  def get_membership_for_authenticated_user(org, options \\ nil) do
    url = github_base() <> "/user/memberships/orgs/#{org}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.OrgMembership, options)
  end

  @doc """
  Get organization membership for a user

  @see https://docs.github.com/rest/orgs/members#get-organization-membership-for-a-user
  """
  def get_membership_for_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/memberships/#{username}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.OrgMembership, options)
  end

  @doc """
  Get an organization role

  @see https://docs.github.com/rest/orgs/organization-roles#get-an-organization-role
  """
  def get_org_role(org, role_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/organization-roles/#{role_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.OrganizationRole, options)
  end

  @doc """
  Get organization ruleset history

  @see https://docs.github.com/rest/orgs/rules#get-organization-ruleset-history
  """
  def get_org_ruleset_history(org, ruleset_id, 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}/rulesets/#{ruleset_id}/history" <> qs
      )

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

  @doc """
  Get organization ruleset version

  @see https://docs.github.com/rest/orgs/rules#get-organization-ruleset-version
  """
  def get_org_ruleset_version(org, ruleset_id, version_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/rulesets/#{ruleset_id}/history/#{version_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.RulesetVersionWithState, options)
  end

  @doc """
  Get an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#get-an-organization-webhook
  """
  def get_webhook(org, hook_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.OrgHook, options)
  end

  @doc """
  Get a webhook configuration for an organization

  @see https://docs.github.com/rest/orgs/webhooks#get-a-webhook-configuration-for-an-organization
  """
  def get_webhook_config_for_org(org, hook_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}/config"
    body = %{}
    api_call(:get, url, body, Noizu.Github.WebhookConfig, options)
  end

  @doc """
  Get a webhook delivery for an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#get-a-webhook-delivery-for-an-organization-webhook
  """
  def get_webhook_delivery(org, hook_id, delivery_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}/deliveries/#{delivery_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.HookDelivery, options)
  end

  @doc """
  List organizations

  @see https://docs.github.com/rest/orgs/orgs#list-organizations
  """
  def list(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:since, options, nil),
            get_field(:per_page, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List app installations for an organization

  @see https://docs.github.com/rest/orgs/orgs#list-app-installations-for-an-organization
  """
  def list_app_installations(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}/installations" <> qs
      )

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

  @doc """
  List artifact deployment records

  @see https://docs.github.com/rest/orgs/artifact-metadata#list-artifact-deployment-records
  """
  def list_artifact_deployment_records(org, subject_digest, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/artifacts/#{subject_digest}/metadata/deployment-records"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  List artifact storage records

  @see https://docs.github.com/rest/orgs/artifact-metadata#list-artifact-storage-records
  """
  def list_artifact_storage_records(org, subject_digest, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/artifacts/#{subject_digest}/metadata/storage-records"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  List attestation repositories

  @see https://docs.github.com/rest/orgs/attestations#list-attestation-repositories
  """
  def list_attestation_repositories(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:before, options, nil),
            get_field(:after, options, nil),
            get_field(:predicate_type, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List attestations

  @see https://docs.github.com/rest/orgs/attestations#list-attestations
  """
  def list_attestations(org, subject_digest, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:before, options, nil),
            get_field(:after, options, nil),
            get_field(:predicate_type, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List attestations by bulk subject digests

  @see https://docs.github.com/rest/orgs/attestations#list-attestations-by-bulk-subject-digests
  """
  def list_attestations_bulk(org, body, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:before, options, nil),
            get_field(:after, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/attestations/bulk-list" <> qs
      )

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

  @doc """
  List users blocked by an organization

  @see https://docs.github.com/rest/orgs/blocking#list-users-blocked-by-an-organization
  """
  def list_blocked_users(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}/blocks" <> qs
      )

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

  @doc """
  List failed organization invitations

  @see https://docs.github.com/rest/orgs/members#list-failed-organization-invitations
  """
  def list_failed_invitations(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}/failed_invitations" <> qs
      )

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

  @doc """
  List organizations for the authenticated user

  @see https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user
  """
  def list_for_authenticated_user(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() <> "/user/orgs" <> qs
      )

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

  @doc """
  List organizations for a user

  @see https://docs.github.com/rest/orgs/orgs#list-organizations-for-a-user
  """
  def list_for_user(username, 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() <> "/users/#{username}/orgs" <> qs
      )

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

  @doc """
  List organization invitation teams

  @see https://docs.github.com/rest/orgs/members#list-organization-invitation-teams
  """
  def list_invitation_teams(org, invitation_id, 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}/invitations/#{invitation_id}/teams" <> qs
      )

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

  @doc """
  List issue fields for an organization

  @see https://docs.github.com/rest/orgs/issue-fields#list-issue-fields-for-an-organization
  """
  def list_issue_fields(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-fields"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.IssueField, options)
  end

  @doc """
  List issue types for an organization

  @see https://docs.github.com/rest/orgs/issue-types#list-issue-types-for-an-organization
  """
  def list_issue_types(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-types"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.IssueType, options)
  end

  @doc """
  List organization members

  @see https://docs.github.com/rest/orgs/members#list-organization-members
  """
  def list_members(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:filter, options, nil),
            get_field(:role, options, nil),
            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}/members" <> qs
      )

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

  @doc """
  List organization memberships for the authenticated user

  @see https://docs.github.com/rest/orgs/members#list-organization-memberships-for-the-authenticated-user
  """
  def list_memberships_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:state, options, nil),
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List teams that are assigned to an organization role

  @see https://docs.github.com/rest/orgs/organization-roles#list-teams-that-are-assigned-to-an-organization-role
  """
  def list_org_role_teams(org, role_id, 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}/organization-roles/#{role_id}/teams" <> qs
      )

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

  @doc """
  List users that are assigned to an organization role

  @see https://docs.github.com/rest/orgs/organization-roles#list-users-that-are-assigned-to-an-organization-role
  """
  def list_org_role_users(org, role_id, 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}/organization-roles/#{role_id}/users" <> qs
      )

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

  @doc """
  Get all organization roles for an organization

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

  @doc """
  List outside collaborators for an organization

  @see https://docs.github.com/rest/orgs/outside-collaborators#list-outside-collaborators-for-an-organization
  """
  def list_outside_collaborators(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:filter, options, nil),
            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}/outside_collaborators" <> qs
      )

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

  @doc """
  List repositories a fine-grained personal access token has access to

  @see https://docs.github.com/rest/orgs/personal-access-tokens#list-repositories-a-fine-grained-personal-access-token-has-access-to
  """
  def list_pat_grant_repositories(org, pat_id, 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}/personal-access-tokens/#{pat_id}/repositories" <> qs
      )

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

  @doc """
  List repositories requested to be accessed by a fine-grained personal access token

  @see https://docs.github.com/rest/orgs/personal-access-tokens#list-repositories-requested-to-be-accessed-by-a-fine-grained-personal-access-token
  """
  def list_pat_grant_request_repositories(org, pat_request_id, 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}/personal-access-token-requests/#{pat_request_id}/repositories" <> qs
      )

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

  @doc """
  List requests to access organization resources with fine-grained personal access tokens

  @see https://docs.github.com/rest/orgs/personal-access-tokens#list-requests-to-access-organization-resources-with-fine-grained-personal-access-tokens
  """
  def list_pat_grant_requests(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil),
            get_field(:sort, options, nil),
            get_field(:direction, options, nil),
            get_field(:owner, options, nil),
            get_field(:repository, options, nil),
            get_field(:permission, options, nil),
            get_field(:last_used_before, options, nil),
            get_field(:last_used_after, options, nil),
            get_field(:token_id, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/personal-access-token-requests" <> qs
      )

    body = %{}

    api_call(
      :get,
      url,
      body,
      Noizu.Github.Collection.OrganizationProgrammaticAccessGrantRequest,
      options
    )
  end

  @doc """
  List fine-grained personal access tokens with access to organization resources

  @see https://docs.github.com/rest/orgs/personal-access-tokens#list-fine-grained-personal-access-tokens-with-access-to-organization-resources
  """
  def list_pat_grants(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil),
            get_field(:sort, options, nil),
            get_field(:direction, options, nil),
            get_field(:owner, options, nil),
            get_field(:repository, options, nil),
            get_field(:permission, options, nil),
            get_field(:last_used_before, options, nil),
            get_field(:last_used_after, options, nil),
            get_field(:token_id, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/orgs/#{org}/personal-access-tokens" <> qs
      )

    body = %{}

    api_call(
      :get,
      url,
      body,
      Noizu.Github.Collection.OrganizationProgrammaticAccessGrant,
      options
    )
  end

  @doc """
  List pending organization invitations

  @see https://docs.github.com/rest/orgs/members#list-pending-organization-invitations
  """
  def list_pending_invitations(org, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil),
            get_field(:role, options, nil),
            get_field(:invitation_source, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List public organization members

  @see https://docs.github.com/rest/orgs/members#list-public-organization-members
  """
  def list_public_members(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}/public_members" <> qs
      )

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

  @doc """
  List security manager teams

  @see https://docs.github.com/rest/orgs/security-managers#list-security-manager-teams
  """
  def list_security_manager_teams(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/security-managers"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.TeamSimple, options)
  end

  @doc """
  List deliveries for an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#list-deliveries-for-an-organization-webhook
  """
  def list_webhook_deliveries(org, hook_id, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:cursor, options, nil),
            get_field(:status, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List organization webhooks

  @see https://docs.github.com/rest/orgs/webhooks#list-organization-webhooks
  """
  def list_webhooks(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}/hooks" <> qs
      )

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

  @doc """
  Ping an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#ping-an-organization-webhook
  """
  def ping_webhook(org, hook_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}/pings"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Redeliver a delivery for an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#redeliver-a-delivery-for-an-organization-webhook
  """
  def redeliver_webhook_delivery(org, hook_id, delivery_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}/deliveries/#{delivery_id}/attempts"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove an organization member

  @see https://docs.github.com/rest/orgs/members#remove-an-organization-member
  """
  def remove_member(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/members/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove organization membership for a user

  @see https://docs.github.com/rest/orgs/members#remove-organization-membership-for-a-user
  """
  def remove_membership_for_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/memberships/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove outside collaborator from an organization

  @see https://docs.github.com/rest/orgs/outside-collaborators#remove-outside-collaborator-from-an-organization
  """
  def remove_outside_collaborator(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/outside_collaborators/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove public organization membership for the authenticated user

  @see https://docs.github.com/rest/orgs/members#remove-public-organization-membership-for-the-authenticated-user
  """
  def remove_public_membership_for_authenticated_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/public_members/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove a security manager team

  @see https://docs.github.com/rest/orgs/security-managers#remove-a-security-manager-team
  """
  def remove_security_manager_team(org, team_slug, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/security-managers/teams/#{team_slug}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Review a request to access organization resources with a fine-grained personal access token

  @see https://docs.github.com/rest/orgs/personal-access-tokens#review-a-request-to-access-organization-resources-with-a-fine-grained-personal-access-token
  """
  def review_pat_grant_request(org, pat_request_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/personal-access-token-requests/#{pat_request_id}"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Review requests to access organization resources with fine-grained personal access tokens

  @see https://docs.github.com/rest/orgs/personal-access-tokens#review-requests-to-access-organization-resources-with-fine-grained-personal-access-tokens
  """
  def review_pat_grant_requests_in_bulk(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/personal-access-token-requests"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove all organization roles for a team

  @see https://docs.github.com/rest/orgs/organization-roles#remove-all-organization-roles-for-a-team
  """
  def revoke_all_org_roles_team(org, team_slug, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/organization-roles/teams/#{team_slug}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove all organization roles for a user

  @see https://docs.github.com/rest/orgs/organization-roles#remove-all-organization-roles-for-a-user
  """
  def revoke_all_org_roles_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/organization-roles/users/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove an organization role from a team

  @see https://docs.github.com/rest/orgs/organization-roles#remove-an-organization-role-from-a-team
  """
  def revoke_org_role_team(org, team_slug, role_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/organization-roles/teams/#{team_slug}/#{role_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove an organization role from a user

  @see https://docs.github.com/rest/orgs/organization-roles#remove-an-organization-role-from-a-user
  """
  def revoke_org_role_user(org, username, role_id, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/organization-roles/users/#{username}/#{role_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set cluster deployment records

  @see https://docs.github.com/rest/orgs/artifact-metadata#set-cluster-deployment-records
  """
  def set_cluster_deployment_records(org, cluster, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/artifacts/metadata/deployment-record/cluster/#{cluster}"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set immutable releases settings for an organization

  @see https://docs.github.com/rest/orgs/orgs#set-immutable-releases-settings-for-an-organization
  """
  def set_immutable_releases_settings(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/settings/immutable-releases"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set selected repositories for immutable releases enforcement

  @see https://docs.github.com/rest/orgs/orgs#set-selected-repositories-for-immutable-releases-enforcement
  """
  def set_immutable_releases_settings_repositories(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/settings/immutable-releases/repositories"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set organization membership for a user

  @see https://docs.github.com/rest/orgs/members#set-organization-membership-for-a-user
  """
  def set_membership_for_user(org, username, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/memberships/#{username}"
    body = body
    api_call(:put, url, body, Noizu.Github.OrgMembership, options)
  end

  @doc """
  Set public organization membership for the authenticated user

  @see https://docs.github.com/rest/orgs/members#set-public-organization-membership-for-the-authenticated-user
  """
  def set_public_membership_for_authenticated_user(org, username, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/public_members/#{username}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Unblock a user from an organization

  @see https://docs.github.com/rest/orgs/blocking#unblock-a-user-from-an-organization
  """
  def unblock_user(org, username, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/blocks/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Update an organization

  @see https://docs.github.com/rest/orgs/orgs#update-an-organization
  """
  def update(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}"
    body = body
    api_call(:patch, url, body, Noizu.Github.OrganizationFull, options)
  end

  @doc """
  Update issue field for an organization

  @see https://docs.github.com/rest/orgs/issue-fields#update-issue-field-for-an-organization
  """
  def update_issue_field(org, issue_field_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-fields/#{issue_field_id}"
    body = body
    api_call(:patch, url, body, Noizu.Github.IssueField, options)
  end

  @doc """
  Update issue type for an organization

  @see https://docs.github.com/rest/orgs/issue-types#update-issue-type-for-an-organization
  """
  def update_issue_type(org, issue_type_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/issue-types/#{issue_type_id}"
    body = body
    api_call(:put, url, body, Noizu.Github.IssueType, options)
  end

  @doc """
  Update an organization membership for the authenticated user

  @see https://docs.github.com/rest/orgs/members#update-an-organization-membership-for-the-authenticated-user
  """
  def update_membership_for_authenticated_user(org, body, options \\ nil) do
    url = github_base() <> "/user/memberships/orgs/#{org}"
    body = body
    api_call(:patch, url, body, Noizu.Github.OrgMembership, options)
  end

  @doc """
  Update the access a fine-grained personal access token has to organization resources

  @see https://docs.github.com/rest/orgs/personal-access-tokens#update-the-access-a-fine-grained-personal-access-token-has-to-organization-resources
  """
  def update_pat_access(org, pat_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/personal-access-tokens/#{pat_id}"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Update the access to organization resources via fine-grained personal access tokens

  @see https://docs.github.com/rest/orgs/personal-access-tokens#update-the-access-to-organization-resources-via-fine-grained-personal-access-tokens
  """
  def update_pat_accesses(org, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/personal-access-tokens"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Update an organization webhook

  @see https://docs.github.com/rest/orgs/webhooks#update-an-organization-webhook
  """
  def update_webhook(org, hook_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}"
    body = body
    api_call(:patch, url, body, Noizu.Github.OrgHook, options)
  end

  @doc """
  Update a webhook configuration for an organization

  @see https://docs.github.com/rest/orgs/webhooks#update-a-webhook-configuration-for-an-organization
  """
  def update_webhook_config_for_org(org, hook_id, body, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/hooks/#{hook_id}/config"
    body = body
    api_call(:patch, url, body, Noizu.Github.WebhookConfig, options)
  end
end