1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Copilot organization API.
//!
//! See: [GitHub REST API Documentation](https://docs.github.com/en/rest/copilot?apiVersion=2022-11-28)
use std::marker::PhantomData;
use super::*;
#[derive(serde::Serialize)]
pub struct CopilotHandler<'octo, 'r> {
#[serde(skip)]
crab: &'octo Octocrab,
#[serde(skip)]
owner: String,
#[serde(skip)]
_phantom: PhantomData<&'r ()>,
#[serde(skip_serializing_if = "Option::is_none")]
per_page: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
page: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
since: Option<chrono::DateTime<chrono::Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
until: Option<chrono::DateTime<chrono::Utc>>,
}
impl<'octo, 'r> CopilotHandler<'octo, 'r> {
pub fn new(handler: &'r OrgHandler<'octo>) -> Self {
Self {
crab: handler.crab,
owner: handler.owner.clone(),
_phantom: PhantomData,
per_page: None,
page: None,
since: None,
until: None,
}
}
pub(crate) fn new_with_owner(crab: &'octo Octocrab, owner: String) -> Self {
Self {
crab,
owner,
_phantom: PhantomData,
per_page: None,
page: None,
since: None,
until: None,
}
}
/// Results per page (max 100).
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}
/// Page number of the results to fetch.
pub fn page(mut self, page: impl Into<u32>) -> Self {
self.page = Some(page.into());
self
}
/// Show usage metrics since this date.
/// This is a timestamp in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ).
/// Maximum value is 28 days ago.
pub fn since(mut self, since: chrono::DateTime<chrono::Utc>) -> Self {
self.since = Some(since);
self
}
/// Show usage metrics until this date.
/// This is a timestamp in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ) and should not precede the since date if it is passed.
pub fn until(mut self, until: chrono::DateTime<chrono::Utc>) -> Self {
self.until = Some(until);
self
}
/// Retrieve copilot metrics for the entire organization
pub async fn metrics(
self,
) -> crate::Result<Vec<crate::models::orgs_copilot::metrics::CopilotMetrics>> {
let route = format!("/orgs/{org}/copilot/metrics", org = self.owner);
self.crab.get(route, Some(&self)).await
}
/// Retrieve copilot metrics for a specific team within the organization
pub async fn metrics_team<T: ToString>(
self,
team: T,
) -> crate::Result<Vec<crate::models::orgs_copilot::metrics::CopilotMetrics>> {
let route = format!(
"/orgs/{org}/team/{team}/copilot/metrics",
org = self.owner,
team = team.to_string()
);
self.crab.get(route, Some(&self)).await
}
/// Get Copilot seat information and settings for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/copilot/copilot-user-management?apiVersion=2022-11-28#get-copilot-seat-information-and-settings-for-an-organization)
pub async fn billing(
self,
) -> crate::Result<crate::models::orgs_copilot::billing::CopilotBilling> {
let route = format!("/orgs/{org}/copilot/billing", org = self.owner);
self.crab.get(route, Some(&self)).await
}
/// List all Copilot seat assignments for an organization.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/copilot/copilot-user-management?apiVersion=2022-11-28#list-all-copilot-seat-assignments-for-an-organization)
pub async fn billing_seats(
self,
) -> crate::Result<crate::models::orgs_copilot::billing::CopilotBillingSeats> {
let route = format!("/orgs/{org}/copilot/billing/seats", org = self.owner);
self.crab.get(route, Some(&self)).await
}
/// Get Copilot seat assignment details for a user.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/copilot/copilot-user-management?apiVersion=2022-11-28#get-copilot-seat-assignment-details-for-a-user)
pub async fn seat_assignment(
&self,
username: impl AsRef<str>,
) -> crate::Result<crate::models::orgs_copilot::billing::CopilotSeat> {
let route = format!(
"/orgs/{org}/members/{username}/copilot",
org = self.owner,
username = username.as_ref(),
);
self.crab.get(route, None::<&()>).await
}
/// Shortcut for [`Self::seat_assignment`].
///
/// Note: This is an alias for [`seat_assignment`][Self::seat_assignment].
pub async fn get_user_seat(
&self,
username: impl AsRef<str>,
) -> crate::Result<crate::models::orgs_copilot::billing::CopilotSeat> {
self.seat_assignment(username).await
}
/// Perform seat management operations, such as adding or removing seats.
/// These will typically affect your billing and require admin/manage billing permissions.
pub fn manage_seats(&self) -> copilot_seat_manager::CopilotSeatHandler<'octo, 'r> {
copilot_seat_manager::CopilotSeatHandler::new_with_owner(self.crab, self.owner.clone())
}
}