Skip to main content

lib/api/agent_tasks/agent_tasks.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.AgentTasks do
  @moduledoc """
  GitHub `agent-tasks` API.
  """
  import Noizu.Github

  @doc """
  Start a task

  @see https://docs.github.com/rest/agent-tasks/agent-tasks#start-a-task
  """
  def create_task_in_repo(body, options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/agents/repos/#{owner}/#{repo}/tasks"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get a task by ID

  @see https://docs.github.com/rest/agent-tasks/agent-tasks#get-a-task-by-id
  """
  def get_task_by_id(task_id, options \\ nil) do
    url = github_base() <> "/agents/tasks/#{task_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get a task by repo

  @see https://docs.github.com/rest/agent-tasks/agent-tasks#get-a-task-by-repo
  """
  def get_task_by_repo_and_id(task_id, options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/agents/repos/#{owner}/#{repo}/tasks/#{task_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  List tasks

  @see https://docs.github.com/rest/agent-tasks/agent-tasks#list-tasks
  """
  def list_tasks(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(:state, options, nil),
            get_field(:is_archived, options, nil),
            get_field(:since, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List tasks for repository

  @see https://docs.github.com/rest/agent-tasks/agent-tasks#list-tasks-for-repository
  """
  def list_tasks_for_repo(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)

    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(:state, options, nil),
            get_field(:is_archived, options, nil),
            get_field(:since, options, nil),
            get_field(:creator_id, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/agents/repos/#{owner}/#{repo}/tasks" <> qs
      )

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