pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
pub fn start_copilot_agent_task( &self, input: &StartTask, scope: &TaskScope, ) -> Result<Task, Error>
pub fn start_copilot_agent_task_with_submission( &self, input: &StartTask, scope: &TaskScope, submission: &Submission, ) -> Result<Task, Error>
Sourcepub fn list_my_copilot_agent_tasks(&self) -> Result<TaskList, Error>
pub fn list_my_copilot_agent_tasks(&self) -> Result<TaskList, Error>
The authenticated work user’s recent tasks across every repository. Missing repository names and pull node ids are resolved once per repository, not once per task.
Sourcepub fn get_copilot_agent_task_detail(
&self,
task_id: &str,
subject: Option<Subject>,
) -> Result<TaskDetail, Error>
pub fn get_copilot_agent_task_detail( &self, task_id: &str, subject: Option<Subject>, ) -> Result<TaskDetail, Error>
One task and its sessions, by id, without a repository path.
Source§impl Client
impl Client
Sourcepub fn copilot_api_url(&self) -> Result<String, Error>
pub fn copilot_api_url(&self) -> Result<String, Error>
The Copilot API base for the work account. GraphQL answers it, and the answer is kept for the run, so one process asks once.
Sourcepub fn copilot_agent_session(
&self,
session_id: &str,
) -> Result<CopilotAgentSession, Error>
pub fn copilot_agent_session( &self, session_id: &str, ) -> Result<CopilotAgentSession, Error>
One session document. It carries the pull request number and state the REST task artifact may be missing.
Sourcepub fn copilot_agent_session_log(
&self,
session_id: &str,
max_bytes: usize,
) -> Result<SessionLog, Error>
pub fn copilot_agent_session_log( &self, session_id: &str, max_bytes: usize, ) -> Result<SessionLog, Error>
One session’s log, parsed. max_bytes never goes above
MAX_LOG_BYTES; a log the cap cut says so.
Source§impl Client
impl Client
Sourcepub fn prepare_issue_report(&self, report: PreparedReport) -> ReportPlan
pub fn prepare_issue_report(&self, report: PreparedReport) -> ReportPlan
Resolve credentials in the existing priority, using gh’s active account. Performs no HTTP request and never switches or refreshes an account.
Sourcepub fn submit_issue_report(&self, plan: ReportPlan) -> Result<Outcome, Error>
pub fn submit_issue_report(&self, plan: ReportPlan) -> Result<Outcome, Error>
Consume the review plan. No automatic retry, including parse failures.
Source§impl Client
impl Client
Sourcepub fn bind_read(&self, login: &str) -> Result<BoundRead, Error>
pub fn bind_read(&self, login: &str) -> Result<BoundRead, Error>
Capture one credential and verify that it owns the requested login.
Sourcepub fn new(credentials: Arc<Credentials>) -> Self
pub fn new(credentials: Arc<Credentials>) -> Self
Sourcepub fn agent_search(
&self,
login: &str,
repo: &str,
query: &str,
limit: u32,
) -> Result<Value, Error>
pub fn agent_search( &self, login: &str, repo: &str, query: &str, limit: u32, ) -> Result<Value, Error>
One bounded repository search. Scope is part of the GraphQL repository, so user search text cannot widen it to other repositories.
Sourcepub fn agent_write(
&self,
login: &str,
key: &str,
action: &str,
fields: Value,
) -> Result<Value, Error>
pub fn agent_write( &self, login: &str, key: &str, action: &str, fields: Value, ) -> Result<Value, Error>
Named GraphQL writes, each sent once. Never offers a raw HTTP surface.
Sourcepub fn with_api_url(self, api_url: impl Into<String>) -> Self
pub fn with_api_url(self, api_url: impl Into<String>) -> Self
Sends every request to api_url instead of api.github.com (tests).
Sourcepub fn with_work_account(self, login: Option<String>) -> Self
pub fn with_work_account(self, login: Option<String>) -> Self
Prefer this configured gh account for Copilot work, before EMU detection.
Sourcepub fn accounts(&self) -> Result<GitHubAccounts, Error>
pub fn accounts(&self) -> Result<GitHubAccounts, Error>
The accounts to offer: the signed-in and gh accounts for github.com; but when the token comes from the environment or the config file, the one account that token belongs to (REQ-60).
Examples found in repository?
25fn active_login(client: &Client) -> String {
26 let accounts = match client.accounts() {
27 Ok(accounts) => accounts,
28 Err(error) => {
29 eprintln!("accounts: {error}");
30 std::process::exit(1);
31 }
32 };
33 println!("accounts: {}", accounts.logins.join(", "));
34 let Some(login) = accounts
35 .active
36 .clone()
37 .or_else(|| accounts.logins.first().cloned())
38 else {
39 eprintln!("no account");
40 std::process::exit(1);
41 };
42 println!("active: {login} (short: {})", short_login(&login));
43 login
44}Sourcepub fn viewer_login(&self, login: Option<&str>) -> Result<String, Error>
pub fn viewer_login(&self, login: Option<&str>) -> Result<String, Error>
The login of the token for login (or the default token).
Sourcepub fn work_login(&self) -> Result<String, Error>
pub fn work_login(&self) -> Result<String, Error>
Selects the chosen gh account, else the first enterprise (EMU) login, and verifies that the selected credential really belongs to it. Environment tokens belonging to another account are rejected.
Sourcepub fn credential(
&self,
login: Option<&str>,
) -> Result<Credential, CredentialError>
pub fn credential( &self, login: Option<&str>, ) -> Result<Credential, CredentialError>
The credential for login (REQ-21), for callers that only need to
know whether one exists.
Sourcepub fn section(
&self,
login: &str,
section_id: &str,
repos: Option<&[String]>,
) -> Result<SectionResponse, Error>
pub fn section( &self, login: &str, section_id: &str, repos: Option<&[String]>, ) -> Result<SectionResponse, Error>
One section: up to 50 items, most recently updated first. repos
limits it to those repositories (None: everything the account can
see); a repos_only section without
repositories is empty and sends nothing. Long repository lists run as
several searches in parallel, merged by update time.
Sourcepub fn repositories(
&self,
login: &str,
text: &str,
) -> Result<Vec<GhRepository>, Error>
pub fn repositories( &self, login: &str, text: &str, ) -> Result<Vec<GhRepository>, Error>
Repositories the account can see for text: GitHub’s repository
search, or with no text the account’s own and member repositories,
most recently pushed first. At most 30.
Sourcepub fn sections(
&self,
login: &str,
) -> Vec<(&'static str, Result<SectionResponse, Error>)>
pub fn sections( &self, login: &str, ) -> Vec<(&'static str, Result<SectionResponse, Error>)>
Every section, account-wide, in SECTIONS order, in parallel.
Examples found in repository?
47fn print_sections(client: &Client, login: &str) -> Option<String> {
48 let mut first_pr = None;
49 for (id, result) in client.sections(login) {
50 match result {
51 Ok(section) => {
52 println!(
53 "section {id}: {} items of {}",
54 section.items.len(),
55 section.total
56 );
57 if first_pr.is_none() {
58 first_pr = section
59 .items
60 .iter()
61 .find(|item| item.kind == ItemKind::Pr)
62 .map(|item| item.key.clone());
63 }
64 }
65 Err(error) => println!("section {id}: error: {error}"),
66 }
67 }
68 first_pr
69}Sourcepub fn item(&self, login: &str, key: &str) -> Result<GhItemDetail, Error>
pub fn item(&self, login: &str, key: &str) -> Result<GhItemDetail, Error>
The detail of key (owner/name#number).
Sourcepub fn assignable(
&self,
login: &str,
repo: &str,
) -> Result<AssignableResponse, Error>
pub fn assignable( &self, login: &str, repo: &str, ) -> Result<AssignableResponse, Error>
The people who can be assigned in repo, cached for 10 minutes.
Sourcepub fn review(
&self,
login: &str,
key: &str,
event: ReviewEvent,
body: &str,
) -> Result<GhItemDetail, Error>
pub fn review( &self, login: &str, key: &str, event: ReviewEvent, body: &str, ) -> Result<GhItemDetail, Error>
Approves, requests changes or comments as a review; returns the fresh detail. The body is required except for an approval.
Sourcepub fn default_branch(&self, login: &str, repo: &str) -> Result<String, Error>
pub fn default_branch(&self, login: &str, repo: &str) -> Result<String, Error>
The repository’s default branch, which a cloud agent task branches from when the caller names none.
Sourcepub fn comment(
&self,
login: &str,
key: &str,
body: &str,
) -> Result<GhItemDetail, Error>
pub fn comment( &self, login: &str, key: &str, body: &str, ) -> Result<GhItemDetail, Error>
Comments on an issue or pull request; returns the fresh detail.
Sourcepub fn set_assignees(
&self,
login: &str,
key: &str,
add: &[String],
remove: &[String],
) -> Result<GhItemDetail, Error>
pub fn set_assignees( &self, login: &str, key: &str, add: &[String], remove: &[String], ) -> Result<GhItemDetail, Error>
Adds and removes assignees (at most 10 each, at least one in all); returns the fresh detail.
Sourcepub fn diff(&self, login: &str, key: &str) -> Result<DiffResponse, Error>
pub fn diff(&self, login: &str, key: &str) -> Result<DiffResponse, Error>
A pull request’s changed files, with the merge base as the old side of every patch. Cached per base and head SHA.
Examples found in repository?
71fn print_diff(client: &Client, login: &str, key: Option<&str>) {
72 let Some(key) = key else {
73 println!("diff: no pull request in any section");
74 return;
75 };
76 match client.diff(login, key) {
77 Ok(diff) => println!(
78 "diff: a pull request with {} files of {} (merge base {}…, head {}…)",
79 diff.files.len(),
80 diff.total,
81 &diff.base_sha[..7],
82 &diff.head_sha[..7]
83 ),
84 Err(error) => println!("diff: error: {error}"),
85 }
86}