//! Method, error and parameter types for the Billing endpoint.
#![allow(
clippy::all
)]
/*
* GitHub v3 REST API
*
* GitHub's v3 REST API.
*
* OpenAPI spec version: 1.1.4
*
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
use serde::Deserialize;
use roctokit::adapters::{AdapterError, Client, GitHubRequest, GitHubResponseExt};
use crate::models::*;
use super::PerPage;
use std::collections::HashMap;
use serde_json::value::Value;
pub struct Billing<'api, C: Client> where AdapterError: From<<C as Client>::Err> {
client: &'api C
}
pub fn new<C: Client>(client: &C) -> Billing<C> where AdapterError: From<<C as Client>::Err> {
Billing { client }
}
/// Errors for the [Get GitHub Actions billing for an organization](Billing::get_github_actions_billing_org_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetGithubActionsBillingOrgError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetGithubActionsBillingOrgError> for AdapterError {
fn from(err: BillingGetGithubActionsBillingOrgError) -> Self {
let (description, status_code) = match err {
BillingGetGithubActionsBillingOrgError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get GitHub Actions billing for a user](Billing::get_github_actions_billing_user_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetGithubActionsBillingUserError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetGithubActionsBillingUserError> for AdapterError {
fn from(err: BillingGetGithubActionsBillingUserError) -> Self {
let (description, status_code) = match err {
BillingGetGithubActionsBillingUserError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get billing usage report for an organization](Billing::get_github_billing_usage_report_org_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetGithubBillingUsageReportOrgError {
#[error("Bad Request")]
Status400(BasicError),
#[error("Forbidden")]
Status403(BasicError),
#[error("Internal Error")]
Status500(BasicError),
#[error("Service unavailable")]
Status503(GetBillingGetGithubBillingUsageReportUserResponse503),
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetGithubBillingUsageReportOrgError> for AdapterError {
fn from(err: BillingGetGithubBillingUsageReportOrgError) -> Self {
let (description, status_code) = match err {
BillingGetGithubBillingUsageReportOrgError::Status400(_) => (String::from("Bad Request"), 400),
BillingGetGithubBillingUsageReportOrgError::Status403(_) => (String::from("Forbidden"), 403),
BillingGetGithubBillingUsageReportOrgError::Status500(_) => (String::from("Internal Error"), 500),
BillingGetGithubBillingUsageReportOrgError::Status503(_) => (String::from("Service unavailable"), 503),
BillingGetGithubBillingUsageReportOrgError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get billing usage report for a user](Billing::get_github_billing_usage_report_user_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetGithubBillingUsageReportUserError {
#[error("Bad Request")]
Status400(BasicError),
#[error("Forbidden")]
Status403(BasicError),
#[error("Internal Error")]
Status500(BasicError),
#[error("Service unavailable")]
Status503(GetBillingGetGithubBillingUsageReportUserResponse503),
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetGithubBillingUsageReportUserError> for AdapterError {
fn from(err: BillingGetGithubBillingUsageReportUserError) -> Self {
let (description, status_code) = match err {
BillingGetGithubBillingUsageReportUserError::Status400(_) => (String::from("Bad Request"), 400),
BillingGetGithubBillingUsageReportUserError::Status403(_) => (String::from("Forbidden"), 403),
BillingGetGithubBillingUsageReportUserError::Status500(_) => (String::from("Internal Error"), 500),
BillingGetGithubBillingUsageReportUserError::Status503(_) => (String::from("Service unavailable"), 503),
BillingGetGithubBillingUsageReportUserError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get GitHub Packages billing for an organization](Billing::get_github_packages_billing_org_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetGithubPackagesBillingOrgError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetGithubPackagesBillingOrgError> for AdapterError {
fn from(err: BillingGetGithubPackagesBillingOrgError) -> Self {
let (description, status_code) = match err {
BillingGetGithubPackagesBillingOrgError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get GitHub Packages billing for a user](Billing::get_github_packages_billing_user_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetGithubPackagesBillingUserError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetGithubPackagesBillingUserError> for AdapterError {
fn from(err: BillingGetGithubPackagesBillingUserError) -> Self {
let (description, status_code) = match err {
BillingGetGithubPackagesBillingUserError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get shared storage billing for an organization](Billing::get_shared_storage_billing_org_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetSharedStorageBillingOrgError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetSharedStorageBillingOrgError> for AdapterError {
fn from(err: BillingGetSharedStorageBillingOrgError) -> Self {
let (description, status_code) = match err {
BillingGetSharedStorageBillingOrgError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get shared storage billing for a user](Billing::get_shared_storage_billing_user_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum BillingGetSharedStorageBillingUserError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<BillingGetSharedStorageBillingUserError> for AdapterError {
fn from(err: BillingGetSharedStorageBillingUserError) -> Self {
let (description, status_code) = match err {
BillingGetSharedStorageBillingUserError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Query parameters for the [Get billing usage report for an organization](Billing::get_github_billing_usage_report_org_async()) endpoint.
#[derive(Default, Serialize)]
pub struct BillingGetGithubBillingUsageReportOrgParams {
/// If specified, only return results for a single year. The value of `year` is an integer with four digits representing a year. For example, `2025`. Default value is the current year.
year: Option<i32>,
/// If specified, only return results for a single month. The value of `month` is an integer between `1` and `12`. If no year is specified the default `year` is used.
month: Option<i32>,
/// If specified, only return results for a single day. The value of `day` is an integer between `1` and `31`. If no `year` or `month` is specified, the default `year` and `month` are used.
day: Option<i32>,
/// If specified, only return results for a single hour. The value of `hour` is an integer between `0` and `23`. If no `year`, `month`, or `day` is specified, the default `year`, `month`, and `day` are used.
hour: Option<i32>
}
impl BillingGetGithubBillingUsageReportOrgParams {
pub fn new() -> Self {
Self::default()
}
/// If specified, only return results for a single year. The value of `year` is an integer with four digits representing a year. For example, `2025`. Default value is the current year.
pub fn year(self, year: i32) -> Self {
Self {
year: Some(year),
month: self.month,
day: self.day,
hour: self.hour,
}
}
/// If specified, only return results for a single month. The value of `month` is an integer between `1` and `12`. If no year is specified the default `year` is used.
pub fn month(self, month: i32) -> Self {
Self {
year: self.year,
month: Some(month),
day: self.day,
hour: self.hour,
}
}
/// If specified, only return results for a single day. The value of `day` is an integer between `1` and `31`. If no `year` or `month` is specified, the default `year` and `month` are used.
pub fn day(self, day: i32) -> Self {
Self {
year: self.year,
month: self.month,
day: Some(day),
hour: self.hour,
}
}
/// If specified, only return results for a single hour. The value of `hour` is an integer between `0` and `23`. If no `year`, `month`, or `day` is specified, the default `year`, `month`, and `day` are used.
pub fn hour(self, hour: i32) -> Self {
Self {
year: self.year,
month: self.month,
day: self.day,
hour: Some(hour),
}
}
}
/// Query parameters for the [Get billing usage report for a user](Billing::get_github_billing_usage_report_user_async()) endpoint.
#[derive(Default, Serialize)]
pub struct BillingGetGithubBillingUsageReportUserParams {
/// If specified, only return results for a single year. The value of `year` is an integer with four digits representing a year. For example, `2025`. Default value is the current year.
year: Option<i32>,
/// If specified, only return results for a single month. The value of `month` is an integer between `1` and `12`. If no year is specified the default `year` is used.
month: Option<i32>,
/// If specified, only return results for a single day. The value of `day` is an integer between `1` and `31`. If no `year` or `month` is specified, the default `year` and `month` are used.
day: Option<i32>,
/// If specified, only return results for a single hour. The value of `hour` is an integer between `0` and `23`. If no `year`, `month`, or `day` is specified, the default `year`, `month`, and `day` are used.
hour: Option<i32>
}
impl BillingGetGithubBillingUsageReportUserParams {
pub fn new() -> Self {
Self::default()
}
/// If specified, only return results for a single year. The value of `year` is an integer with four digits representing a year. For example, `2025`. Default value is the current year.
pub fn year(self, year: i32) -> Self {
Self {
year: Some(year),
month: self.month,
day: self.day,
hour: self.hour,
}
}
/// If specified, only return results for a single month. The value of `month` is an integer between `1` and `12`. If no year is specified the default `year` is used.
pub fn month(self, month: i32) -> Self {
Self {
year: self.year,
month: Some(month),
day: self.day,
hour: self.hour,
}
}
/// If specified, only return results for a single day. The value of `day` is an integer between `1` and `31`. If no `year` or `month` is specified, the default `year` and `month` are used.
pub fn day(self, day: i32) -> Self {
Self {
year: self.year,
month: self.month,
day: Some(day),
hour: self.hour,
}
}
/// If specified, only return results for a single hour. The value of `hour` is an integer between `0` and `23`. If no `year`, `month`, or `day` is specified, the default `year`, `month`, and `day` are used.
pub fn hour(self, hour: i32) -> Self {
Self {
year: self.year,
month: self.month,
day: self.day,
hour: Some(hour),
}
}
}
impl<'api, C: Client> Billing<'api, C> where AdapterError: From<<C as Client>::Err> {
/// ---
///
/// # Get GitHub Actions billing for an organization
///
/// Gets the summary of the free and paid GitHub Actions minutes used.
///
/// Paid minutes only apply to workflows in private repositories that use GitHub-hosted runners. Minutes used is listed for each GitHub-hosted runner operating system. Any job re-runs are also included in the usage. The usage returned includes any minute multipliers for macOS and Windows runners, and is rounded up to the nearest whole minute. For more information, see "[Managing billing for GitHub Actions](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-actions)".
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` or `admin:org` scope to use this endpoint.
///
/// [GitHub API docs for get_github_actions_billing_org](https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-an-organization)
///
/// ---
pub async fn get_github_actions_billing_org_async(&self, org: &str) -> Result<ActionsBillingUsage, AdapterError> {
let request_uri = format!("{}/orgs/{}/settings/billing/actions", super::GITHUB_BASE_API_URL, org);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubActionsBillingOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get GitHub Actions billing for an organization
///
/// Gets the summary of the free and paid GitHub Actions minutes used.
///
/// Paid minutes only apply to workflows in private repositories that use GitHub-hosted runners. Minutes used is listed for each GitHub-hosted runner operating system. Any job re-runs are also included in the usage. The usage returned includes any minute multipliers for macOS and Windows runners, and is rounded up to the nearest whole minute. For more information, see "[Managing billing for GitHub Actions](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-actions)".
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` or `admin:org` scope to use this endpoint.
///
/// [GitHub API docs for get_github_actions_billing_org](https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-an-organization)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_github_actions_billing_org(&self, org: &str) -> Result<ActionsBillingUsage, AdapterError> {
let request_uri = format!("{}/orgs/{}/settings/billing/actions", super::GITHUB_BASE_API_URL, org);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubActionsBillingOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get GitHub Actions billing for a user
///
/// Gets the summary of the free and paid GitHub Actions minutes used.
///
/// Paid minutes only apply to workflows in private repositories that use GitHub-hosted runners. Minutes used is listed for each GitHub-hosted runner operating system. Any job re-runs are also included in the usage. The usage returned includes any minute multipliers for macOS and Windows runners, and is rounded up to the nearest whole minute. For more information, see "[Managing billing for GitHub Actions](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-actions)".
///
/// OAuth app tokens and personal access tokens (classic) need the `user` scope to use this endpoint.
///
/// [GitHub API docs for get_github_actions_billing_user](https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-a-user)
///
/// ---
pub async fn get_github_actions_billing_user_async(&self, username: &str) -> Result<ActionsBillingUsage, AdapterError> {
let request_uri = format!("{}/users/{}/settings/billing/actions", super::GITHUB_BASE_API_URL, username);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubActionsBillingUserError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get GitHub Actions billing for a user
///
/// Gets the summary of the free and paid GitHub Actions minutes used.
///
/// Paid minutes only apply to workflows in private repositories that use GitHub-hosted runners. Minutes used is listed for each GitHub-hosted runner operating system. Any job re-runs are also included in the usage. The usage returned includes any minute multipliers for macOS and Windows runners, and is rounded up to the nearest whole minute. For more information, see "[Managing billing for GitHub Actions](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-actions)".
///
/// OAuth app tokens and personal access tokens (classic) need the `user` scope to use this endpoint.
///
/// [GitHub API docs for get_github_actions_billing_user](https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-a-user)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_github_actions_billing_user(&self, username: &str) -> Result<ActionsBillingUsage, AdapterError> {
let request_uri = format!("{}/users/{}/settings/billing/actions", super::GITHUB_BASE_API_URL, username);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubActionsBillingUserError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get billing usage report for an organization
///
/// Gets a report of the total usage for an organization. To use this endpoint, you must be an administrator of an organization within an enterprise or an organization account.
///
/// **Note:** This endpoint is only available to organizations with access to the enhanced billing platform. For more information, see "[About the enhanced billing platform](https://docs.github.com/billing/using-the-new-billing-platform)."
///
/// [GitHub API docs for get_github_billing_usage_report_org](https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-an-organization)
///
/// ---
pub async fn get_github_billing_usage_report_org_async(&self, org: &str, query_params: Option<impl Into<BillingGetGithubBillingUsageReportOrgParams>>) -> Result<BillingUsageReport, AdapterError> {
let mut request_uri = format!("{}/organizations/{}/settings/billing/usage", super::GITHUB_BASE_API_URL, org);
if let Some(params) = query_params {
request_uri.push_str("?");
request_uri.push_str(&serde_urlencoded::to_string(params.into())?);
}
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
400 => Err(BillingGetGithubBillingUsageReportOrgError::Status400(github_response.to_json_async().await?).into()),
403 => Err(BillingGetGithubBillingUsageReportOrgError::Status403(github_response.to_json_async().await?).into()),
500 => Err(BillingGetGithubBillingUsageReportOrgError::Status500(github_response.to_json_async().await?).into()),
503 => Err(BillingGetGithubBillingUsageReportOrgError::Status503(github_response.to_json_async().await?).into()),
code => Err(BillingGetGithubBillingUsageReportOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get billing usage report for an organization
///
/// Gets a report of the total usage for an organization. To use this endpoint, you must be an administrator of an organization within an enterprise or an organization account.
///
/// **Note:** This endpoint is only available to organizations with access to the enhanced billing platform. For more information, see "[About the enhanced billing platform](https://docs.github.com/billing/using-the-new-billing-platform)."
///
/// [GitHub API docs for get_github_billing_usage_report_org](https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-an-organization)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_github_billing_usage_report_org(&self, org: &str, query_params: Option<impl Into<BillingGetGithubBillingUsageReportOrgParams>>) -> Result<BillingUsageReport, AdapterError> {
let mut request_uri = format!("{}/organizations/{}/settings/billing/usage", super::GITHUB_BASE_API_URL, org);
if let Some(params) = query_params {
request_uri.push_str("?");
let qp: BillingGetGithubBillingUsageReportOrgParams = params.into();
request_uri.push_str(&serde_urlencoded::to_string(qp)?);
}
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
400 => Err(BillingGetGithubBillingUsageReportOrgError::Status400(github_response.to_json()?).into()),
403 => Err(BillingGetGithubBillingUsageReportOrgError::Status403(github_response.to_json()?).into()),
500 => Err(BillingGetGithubBillingUsageReportOrgError::Status500(github_response.to_json()?).into()),
503 => Err(BillingGetGithubBillingUsageReportOrgError::Status503(github_response.to_json()?).into()),
code => Err(BillingGetGithubBillingUsageReportOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get billing usage report for a user
///
/// Gets a report of the total usage for a user.
///
/// **Note:** This endpoint is only available to users with access to the enhanced billing platform.
///
/// [GitHub API docs for get_github_billing_usage_report_user](https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-a-user)
///
/// ---
pub async fn get_github_billing_usage_report_user_async(&self, username: &str, query_params: Option<impl Into<BillingGetGithubBillingUsageReportUserParams>>) -> Result<BillingUsageReportUser, AdapterError> {
let mut request_uri = format!("{}/users/{}/settings/billing/usage", super::GITHUB_BASE_API_URL, username);
if let Some(params) = query_params {
request_uri.push_str("?");
request_uri.push_str(&serde_urlencoded::to_string(params.into())?);
}
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
400 => Err(BillingGetGithubBillingUsageReportUserError::Status400(github_response.to_json_async().await?).into()),
403 => Err(BillingGetGithubBillingUsageReportUserError::Status403(github_response.to_json_async().await?).into()),
500 => Err(BillingGetGithubBillingUsageReportUserError::Status500(github_response.to_json_async().await?).into()),
503 => Err(BillingGetGithubBillingUsageReportUserError::Status503(github_response.to_json_async().await?).into()),
code => Err(BillingGetGithubBillingUsageReportUserError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get billing usage report for a user
///
/// Gets a report of the total usage for a user.
///
/// **Note:** This endpoint is only available to users with access to the enhanced billing platform.
///
/// [GitHub API docs for get_github_billing_usage_report_user](https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-a-user)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_github_billing_usage_report_user(&self, username: &str, query_params: Option<impl Into<BillingGetGithubBillingUsageReportUserParams>>) -> Result<BillingUsageReportUser, AdapterError> {
let mut request_uri = format!("{}/users/{}/settings/billing/usage", super::GITHUB_BASE_API_URL, username);
if let Some(params) = query_params {
request_uri.push_str("?");
let qp: BillingGetGithubBillingUsageReportUserParams = params.into();
request_uri.push_str(&serde_urlencoded::to_string(qp)?);
}
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
400 => Err(BillingGetGithubBillingUsageReportUserError::Status400(github_response.to_json()?).into()),
403 => Err(BillingGetGithubBillingUsageReportUserError::Status403(github_response.to_json()?).into()),
500 => Err(BillingGetGithubBillingUsageReportUserError::Status500(github_response.to_json()?).into()),
503 => Err(BillingGetGithubBillingUsageReportUserError::Status503(github_response.to_json()?).into()),
code => Err(BillingGetGithubBillingUsageReportUserError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get GitHub Packages billing for an organization
///
/// Gets the free and paid storage used for GitHub Packages in gigabytes.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` or `admin:org` scope to use this endpoint.
///
/// [GitHub API docs for get_github_packages_billing_org](https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-an-organization)
///
/// ---
pub async fn get_github_packages_billing_org_async(&self, org: &str) -> Result<PackagesBillingUsage, AdapterError> {
let request_uri = format!("{}/orgs/{}/settings/billing/packages", super::GITHUB_BASE_API_URL, org);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubPackagesBillingOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get GitHub Packages billing for an organization
///
/// Gets the free and paid storage used for GitHub Packages in gigabytes.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` or `admin:org` scope to use this endpoint.
///
/// [GitHub API docs for get_github_packages_billing_org](https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-an-organization)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_github_packages_billing_org(&self, org: &str) -> Result<PackagesBillingUsage, AdapterError> {
let request_uri = format!("{}/orgs/{}/settings/billing/packages", super::GITHUB_BASE_API_URL, org);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubPackagesBillingOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get GitHub Packages billing for a user
///
/// Gets the free and paid storage used for GitHub Packages in gigabytes.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `user` scope to use this endpoint.
///
/// [GitHub API docs for get_github_packages_billing_user](https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-a-user)
///
/// ---
pub async fn get_github_packages_billing_user_async(&self, username: &str) -> Result<PackagesBillingUsage, AdapterError> {
let request_uri = format!("{}/users/{}/settings/billing/packages", super::GITHUB_BASE_API_URL, username);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubPackagesBillingUserError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get GitHub Packages billing for a user
///
/// Gets the free and paid storage used for GitHub Packages in gigabytes.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `user` scope to use this endpoint.
///
/// [GitHub API docs for get_github_packages_billing_user](https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-a-user)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_github_packages_billing_user(&self, username: &str) -> Result<PackagesBillingUsage, AdapterError> {
let request_uri = format!("{}/users/{}/settings/billing/packages", super::GITHUB_BASE_API_URL, username);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
code => Err(BillingGetGithubPackagesBillingUserError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get shared storage billing for an organization
///
/// Gets the estimated paid and estimated total storage used for GitHub Actions and GitHub Packages.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` or `admin:org` scope to use this endpoint.
///
/// [GitHub API docs for get_shared_storage_billing_org](https://docs.github.com/rest/billing/billing#get-shared-storage-billing-for-an-organization)
///
/// ---
pub async fn get_shared_storage_billing_org_async(&self, org: &str) -> Result<CombinedBillingUsage, AdapterError> {
let request_uri = format!("{}/orgs/{}/settings/billing/shared-storage", super::GITHUB_BASE_API_URL, org);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
code => Err(BillingGetSharedStorageBillingOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get shared storage billing for an organization
///
/// Gets the estimated paid and estimated total storage used for GitHub Actions and GitHub Packages.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` or `admin:org` scope to use this endpoint.
///
/// [GitHub API docs for get_shared_storage_billing_org](https://docs.github.com/rest/billing/billing#get-shared-storage-billing-for-an-organization)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_shared_storage_billing_org(&self, org: &str) -> Result<CombinedBillingUsage, AdapterError> {
let request_uri = format!("{}/orgs/{}/settings/billing/shared-storage", super::GITHUB_BASE_API_URL, org);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
code => Err(BillingGetSharedStorageBillingOrgError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get shared storage billing for a user
///
/// Gets the estimated paid and estimated total storage used for GitHub Actions and GitHub Packages.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `user` scope to use this endpoint.
///
/// [GitHub API docs for get_shared_storage_billing_user](https://docs.github.com/rest/billing/billing#get-shared-storage-billing-for-a-user)
///
/// ---
pub async fn get_shared_storage_billing_user_async(&self, username: &str) -> Result<CombinedBillingUsage, AdapterError> {
let request_uri = format!("{}/users/{}/settings/billing/shared-storage", super::GITHUB_BASE_API_URL, username);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch_async(request).await?;
// --
if github_response.is_success() {
Ok(github_response.to_json_async().await?)
} else {
match github_response.status_code() {
code => Err(BillingGetSharedStorageBillingUserError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get shared storage billing for a user
///
/// Gets the estimated paid and estimated total storage used for GitHub Actions and GitHub Packages.
///
/// Paid minutes only apply to packages stored for private repositories. For more information, see "[Managing billing for GitHub Packages](https://docs.github.com/github/setting-up-and-managing-billing-and-payments-on-github/managing-billing-for-github-packages)."
///
/// OAuth app tokens and personal access tokens (classic) need the `user` scope to use this endpoint.
///
/// [GitHub API docs for get_shared_storage_billing_user](https://docs.github.com/rest/billing/billing#get-shared-storage-billing-for-a-user)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_shared_storage_billing_user(&self, username: &str) -> Result<CombinedBillingUsage, AdapterError> {
let request_uri = format!("{}/users/{}/settings/billing/shared-storage", super::GITHUB_BASE_API_URL, username);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "GET",
headers: vec![]
};
let request = self.client.build(req)?;
// --
let github_response = self.client.fetch(request)?;
// --
if github_response.is_success() {
Ok(github_response.to_json()?)
} else {
match github_response.status_code() {
code => Err(BillingGetSharedStorageBillingUserError::Generic { code }.into()),
}
}
}
}