//! Method, error and parameter types for the Checks 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 Checks<'api, C: Client> where AdapterError: From<<C as Client>::Err> {
client: &'api C
}
pub fn new<C: Client>(client: &C) -> Checks<C> where AdapterError: From<<C as Client>::Err> {
Checks { client }
}
/// Errors for the [Create a check run](Checks::create_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksCreateError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksCreateError> for AdapterError {
fn from(err: ChecksCreateError) -> Self {
let (description, status_code) = match err {
ChecksCreateError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Create a check suite](Checks::create_suite_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksCreateSuiteError {
#[error("Response when the suite was created")]
Status201(CheckSuite),
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksCreateSuiteError> for AdapterError {
fn from(err: ChecksCreateSuiteError) -> Self {
let (description, status_code) = match err {
ChecksCreateSuiteError::Status201(_) => (String::from("Response when the suite was created"), 201),
ChecksCreateSuiteError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get a check run](Checks::get_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksGetError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksGetError> for AdapterError {
fn from(err: ChecksGetError) -> Self {
let (description, status_code) = match err {
ChecksGetError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Get a check suite](Checks::get_suite_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksGetSuiteError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksGetSuiteError> for AdapterError {
fn from(err: ChecksGetSuiteError) -> Self {
let (description, status_code) = match err {
ChecksGetSuiteError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [List check run annotations](Checks::list_annotations_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksListAnnotationsError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksListAnnotationsError> for AdapterError {
fn from(err: ChecksListAnnotationsError) -> Self {
let (description, status_code) = match err {
ChecksListAnnotationsError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [List check runs for a Git reference](Checks::list_for_ref_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksListForRefError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksListForRefError> for AdapterError {
fn from(err: ChecksListForRefError) -> Self {
let (description, status_code) = match err {
ChecksListForRefError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [List check runs in a check suite](Checks::list_for_suite_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksListForSuiteError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksListForSuiteError> for AdapterError {
fn from(err: ChecksListForSuiteError) -> Self {
let (description, status_code) = match err {
ChecksListForSuiteError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [List check suites for a Git reference](Checks::list_suites_for_ref_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksListSuitesForRefError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksListSuitesForRefError> for AdapterError {
fn from(err: ChecksListSuitesForRefError) -> Self {
let (description, status_code) = match err {
ChecksListSuitesForRefError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Rerequest a check run](Checks::rerequest_run_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksRerequestRunError {
#[error("Forbidden if the check run is not rerequestable or doesn't belong to the authenticated GitHub App")]
Status403(BasicError),
#[error("Validation error if the check run is not rerequestable")]
Status422(BasicError),
#[error("Resource not found")]
Status404(BasicError),
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksRerequestRunError> for AdapterError {
fn from(err: ChecksRerequestRunError) -> Self {
let (description, status_code) = match err {
ChecksRerequestRunError::Status403(_) => (String::from("Forbidden if the check run is not rerequestable or doesn't belong to the authenticated GitHub App"), 403),
ChecksRerequestRunError::Status422(_) => (String::from("Validation error if the check run is not rerequestable"), 422),
ChecksRerequestRunError::Status404(_) => (String::from("Resource not found"), 404),
ChecksRerequestRunError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Rerequest a check suite](Checks::rerequest_suite_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksRerequestSuiteError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksRerequestSuiteError> for AdapterError {
fn from(err: ChecksRerequestSuiteError) -> Self {
let (description, status_code) = match err {
ChecksRerequestSuiteError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Update repository preferences for check suites](Checks::set_suites_preferences_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksSetSuitesPreferencesError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksSetSuitesPreferencesError> for AdapterError {
fn from(err: ChecksSetSuitesPreferencesError) -> Self {
let (description, status_code) = match err {
ChecksSetSuitesPreferencesError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Errors for the [Update a check run](Checks::update_async()) endpoint.
#[derive(Debug, thiserror::Error)]
pub enum ChecksUpdateError {
#[error("Status code: {}", code)]
Generic { code: u16 },
}
impl From<ChecksUpdateError> for AdapterError {
fn from(err: ChecksUpdateError) -> Self {
let (description, status_code) = match err {
ChecksUpdateError::Generic { code } => (String::from("Generic"), code)
};
Self::Endpoint {
description,
status_code,
source: Some(Box::new(err))
}
}
}
/// Query parameters for the [List check run annotations](Checks::list_annotations_async()) endpoint.
#[derive(Default, Serialize)]
pub struct ChecksListAnnotationsParams {
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
per_page: Option<u16>,
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
page: Option<u16>
}
impl ChecksListAnnotationsParams {
pub fn new() -> Self {
Self::default()
}
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn per_page(self, per_page: u16) -> Self {
Self {
per_page: Some(per_page),
page: self.page,
}
}
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn page(self, page: u16) -> Self {
Self {
per_page: self.per_page,
page: Some(page),
}
}
}
impl<'enc> From<&'enc PerPage> for ChecksListAnnotationsParams {
fn from(per_page: &'enc PerPage) -> Self {
Self {
per_page: Some(per_page.per_page),
page: Some(per_page.page),
..Default::default()
}
}
}
/// Query parameters for the [List check runs for a Git reference](Checks::list_for_ref_async()) endpoint.
#[derive(Default, Serialize)]
pub struct ChecksListForRefParams<'req> {
/// Returns check runs with the specified `name`.
check_name: Option<&'req str>,
/// Returns check runs with the specified `status`.
status: Option<&'req str>,
/// Filters check runs by their `completed_at` timestamp. `latest` returns the most recent check runs.
filter: Option<&'req str>,
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
per_page: Option<u16>,
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
page: Option<u16>,
app_id: Option<i32>
}
impl<'req> ChecksListForRefParams<'req> {
pub fn new() -> Self {
Self::default()
}
/// Returns check runs with the specified `name`.
pub fn check_name(self, check_name: &'req str) -> Self {
Self {
check_name: Some(check_name),
status: self.status,
filter: self.filter,
per_page: self.per_page,
page: self.page,
app_id: self.app_id,
}
}
/// Returns check runs with the specified `status`.
pub fn status(self, status: &'req str) -> Self {
Self {
check_name: self.check_name,
status: Some(status),
filter: self.filter,
per_page: self.per_page,
page: self.page,
app_id: self.app_id,
}
}
/// Filters check runs by their `completed_at` timestamp. `latest` returns the most recent check runs.
pub fn filter(self, filter: &'req str) -> Self {
Self {
check_name: self.check_name,
status: self.status,
filter: Some(filter),
per_page: self.per_page,
page: self.page,
app_id: self.app_id,
}
}
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn per_page(self, per_page: u16) -> Self {
Self {
check_name: self.check_name,
status: self.status,
filter: self.filter,
per_page: Some(per_page),
page: self.page,
app_id: self.app_id,
}
}
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn page(self, page: u16) -> Self {
Self {
check_name: self.check_name,
status: self.status,
filter: self.filter,
per_page: self.per_page,
page: Some(page),
app_id: self.app_id,
}
}
pub fn app_id(self, app_id: i32) -> Self {
Self {
check_name: self.check_name,
status: self.status,
filter: self.filter,
per_page: self.per_page,
page: self.page,
app_id: Some(app_id),
}
}
}
impl<'enc> From<&'enc PerPage> for ChecksListForRefParams<'enc> {
fn from(per_page: &'enc PerPage) -> Self {
Self {
per_page: Some(per_page.per_page),
page: Some(per_page.page),
..Default::default()
}
}
}
/// Query parameters for the [List check runs in a check suite](Checks::list_for_suite_async()) endpoint.
#[derive(Default, Serialize)]
pub struct ChecksListForSuiteParams<'req> {
/// Returns check runs with the specified `name`.
check_name: Option<&'req str>,
/// Returns check runs with the specified `status`.
status: Option<&'req str>,
/// Filters check runs by their `completed_at` timestamp. `latest` returns the most recent check runs.
filter: Option<&'req str>,
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
per_page: Option<u16>,
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
page: Option<u16>
}
impl<'req> ChecksListForSuiteParams<'req> {
pub fn new() -> Self {
Self::default()
}
/// Returns check runs with the specified `name`.
pub fn check_name(self, check_name: &'req str) -> Self {
Self {
check_name: Some(check_name),
status: self.status,
filter: self.filter,
per_page: self.per_page,
page: self.page,
}
}
/// Returns check runs with the specified `status`.
pub fn status(self, status: &'req str) -> Self {
Self {
check_name: self.check_name,
status: Some(status),
filter: self.filter,
per_page: self.per_page,
page: self.page,
}
}
/// Filters check runs by their `completed_at` timestamp. `latest` returns the most recent check runs.
pub fn filter(self, filter: &'req str) -> Self {
Self {
check_name: self.check_name,
status: self.status,
filter: Some(filter),
per_page: self.per_page,
page: self.page,
}
}
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn per_page(self, per_page: u16) -> Self {
Self {
check_name: self.check_name,
status: self.status,
filter: self.filter,
per_page: Some(per_page),
page: self.page,
}
}
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn page(self, page: u16) -> Self {
Self {
check_name: self.check_name,
status: self.status,
filter: self.filter,
per_page: self.per_page,
page: Some(page),
}
}
}
impl<'enc> From<&'enc PerPage> for ChecksListForSuiteParams<'enc> {
fn from(per_page: &'enc PerPage) -> Self {
Self {
per_page: Some(per_page.per_page),
page: Some(per_page.page),
..Default::default()
}
}
}
/// Query parameters for the [List check suites for a Git reference](Checks::list_suites_for_ref_async()) endpoint.
#[derive(Default, Serialize)]
pub struct ChecksListSuitesForRefParams<'req> {
/// Filters check suites by GitHub App `id`.
app_id: Option<i32>,
/// Returns check runs with the specified `name`.
check_name: Option<&'req str>,
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
per_page: Option<u16>,
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
page: Option<u16>
}
impl<'req> ChecksListSuitesForRefParams<'req> {
pub fn new() -> Self {
Self::default()
}
/// Filters check suites by GitHub App `id`.
pub fn app_id(self, app_id: i32) -> Self {
Self {
app_id: Some(app_id),
check_name: self.check_name,
per_page: self.per_page,
page: self.page,
}
}
/// Returns check runs with the specified `name`.
pub fn check_name(self, check_name: &'req str) -> Self {
Self {
app_id: self.app_id,
check_name: Some(check_name),
per_page: self.per_page,
page: self.page,
}
}
/// The number of results per page (max 100). For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn per_page(self, per_page: u16) -> Self {
Self {
app_id: self.app_id,
check_name: self.check_name,
per_page: Some(per_page),
page: self.page,
}
}
/// The page number of the results to fetch. For more information, see \"[Using pagination in the REST API](https://docs.github.com/rest/using-the-rest-api/using-pagination-in-the-rest-api).\"
pub fn page(self, page: u16) -> Self {
Self {
app_id: self.app_id,
check_name: self.check_name,
per_page: self.per_page,
page: Some(page),
}
}
}
impl<'enc> From<&'enc PerPage> for ChecksListSuitesForRefParams<'enc> {
fn from(per_page: &'enc PerPage) -> Self {
Self {
per_page: Some(per_page.per_page),
page: Some(per_page.page),
..Default::default()
}
}
}
impl<'api, C: Client> Checks<'api, C> where AdapterError: From<<C as Client>::Err> {
/// ---
///
/// # Create a check run
///
/// Creates a new check run for a specific commit in a repository.
///
/// To create a check run, you must use a GitHub App. OAuth apps and authenticated users are not able to create a check suite.
///
/// In a check suite, GitHub limits the number of check runs with the same name to 1000. Once these check runs exceed 1000, GitHub will start to automatically delete older check runs.
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// [GitHub API docs for create](https://docs.github.com/rest/checks/runs#create-a-check-run)
///
/// ---
pub async fn create_async(&self, owner: &str, repo: &str, body: PostChecksCreate) -> Result<CheckRun, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs", super::GITHUB_BASE_API_URL, owner, repo);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PostChecksCreate>(body)?),
method: "POST",
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(ChecksCreateError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Create a check run
///
/// Creates a new check run for a specific commit in a repository.
///
/// To create a check run, you must use a GitHub App. OAuth apps and authenticated users are not able to create a check suite.
///
/// In a check suite, GitHub limits the number of check runs with the same name to 1000. Once these check runs exceed 1000, GitHub will start to automatically delete older check runs.
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// [GitHub API docs for create](https://docs.github.com/rest/checks/runs#create-a-check-run)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn create(&self, owner: &str, repo: &str, body: PostChecksCreate) -> Result<CheckRun, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs", super::GITHUB_BASE_API_URL, owner, repo);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PostChecksCreate>(body)?),
method: "POST",
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(ChecksCreateError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Create a check suite
///
/// Creates a check suite manually. By default, check suites are automatically created when you create a [check run](https://docs.github.com/rest/checks/runs). You only need to use this endpoint for manually creating check suites when you've disabled automatic creation using "[Update repository preferences for check suites](https://docs.github.com/rest/checks/suites#update-repository-preferences-for-check-suites)".
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
///
/// OAuth apps and personal access tokens (classic) cannot use this endpoint.
///
/// [GitHub API docs for create_suite](https://docs.github.com/rest/checks/suites#create-a-check-suite)
///
/// ---
pub async fn create_suite_async(&self, owner: &str, repo: &str, body: PostChecksCreateSuite) -> Result<CheckSuite, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites", super::GITHUB_BASE_API_URL, owner, repo);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PostChecksCreateSuite>(body)?),
method: "POST",
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() {
201 => Err(ChecksCreateSuiteError::Status201(github_response.to_json_async().await?).into()),
code => Err(ChecksCreateSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Create a check suite
///
/// Creates a check suite manually. By default, check suites are automatically created when you create a [check run](https://docs.github.com/rest/checks/runs). You only need to use this endpoint for manually creating check suites when you've disabled automatic creation using "[Update repository preferences for check suites](https://docs.github.com/rest/checks/suites#update-repository-preferences-for-check-suites)".
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
///
/// OAuth apps and personal access tokens (classic) cannot use this endpoint.
///
/// [GitHub API docs for create_suite](https://docs.github.com/rest/checks/suites#create-a-check-suite)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn create_suite(&self, owner: &str, repo: &str, body: PostChecksCreateSuite) -> Result<CheckSuite, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites", super::GITHUB_BASE_API_URL, owner, repo);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PostChecksCreateSuite>(body)?),
method: "POST",
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() {
201 => Err(ChecksCreateSuiteError::Status201(github_response.to_json()?).into()),
code => Err(ChecksCreateSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get a check run
///
/// Gets a single check run using its `id`.
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for get](https://docs.github.com/rest/checks/runs#get-a-check-run)
///
/// ---
pub async fn get_async(&self, owner: &str, repo: &str, check_run_id: i32) -> Result<CheckRun, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs/{}", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
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(ChecksGetError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get a check run
///
/// Gets a single check run using its `id`.
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for get](https://docs.github.com/rest/checks/runs#get-a-check-run)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get(&self, owner: &str, repo: &str, check_run_id: i32) -> Result<CheckRun, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs/{}", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
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(ChecksGetError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get a check suite
///
/// Gets a single check suite using its `id`.
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for get_suite](https://docs.github.com/rest/checks/suites#get-a-check-suite)
///
/// ---
pub async fn get_suite_async(&self, owner: &str, repo: &str, check_suite_id: i32) -> Result<CheckSuite, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites/{}", super::GITHUB_BASE_API_URL, owner, repo, check_suite_id);
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(ChecksGetSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Get a check suite
///
/// Gets a single check suite using its `id`.
///
/// > [!NOTE]
/// > The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for get_suite](https://docs.github.com/rest/checks/suites#get-a-check-suite)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn get_suite(&self, owner: &str, repo: &str, check_suite_id: i32) -> Result<CheckSuite, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites/{}", super::GITHUB_BASE_API_URL, owner, repo, check_suite_id);
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(ChecksGetSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check run annotations
///
/// Lists annotations for a check run using the annotation `id`.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_annotations](https://docs.github.com/rest/checks/runs#list-check-run-annotations)
///
/// ---
pub async fn list_annotations_async(&self, owner: &str, repo: &str, check_run_id: i32, query_params: Option<impl Into<ChecksListAnnotationsParams>>) -> Result<Vec<CheckAnnotation>, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/check-runs/{}/annotations", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
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() {
code => Err(ChecksListAnnotationsError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check run annotations
///
/// Lists annotations for a check run using the annotation `id`.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_annotations](https://docs.github.com/rest/checks/runs#list-check-run-annotations)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn list_annotations(&self, owner: &str, repo: &str, check_run_id: i32, query_params: Option<impl Into<ChecksListAnnotationsParams>>) -> Result<Vec<CheckAnnotation>, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/check-runs/{}/annotations", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
if let Some(params) = query_params {
request_uri.push_str("?");
let qp: ChecksListAnnotationsParams = 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() {
code => Err(ChecksListAnnotationsError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check runs for a Git reference
///
/// Lists check runs for a commit ref. The `ref` can be a SHA, branch name, or a tag name.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// If there are more than 1000 check suites on a single git reference, this endpoint will limit check runs to the 1000 most recent check suites. To iterate over all possible check runs, use the [List check suites for a Git reference](https://docs.github.com/rest/reference/checks#list-check-suites-for-a-git-reference) endpoint and provide the `check_suite_id` parameter to the [List check runs in a check suite](https://docs.github.com/rest/reference/checks#list-check-runs-in-a-check-suite) endpoint.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_for_ref](https://docs.github.com/rest/checks/runs#list-check-runs-for-a-git-reference)
///
/// ---
pub async fn list_for_ref_async(&self, owner: &str, repo: &str, git_ref: &str, query_params: Option<impl Into<ChecksListForRefParams<'api>>>) -> Result<GetChecksListForRefResponse200, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/commits/{}/check-runs", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
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() {
code => Err(ChecksListForRefError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check runs for a Git reference
///
/// Lists check runs for a commit ref. The `ref` can be a SHA, branch name, or a tag name.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// If there are more than 1000 check suites on a single git reference, this endpoint will limit check runs to the 1000 most recent check suites. To iterate over all possible check runs, use the [List check suites for a Git reference](https://docs.github.com/rest/reference/checks#list-check-suites-for-a-git-reference) endpoint and provide the `check_suite_id` parameter to the [List check runs in a check suite](https://docs.github.com/rest/reference/checks#list-check-runs-in-a-check-suite) endpoint.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_for_ref](https://docs.github.com/rest/checks/runs#list-check-runs-for-a-git-reference)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn list_for_ref(&self, owner: &str, repo: &str, git_ref: &str, query_params: Option<impl Into<ChecksListForRefParams<'api>>>) -> Result<GetChecksListForRefResponse200, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/commits/{}/check-runs", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
if let Some(params) = query_params {
request_uri.push_str("?");
let qp: ChecksListForRefParams = 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() {
code => Err(ChecksListForRefError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check runs in a check suite
///
/// Lists check runs for a check suite using its `id`.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_for_suite](https://docs.github.com/rest/checks/runs#list-check-runs-in-a-check-suite)
///
/// ---
pub async fn list_for_suite_async(&self, owner: &str, repo: &str, check_suite_id: i32, query_params: Option<impl Into<ChecksListForSuiteParams<'api>>>) -> Result<GetChecksListForRefResponse200, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/check-suites/{}/check-runs", super::GITHUB_BASE_API_URL, owner, repo, check_suite_id);
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() {
code => Err(ChecksListForSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check runs in a check suite
///
/// Lists check runs for a check suite using its `id`.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_for_suite](https://docs.github.com/rest/checks/runs#list-check-runs-in-a-check-suite)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn list_for_suite(&self, owner: &str, repo: &str, check_suite_id: i32, query_params: Option<impl Into<ChecksListForSuiteParams<'api>>>) -> Result<GetChecksListForRefResponse200, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/check-suites/{}/check-runs", super::GITHUB_BASE_API_URL, owner, repo, check_suite_id);
if let Some(params) = query_params {
request_uri.push_str("?");
let qp: ChecksListForSuiteParams = 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() {
code => Err(ChecksListForSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check suites for a Git reference
///
/// Lists check suites for a commit `ref`. The `ref` can be a SHA, branch name, or a tag name.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_suites_for_ref](https://docs.github.com/rest/checks/suites#list-check-suites-for-a-git-reference)
///
/// ---
pub async fn list_suites_for_ref_async(&self, owner: &str, repo: &str, git_ref: &str, query_params: Option<impl Into<ChecksListSuitesForRefParams<'api>>>) -> Result<GetChecksListSuitesForRefResponse200, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/commits/{}/check-suites", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
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() {
code => Err(ChecksListSuitesForRefError::Generic { code }.into()),
}
}
}
/// ---
///
/// # List check suites for a Git reference
///
/// Lists check suites for a commit `ref`. The `ref` can be a SHA, branch name, or a tag name.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
///
/// OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint on a private repository.
///
/// [GitHub API docs for list_suites_for_ref](https://docs.github.com/rest/checks/suites#list-check-suites-for-a-git-reference)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn list_suites_for_ref(&self, owner: &str, repo: &str, git_ref: &str, query_params: Option<impl Into<ChecksListSuitesForRefParams<'api>>>) -> Result<GetChecksListSuitesForRefResponse200, AdapterError> {
let mut request_uri = format!("{}/repos/{}/{}/commits/{}/check-suites", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
if let Some(params) = query_params {
request_uri.push_str("?");
let qp: ChecksListSuitesForRefParams = 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() {
code => Err(ChecksListSuitesForRefError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Rerequest a check run
///
/// Triggers GitHub to rerequest an existing check run, without pushing new code to a repository. This endpoint will trigger the [`check_run` webhook](https://docs.github.com/webhooks/event-payloads/#check_run) event with the action `rerequested`. When a check run is `rerequested`, the `status` of the check suite it belongs to is reset to `queued` and the `conclusion` is cleared. The check run itself is not updated. GitHub apps recieving the [`check_run` webhook](https://docs.github.com/webhooks/event-payloads/#check_run) with the `rerequested` action should then decide if the check run should be reset or updated and call the [update `check_run` endpoint](https://docs.github.com/rest/checks/runs#update-a-check-run) to update the check_run if desired.
///
/// For more information about how to re-run GitHub Actions jobs, see "[Re-run a job from a workflow run](https://docs.github.com/rest/actions/workflow-runs#re-run-a-job-from-a-workflow-run)".
///
/// [GitHub API docs for rerequest_run](https://docs.github.com/rest/checks/runs#rerequest-a-check-run)
///
/// ---
pub async fn rerequest_run_async(&self, owner: &str, repo: &str, check_run_id: i32) -> Result<EmptyObject, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs/{}/rerequest", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "POST",
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() {
403 => Err(ChecksRerequestRunError::Status403(github_response.to_json_async().await?).into()),
422 => Err(ChecksRerequestRunError::Status422(github_response.to_json_async().await?).into()),
404 => Err(ChecksRerequestRunError::Status404(github_response.to_json_async().await?).into()),
code => Err(ChecksRerequestRunError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Rerequest a check run
///
/// Triggers GitHub to rerequest an existing check run, without pushing new code to a repository. This endpoint will trigger the [`check_run` webhook](https://docs.github.com/webhooks/event-payloads/#check_run) event with the action `rerequested`. When a check run is `rerequested`, the `status` of the check suite it belongs to is reset to `queued` and the `conclusion` is cleared. The check run itself is not updated. GitHub apps recieving the [`check_run` webhook](https://docs.github.com/webhooks/event-payloads/#check_run) with the `rerequested` action should then decide if the check run should be reset or updated and call the [update `check_run` endpoint](https://docs.github.com/rest/checks/runs#update-a-check-run) to update the check_run if desired.
///
/// For more information about how to re-run GitHub Actions jobs, see "[Re-run a job from a workflow run](https://docs.github.com/rest/actions/workflow-runs#re-run-a-job-from-a-workflow-run)".
///
/// [GitHub API docs for rerequest_run](https://docs.github.com/rest/checks/runs#rerequest-a-check-run)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn rerequest_run(&self, owner: &str, repo: &str, check_run_id: i32) -> Result<EmptyObject, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs/{}/rerequest", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "POST",
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() {
403 => Err(ChecksRerequestRunError::Status403(github_response.to_json()?).into()),
422 => Err(ChecksRerequestRunError::Status422(github_response.to_json()?).into()),
404 => Err(ChecksRerequestRunError::Status404(github_response.to_json()?).into()),
code => Err(ChecksRerequestRunError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Rerequest a check suite
///
/// Triggers GitHub to rerequest an existing check suite, without pushing new code to a repository. This endpoint will trigger the [`check_suite` webhook](https://docs.github.com/webhooks/event-payloads/#check_suite) event with the action `rerequested`. When a check suite is `rerequested`, its `status` is reset to `queued` and the `conclusion` is cleared.
///
/// [GitHub API docs for rerequest_suite](https://docs.github.com/rest/checks/suites#rerequest-a-check-suite)
///
/// ---
pub async fn rerequest_suite_async(&self, owner: &str, repo: &str, check_suite_id: i32) -> Result<EmptyObject, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites/{}/rerequest", super::GITHUB_BASE_API_URL, owner, repo, check_suite_id);
let req = GitHubRequest {
uri: request_uri,
body: None::<C::Body>,
method: "POST",
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(ChecksRerequestSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Rerequest a check suite
///
/// Triggers GitHub to rerequest an existing check suite, without pushing new code to a repository. This endpoint will trigger the [`check_suite` webhook](https://docs.github.com/webhooks/event-payloads/#check_suite) event with the action `rerequested`. When a check suite is `rerequested`, its `status` is reset to `queued` and the `conclusion` is cleared.
///
/// [GitHub API docs for rerequest_suite](https://docs.github.com/rest/checks/suites#rerequest-a-check-suite)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn rerequest_suite(&self, owner: &str, repo: &str, check_suite_id: i32) -> Result<EmptyObject, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites/{}/rerequest", super::GITHUB_BASE_API_URL, owner, repo, check_suite_id);
let req = GitHubRequest {
uri: request_uri,
body: None,
method: "POST",
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(ChecksRerequestSuiteError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Update repository preferences for check suites
///
/// Changes the default automatic flow when creating check suites. By default, a check suite is automatically created each time code is pushed to a repository. When you disable the automatic creation of check suites, you can manually [Create a check suite](https://docs.github.com/rest/checks/suites#create-a-check-suite).
/// You must have admin permissions in the repository to set preferences for check suites.
///
/// [GitHub API docs for set_suites_preferences](https://docs.github.com/rest/checks/suites#update-repository-preferences-for-check-suites)
///
/// ---
pub async fn set_suites_preferences_async(&self, owner: &str, repo: &str, body: PatchChecksSetSuitesPreferences) -> Result<CheckSuitePreference, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites/preferences", super::GITHUB_BASE_API_URL, owner, repo);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PatchChecksSetSuitesPreferences>(body)?),
method: "PATCH",
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(ChecksSetSuitesPreferencesError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Update repository preferences for check suites
///
/// Changes the default automatic flow when creating check suites. By default, a check suite is automatically created each time code is pushed to a repository. When you disable the automatic creation of check suites, you can manually [Create a check suite](https://docs.github.com/rest/checks/suites#create-a-check-suite).
/// You must have admin permissions in the repository to set preferences for check suites.
///
/// [GitHub API docs for set_suites_preferences](https://docs.github.com/rest/checks/suites#update-repository-preferences-for-check-suites)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn set_suites_preferences(&self, owner: &str, repo: &str, body: PatchChecksSetSuitesPreferences) -> Result<CheckSuitePreference, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-suites/preferences", super::GITHUB_BASE_API_URL, owner, repo);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PatchChecksSetSuitesPreferences>(body)?),
method: "PATCH",
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(ChecksSetSuitesPreferencesError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Update a check run
///
/// Updates a check run for a specific commit in a repository.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// OAuth apps and personal access tokens (classic) cannot use this endpoint.
///
/// [GitHub API docs for update](https://docs.github.com/rest/checks/runs#update-a-check-run)
///
/// ---
pub async fn update_async(&self, owner: &str, repo: &str, check_run_id: i32, body: PatchChecksUpdate) -> Result<CheckRun, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs/{}", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PatchChecksUpdate>(body)?),
method: "PATCH",
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(ChecksUpdateError::Generic { code }.into()),
}
}
}
/// ---
///
/// # Update a check run
///
/// Updates a check run for a specific commit in a repository.
///
/// > [!NOTE]
/// > The endpoints to manage checks only look for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
///
/// OAuth apps and personal access tokens (classic) cannot use this endpoint.
///
/// [GitHub API docs for update](https://docs.github.com/rest/checks/runs#update-a-check-run)
///
/// ---
#[cfg(not(target_arch = "wasm32"))]
pub fn update(&self, owner: &str, repo: &str, check_run_id: i32, body: PatchChecksUpdate) -> Result<CheckRun, AdapterError> {
let request_uri = format!("{}/repos/{}/{}/check-runs/{}", super::GITHUB_BASE_API_URL, owner, repo, check_run_id);
let req = GitHubRequest {
uri: request_uri,
body: Some(C::from_json::<PatchChecksUpdate>(body)?),
method: "PATCH",
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(ChecksUpdateError::Generic { code }.into()),
}
}
}
}