diff --git a/src/api/checks.rs b/src/api/checks.rs index b7696c80..a722be65 100644 --- a/src/api/checks.rs +++ b/src/api/checks.rs @@ -1,8 +1,13 @@ -use crate::models::{CheckRunId, CheckSuiteId}; -use crate::params::checks::{CheckRunConclusion, CheckRunOutput, CheckRunStatus}; +use chrono::{DateTime, Utc}; +use hyper::body::Body; + +use crate::models::checks::{AutoTriggerCheck, CheckSuite, CheckSuitePreferences}; +use crate::models::{AppId, CheckRunId, CheckSuiteId}; +use crate::params::checks::{ + CheckRunAnnotation, CheckRunConclusion, CheckRunOutput, CheckRunStatus, +}; use crate::params::repos::Commitish; use crate::{models, Octocrab, Result}; -use chrono::{DateTime, Utc}; /// Handler for GitHub's Checks API. /// @@ -295,6 +300,70 @@ impl<'octo, 'r> ListCheckRunsForGitRefBuilder<'octo, 'r> { } } +#[derive(serde::Serialize)] +pub struct ListCheckSuitesForGitRefBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + #[serde(skip)] + git_ref: Commitish, + per_page: Option, + page: Option, + ///Filters check suites by GitHub App id. + app_id: Option, + ///Returns check runs with the specified name. + check_name: Option, +} + +impl<'octo, 'r> crate::checks::ListCheckSuitesForGitRefBuilder<'octo, 'r> { + pub(crate) fn new(handler: &'r ChecksHandler<'octo>, git_ref: Commitish) -> Self { + Self { + handler, + git_ref, + page: None, + per_page: None, + app_id: None, + check_name: None, + } + } + + /// Send the actual request to /repos/{owner}/{repo}/commits/{ref}/check-suites + /// See https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#list-check-suites-for-a-git-reference + pub async fn send(self) -> Result { + let route = format!( + "/repos/{owner}/{repo}/commits/{ref}/check-suites", + owner = self.handler.owner, + repo = self.handler.repo, + ref = self.git_ref, + ); + + self.handler.crab.get(route, Some(&self)).await + } + + /// Results per page (max 100). + pub fn per_page(mut self, per_page: impl Into) -> Self { + self.per_page = Some(per_page.into()); + self + } + + /// Page number of the results to fetch. + pub fn page(mut self, page: impl Into) -> Self { + self.page = Some(page.into()); + self + } + + /// Filters check suites by GitHub App id. + pub fn app_id(mut self, app_id: impl Into) -> Self { + self.app_id = Some(app_id.into()); + self + } + + /// Returns check runs with the specified name. + pub fn check_name(mut self, check_name: impl Into) -> Self { + self.check_name = Some(check_name.into()); + self + } +} + impl<'octo> ChecksHandler<'octo> { pub(crate) fn new(crab: &'octo Octocrab, owner: String, repo: String) -> Self { Self { crab, owner, repo } @@ -334,6 +403,26 @@ impl<'octo> ChecksHandler<'octo> { ListCheckRunsForGitRefBuilder::new(self, git_ref) } + ///Lists check suites for a commit ref. + ///See https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#list-check-suites-for-a-git-reference + ///```no_run + /// use octocrab::models::checks::ListCheckSuites; + /// use octocrab::params::repos::Commitish; + /// async fn run() -> octocrab::Result { + /// let check_suites = octocrab::instance() + /// .checks("owner", "repo") + /// .list_check_suites_for_git_ref(Commitish("ref".to_string())) + /// .send() + /// .await; + /// check_suites + /// } + pub fn list_check_suites_for_git_ref( + &self, + git_ref: Commitish, + ) -> ListCheckSuitesForGitRefBuilder<'_, '_> { + ListCheckSuitesForGitRefBuilder::new(self, git_ref) + } + /// ```no_run /// # async fn run() -> octocrab::Result<()> { /// let check_run = octocrab::instance() @@ -372,4 +461,327 @@ impl<'octo> ChecksHandler<'octo> { pub fn update_check_run(&self, check_run_id: CheckRunId) -> UpdateCheckRunBuilder<'_, '_> { UpdateCheckRunBuilder::new(self, check_run_id) } + + /// Creates a check suite manually. see https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#create-a-check-suite + /// ```no_run + /// use octocrab::models::checks::CheckSuite; + /// async fn run() -> octocrab::Result { + /// let check_suite_create_result = octocrab::instance() + /// .checks("owner", "repo") + /// .create_check_suite("head_sha") + /// .send() + /// .await; + /// check_suite_create_result + /// } + /// ``` + pub fn create_check_suite( + &self, + head_sha: impl Into, + ) -> CreateCheckSuiteBuilder<'_, '_> { + CreateCheckSuiteBuilder::new(self, head_sha.into()) + } + + /// 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. You must have admin permissions in the repository to set preferences for check suites. + /// see https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#update-repository-preferences-for-check-suites + /// ```no_run + /// use octocrab::models::{AppId, checks::AutoTriggerCheck}; + /// use octocrab::models::checks::CheckSuitePreferences; + /// async fn run() -> octocrab::Result { + /// let check_suite_run = octocrab::instance() + /// .checks("owner", "repo") + /// .update_preferences( + /// vec![ AutoTriggerCheck {app_id: AppId(23874), setting: false}, + /// AutoTriggerCheck {app_id: AppId(42), setting: false} ] + /// ) + /// .send() + /// .await; + /// check_suite_run + /// } + /// ``` + pub fn update_preferences( + &self, + auto_trigger_checks: Vec, + ) -> CheckSuitePreferencesBuilder<'_, '_> { + CheckSuitePreferencesBuilder::new(self, auto_trigger_checks) + } + + /// Gets a single check suite using its id. + /// See https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#get-a-check-suite + /// ```no_run + /// use octocrab::models::checks::CheckSuite; + /// use octocrab::models::CheckSuiteId; + /// async fn run() -> octocrab::Result { + /// let get_check_suite_result = octocrab::instance() + /// .checks("owner", "repo") + /// .get_check_suite(CheckSuiteId(42)) + /// .send() + /// .await; + /// get_check_suite_result + /// } + /// ``` + pub fn get_check_suite(&self, check_suite_id: CheckSuiteId) -> GetCheckSuiteBuilder<'_, '_> { + GetCheckSuiteBuilder::new(self, check_suite_id) + } + + ///Triggers GitHub to rerequest an existing check suite, without pushing new code to a repository. + ///See https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#rerequest-a-check-suite + ///```no_run + /// use octocrab::models::CheckSuiteId; + /// async fn run() -> octocrab::Result<()> { + /// let rerequest_check_suite_result = octocrab::instance() + /// .checks("owner", "repo") + /// .rerequest_check_suite(CheckSuiteId(42)) + /// .send() + /// .await; + /// rerequest_check_suite_result + /// } + /// ``` + pub fn rerequest_check_suite( + &self, + check_suite_id: CheckSuiteId, + ) -> crate::api::checks::RerequestCheckSuiteBuilder<'_, '_> { + RerequestCheckSuiteBuilder::new(self, check_suite_id) + } + + ///Triggers GitHub to rerequest an existing check run, without pushing new code to a repository. + ///See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#rerequest-a-check-run + ///```no_run + /// use octocrab::models::CheckRunId; + /// async fn run() -> octocrab::Result<()> { + /// let rerequest_check_run_result = octocrab::instance() + /// .checks("owner", "repo") + /// .rerequest_check_run(CheckRunId(42)) + /// .send() + /// .await; + /// rerequest_check_run_result + /// } + /// ``` + pub fn rerequest_check_run( + &self, + check_run_id: CheckRunId, + ) -> crate::api::checks::RerequestCheckRunBuilder<'_, '_> { + RerequestCheckRunBuilder::new(self, check_run_id) + } + + ///Lists annotations for a check run using the annotation id. + ///See https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-run-annotations + ///```no_run + /// use octocrab::models::CheckRunId; + /// use octocrab::params::checks::CheckRunAnnotation; + /// async fn run() -> octocrab::Result> { + /// let check_run_annotations_result = octocrab::instance() + /// .checks("owner", "repo") + /// .list_annotations(CheckRunId(42)) + /// .send() + /// .await; + /// check_run_annotations_result + /// } + /// ``` + pub fn list_annotations( + &self, + check_run_id: CheckRunId, + ) -> crate::api::checks::CheckRunAnnotationsBuilder<'_, '_> { + CheckRunAnnotationsBuilder::new(self, check_run_id) + } +} + +#[derive(serde::Serialize)] +pub struct CreateCheckSuiteBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + head_sha: String, +} + +impl<'octo, 'r> CreateCheckSuiteBuilder<'octo, 'r> { + pub(crate) fn new(handler: &'r ChecksHandler<'octo>, head_sha: String) -> Self { + Self { handler, head_sha } + } + + /// Sends the actual request. + pub async fn send(self) -> Result { + let route = format!( + "/repos/{owner}/{repo}/check-suites", + owner = self.handler.owner, + repo = self.handler.repo + ); + self.handler.crab.post(route, Some(&self)).await + } +} + +#[derive(serde::Serialize)] +pub struct CheckSuitePreferencesBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + auto_trigger_checks: Vec, +} + +impl<'octo, 'r> CheckSuitePreferencesBuilder<'octo, 'r> { + pub(crate) fn new( + handler: &'r ChecksHandler<'octo>, + auto_trigger_checks: Vec, + ) -> Self { + Self { + handler, + auto_trigger_checks, + } + } + + /// Sends the actual request of [`ChecksHandler.update_preferences()`] + /// see https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#update-repository-preferences-for-check-suites + /// + /// [`ChecksHandler.update_preferences()`]: ChecksHandler#method.update_preferences() + pub async fn send(self) -> Result { + let route = format!( + "/repos/{owner}/{repo}/check-suites/preferences", + owner = self.handler.owner, + repo = self.handler.repo + ); + self.handler.crab.patch(route, Some(&self)).await + } +} + +#[derive(serde::Serialize)] +pub struct GetCheckSuiteBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + check_suite_id: CheckSuiteId, +} + +impl<'octo, 'r> GetCheckSuiteBuilder<'octo, 'r> { + pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_suite_id: CheckSuiteId) -> Self { + Self { + handler, + check_suite_id, + } + } + + /// Sends the actual request of [`ChecksHandler.get_check_suite()`] + /// see https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#get-a-check-suite + /// + /// [`ChecksHandler.get_check_suite()`]: ChecksHandler#method.get_check_suite() + pub async fn send(self) -> Result { + let route = format!( + "/repos/{owner}/{repo}/check-suites/{check_suite_id}", + owner = self.handler.owner, + repo = self.handler.repo, + check_suite_id = self.check_suite_id + ); + self.handler.crab.get(route, Some(&self)).await + } +} + +#[derive(serde::Serialize)] +pub struct RerequestCheckSuiteBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + check_suite_id: CheckSuiteId, +} + +impl<'octo, 'r> crate::checks::RerequestCheckSuiteBuilder<'octo, 'r> { + pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_suite_id: CheckSuiteId) -> Self { + Self { + handler, + check_suite_id, + } + } + + /// Sends the actual request of [`ChecksHandler.rerequest_check_suite()`] + /// see https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#rerequest-a-check-suite + /// + /// [`ChecksHandler.rerequest_check_suite()`]: ChecksHandler#method.rerequest_check_suite() + pub async fn send(self) -> Result<()> { + let route = format!( + "/repos/{owner}/{repo}/check-suites/{check_suite_id}/rerequest", + owner = self.handler.owner, + repo = self.handler.repo, + check_suite_id = self.check_suite_id + ); + let response = self.handler.crab._post(route, Some(&self)).await?; + if !response.status().is_success() { + return Err(crate::map_github_error(response).await.unwrap_err()); + } + + Ok(()) + } +} + +#[derive(serde::Serialize)] +pub struct RerequestCheckRunBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + check_run_id: CheckRunId, +} + +impl<'octo, 'r> crate::checks::RerequestCheckRunBuilder<'octo, 'r> { + pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_run_id: CheckRunId) -> Self { + Self { + handler, + check_run_id, + } + } + + /// Sends the actual request of [`ChecksHandler.rerequest_check_run()`] + /// see https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#rerequest-a-check-run + /// + /// [`ChecksHandler.rerequest_check_run()`]: ChecksHandler#method.rerequest_check_run() + pub async fn send(self) -> Result<()> { + let route = format!( + "/repos/{owner}/{repo}/check-runs/{check_run_id}/rerequest", + owner = self.handler.owner, + repo = self.handler.repo, + check_run_id = self.check_run_id + ); + let response = self.handler.crab._post(route, Some(&self)).await?; + if !response.status().is_success() { + return Err(crate::map_github_error(response).await.unwrap_err()); + } + + Ok(()) + } +} + +#[derive(serde::Serialize)] +pub struct CheckRunAnnotationsBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r ChecksHandler<'octo>, + check_run_id: CheckRunId, + per_page: Option, + page: Option, +} + +impl<'octo, 'r> crate::checks::CheckRunAnnotationsBuilder<'octo, 'r> { + pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_run_id: CheckRunId) -> Self { + Self { + handler, + check_run_id, + page: None, + per_page: None, + } + } + + /// Sends the actual request of [`ChecksHandler.list_annotations()`] + /// see https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-run-annotations + /// + /// [`ChecksHandler.list_annotations()`]: ChecksHandler#method.list_annotations() + pub async fn send(self) -> Result> { + let route = format!( + "/repos/{owner}/{repo}/check-runs/{check_run_id}/annotations", + owner = self.handler.owner, + repo = self.handler.repo, + check_run_id = self.check_run_id + ); + self.handler.crab.get(route, Some(&self)).await + } + + /// Results per page (max 100). + pub fn per_page(mut self, per_page: impl Into) -> Self { + self.per_page = Some(per_page.into()); + self + } + + /// Page number of the results to fetch. + pub fn page(mut self, page: impl Into) -> Self { + self.page = Some(page.into()); + self + } } diff --git a/src/models/checks.rs b/src/models/checks.rs index d090c0f8..3f737e01 100644 --- a/src/models/checks.rs +++ b/src/models/checks.rs @@ -1,3 +1,5 @@ +use crate::models::workflows::HeadCommit; + use super::*; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -32,3 +34,52 @@ pub struct ListCheckRuns { pub total_count: u64, pub check_runs: Vec, } + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct CheckSuite { + pub id: CheckSuiteId, + pub node_id: String, + pub head_branch: String, + pub head_sha: String, + pub status: Option, + pub conclusion: Option, + pub url: String, + pub before: String, + pub after: String, + app: Option, + pub repository: Repository, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, + pub head_commit: HeadCommit, + latest_check_runs_count: i64, + check_runs_url: String, + rerequestable: Option, + runs_rerequestable: Option, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct ListCheckSuites { + pub total_count: u32, + pub check_suites: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct CheckSuitePreferences { + pub preferences: CheckSuiteUpdatePreferences, + pub repository: Repository, +} +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct CheckSuiteUpdatePreferences { + pub auto_trigger_checks: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct AutoTriggerCheck { + /// Enables or disables automatic creation of CheckSuite events upon pushes to the repository. + pub app_id: AppId, + pub setting: bool, +} diff --git a/src/params.rs b/src/params.rs index 16c334a4..aa7a94b4 100644 --- a/src/params.rs +++ b/src/params.rs @@ -152,6 +152,26 @@ pub mod checks { #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, } + + #[derive(serde::Serialize, serde::Deserialize, Debug)] + pub struct CheckRunAnnotation { + pub path: String, + pub start_line: u32, + pub end_line: u32, + #[serde(skip_serializing_if = "Option::is_none")] + pub start_column: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub end_column: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub annotation_level: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub message: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub raw_details: Option, + pub blob_href: String, + } } pub mod issues { diff --git a/tests/check_suites.rs b/tests/check_suites.rs new file mode 100644 index 00000000..c8dc532d --- /dev/null +++ b/tests/check_suites.rs @@ -0,0 +1,255 @@ +use wiremock::{ + matchers::{method, path}, + Mock, MockServer, ResponseTemplate, +}; + +use mock_error::setup_error_handler; +use octocrab::models::checks::{AutoTriggerCheck, CheckSuite, CheckSuitePreferences}; +use octocrab::models::{AppId, CheckRunId, CheckSuiteId}; +use octocrab::params::repos::Commitish; +use octocrab::Octocrab; + +/// Unit test for calls to the `/repos/OWNER/REPO/contributors` endpoint +mod mock_error; + +const OWNER: &str = "XAMPPRocky"; +const REPO: &str = "octocrab"; + +async fn setup_api(template: ResponseTemplate) -> MockServer { + let mock_server = MockServer::start().await; + + Mock::given(method("POST")) + .and(path(format!("/repos/{OWNER}/{REPO}/check-suites"))) + .respond_with(template) + .mount(&mock_server) + .await; + setup_error_handler( + &mock_server, + "POST on /repos/OWNER/REPO/check-suites not called", + ) + .await; + mock_server +} + +fn setup_octocrab(uri: &str) -> Octocrab { + Octocrab::builder().base_uri(uri).unwrap().build().unwrap() +} + +#[tokio::test] +async fn should_create_check_suite() { + let check_suite_response: CheckSuite = + serde_json::from_str(include_str!("resources/check_suite.json")).unwrap(); + let template = ResponseTemplate::new(200).set_body_json(&check_suite_response); + let mock_server = setup_api(template).await; + let client = setup_octocrab(&mock_server.uri()); + + let head_sha = "d6fde92930d4715a2b49857d24b940956b26d2d3"; + let result = client + .checks(OWNER, REPO) + .create_check_suite(head_sha) + .send() + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); + + let check_suite = result.unwrap(); + + assert_eq!(check_suite.head_sha, head_sha); +} + +#[tokio::test] +async fn should_patch_check_suite_preferences() { + // mock infrastructure + let mock_server = MockServer::start().await; + let check_suite_response: CheckSuitePreferences = + serde_json::from_str(include_str!("resources/check_suite_preferences.json")).unwrap(); + let response = ResponseTemplate::new(200).set_body_json(&check_suite_response); + + let mock = Mock::given(method("PATCH")) + .and(path(format!( + "/repos/{OWNER}/{REPO}/check-suites/preferences" + ))) + .respond_with(response.clone()); + mock_server.register(mock).await; + let client = setup_octocrab(&mock_server.uri()); + // fixture + let check_suite_patches = vec![AutoTriggerCheck { + app_id: AppId(42), + setting: true, + }]; + + let result = client + .checks(OWNER, REPO) // though, mocking here 'octocat' / 'Hello-World' + .update_preferences(check_suite_patches) + .send() + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); + let upd_pref_result = result.unwrap(); + assert_eq!(upd_pref_result.preferences.auto_trigger_checks.len(), 2); +} + +#[tokio::test] +async fn should_get_check_suite() { + // mock infrastructure + let mock_server = MockServer::start().await; + let check_suite_response: CheckSuite = + serde_json::from_str(include_str!("resources/check_suite.json")).unwrap(); + let response = ResponseTemplate::new(200).set_body_json(&check_suite_response); + + const CHECK_SUITE_ID: i32 = 5; + let mock = Mock::given(method("GET")) + .and(path(format!( + "/repos/{OWNER}/{REPO}/check-suites/{CHECK_SUITE_ID}" + ))) + .respond_with(response.clone()); + mock_server.register(mock).await; + let client = setup_octocrab(&mock_server.uri()); + + let result = client + .checks(OWNER, REPO) + .get_check_suite(CheckSuiteId(5)) + .send() + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); + let get_cs_result = result.unwrap(); + assert_eq!(get_cs_result.id, CheckSuiteId(5)); +} + +#[tokio::test] +async fn should_trigger_rerequest_check_suite() { + // mock infrastructure + let mock_server = MockServer::start().await; + let response = ResponseTemplate::new(201); + + const CHECK_SUITE_ID: i32 = 42; + let mock = Mock::given(method("POST")) + .and(path(format!( + "/repos/{OWNER}/{REPO}/check-suites/{CHECK_SUITE_ID}/rerequest" + ))) + .respond_with(response.clone()); + mock_server.register(mock).await; + let client = setup_octocrab(&mock_server.uri()); + + let result = client + .checks(OWNER, REPO) + .rerequest_check_suite(CheckSuiteId(42)) + .send() + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); +} + +#[tokio::test] +async fn should_trigger_rerequest_check_run() { + // mock infrastructure + let mock_server = MockServer::start().await; + let response = ResponseTemplate::new(201).set_body_string(""); + + const CHECK_RUN_ID: i32 = 42; + let mock = Mock::given(method("POST")) + .and(path(format!( + "/repos/{OWNER}/{REPO}/check-runs/{CHECK_RUN_ID}/rerequest" + ))) + .respond_with(response.clone()); + mock_server.register(mock).await; + let client = setup_octocrab(&mock_server.uri()); + + let result = client + .checks(OWNER, REPO) + .rerequest_check_run(CheckRunId(42)) + .send() + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); +} + +#[tokio::test] +async fn should_list_annotations() { + // mock infrastructure + let mock_server = MockServer::start().await; + let response = ResponseTemplate::new(200) + .set_body_string(include_str!("resources/check_run_annotations.json")); + + const CHECK_RUN_ID: i32 = 42; + let mock = Mock::given(method("GET")) + .and(path(format!( + "/repos/{OWNER}/{REPO}/check-runs/{CHECK_RUN_ID}/annotations" + ))) + .respond_with(response.clone()); + mock_server.register(mock).await; + let client = setup_octocrab(&mock_server.uri()); + + let result = client + .checks(OWNER, REPO) + .list_annotations(CheckRunId(42)) + .send() + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); + let list_annotations_result = result.unwrap(); + assert_eq!(list_annotations_result.len(), 1); +} + +#[tokio::test] +async fn should_list_check_suites_for_ref() { + // mock infrastructure + let mock_server = MockServer::start().await; + let response = ResponseTemplate::new(200) + .set_body_string(include_str!("resources/list_check_suites_for_ref.json")); + + const COMMIT: &str = "42"; + let mock = Mock::given(method("GET")) + .and(path(format!( + "/repos/{OWNER}/{REPO}/commits/{COMMIT}/check-suites" + ))) + .respond_with(response.clone()); + mock_server.register(mock).await; + let client = setup_octocrab(&mock_server.uri()); + + let result = client + .checks(OWNER, REPO) + .list_check_suites_for_git_ref(Commitish(String::from("42"))) + .send() + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); + let list_check_suites_for_ref_result = result.unwrap(); + assert_eq!( + list_check_suites_for_ref_result.total_count as u32, + list_check_suites_for_ref_result.check_suites.len() as u32 + ); + assert_eq!( + list_check_suites_for_ref_result.check_suites[0].id, + CheckSuiteId(5) + ); +} diff --git a/tests/resources/check_run_annotations.json b/tests/resources/check_run_annotations.json new file mode 100644 index 00000000..ecc4faee --- /dev/null +++ b/tests/resources/check_run_annotations.json @@ -0,0 +1,14 @@ +[ + { + "path": "README.md", + "start_line": 2, + "end_line": 2, + "start_column": 5, + "end_column": 10, + "annotation_level": "warning", + "title": "Spell Checker", + "message": "Check your spelling for 'banaas'.", + "raw_details": "Do you mean 'bananas' or 'banana'?", + "blob_href": "https://api.github.com/repos/github/rest-api-description/git/blobs/abc" + } +] diff --git a/tests/resources/check_suite.json b/tests/resources/check_suite.json new file mode 100644 index 00000000..e8d0b554 --- /dev/null +++ b/tests/resources/check_suite.json @@ -0,0 +1,300 @@ +{ + "id": 5, + "node_id": "MDEwOkNoZWNrU3VpdGU1", + "head_branch": "master", + "head_sha": "d6fde92930d4715a2b49857d24b940956b26d2d3", + "status": "completed", + "conclusion": "neutral", + "url": "https://api.github.com/repos/github/hello-world/check-suites/5", + "before": "146e867f55c26428e5f9fade55a9bbf5e95a7912", + "after": "d6fde92930d4715a2b49857d24b940956b26d2d3", + "pull_requests": [], + "created_at": "2017-07-08T16:18:44-04:00", + "updated_at": "2017-07-08T16:18:44-04:00", + "app": { + "id": 1, + "slug": "octoapp", + "node_id": "MDExOkludGVncmF0aW9uMQ==", + "owner": { + "login": "github", + "id": 1, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", + "url": "https://api.github.com/orgs/github", + "repos_url": "https://api.github.com/orgs/github/repos", + "events_url": "https://api.github.com/orgs/github/events", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": true + }, + "name": "Octocat App", + "description": "", + "external_url": "https://example.com", + "html_url": "https://github.com/apps/octoapp", + "created_at": "2017-07-08T16:18:44-04:00", + "updated_at": "2017-07-08T16:18:44-04:00", + "permissions": { + "metadata": "read", + "contents": "read", + "issues": "write", + "single_file": "write" + }, + "events": [ + "push", + "pull_request" + ] + }, + "repository": { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "template_repository": { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World-Template", + "full_name": "octocat/Hello-World-Template", + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World-Template", + "description": "This your first repo!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World-Template", + "archive_url": "https://api.github.com/repos/octocat/Hello-World-Template/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World-Template/assignees{/user}", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World-Template/branches{/branch}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World-Template/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World-Template/comments{/number}", + "commits_url": "https://api.github.com/repos/octocat/Hello-World-Template/commits{/sha}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World-Template/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World-Template/contents/{+path}", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World-Template/contributors", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World-Template/deployments", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World-Template/downloads", + "events_url": "https://api.github.com/repos/octocat/Hello-World-Template/events", + "forks_url": "https://api.github.com/repos/octocat/Hello-World-Template/forks", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/tags{/sha}", + "git_url": "git:github.com/octocat/Hello-World-Template.git", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World-Template/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World-Template/issues/events{/number}", + "issues_url": "https://api.github.com/repos/octocat/Hello-World-Template/issues{/number}", + "keys_url": "https://api.github.com/repos/octocat/Hello-World-Template/keys{/key_id}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World-Template/labels{/name}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World-Template/languages", + "merges_url": "https://api.github.com/repos/octocat/Hello-World-Template/merges", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World-Template/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World-Template/notifications{?since,all,participating}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World-Template/pulls{/number}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World-Template/releases{/id}", + "ssh_url": "git@github.com:octocat/Hello-World-Template.git", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World-Template/stargazers", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World-Template/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World-Template/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World-Template/subscription", + "tags_url": "https://api.github.com/repos/octocat/Hello-World-Template/tags", + "teams_url": "https://api.github.com/repos/octocat/Hello-World-Template/teams", + "trees_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/trees{/sha}", + "clone_url": "https://github.com/octocat/Hello-World-Template.git", + "mirror_url": "git:git.example.com/octocat/Hello-World-Template", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World-Template/hooks", + "svn_url": "https://svn.github.com/octocat/Hello-World-Template", + "homepage": "https://github.com", + "language": null, + "forks": 9, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "watchers": 80, + "size": 108, + "default_branch": "master", + "open_issues": 0, + "open_issues_count": 0, + "is_template": true, + "license": { + "key": "mit", + "name": "MIT License", + "url": "https://api.github.com/licenses/mit", + "spdx_id": "MIT", + "node_id": "MDc6TGljZW5zZW1pdA==", + "html_url": "https://api.github.com/licenses/mit" + }, + "topics": [ + "octocat", + "atom", + "electron", + "api" + ], + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "archived": false, + "disabled": false, + "visibility": "public", + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "allow_rebase_merge": true, + "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", + "allow_squash_merge": true, + "allow_auto_merge": false, + "delete_branch_on_merge": true, + "allow_merge_commit": true, + "subscribers_count": 42, + "network_count": 0 + }, + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World", + "description": "This your first repo!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World", + "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", + "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", + "events_url": "https://api.github.com/repos/octocat/Hello-World/events", + "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", + "git_url": "git:github.com/octocat/Hello-World.git", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", + "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", + "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", + "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", + "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", + "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", + "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", + "clone_url": "https://github.com/octocat/Hello-World.git", + "mirror_url": "git:git.example.com/octocat/Hello-World", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", + "svn_url": "https://svn.github.com/octocat/Hello-World", + "homepage": "https://github.com", + "language": null, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "size": 108, + "default_branch": "master", + "open_issues_count": 0, + "is_template": false, + "topics": [ + "octocat", + "atom", + "electron", + "api" + ], + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "archived": false, + "disabled": false, + "visibility": "public", + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", + "delete_branch_on_merge": true, + "subscribers_count": 42, + "network_count": 0 + }, + "head_commit": { + "id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", + "tree_id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", + "message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.", + "timestamp": "2016-10-10T00:00:00Z", + "author": { + "name": "The Octocat", + "email": "octocat@nowhere.com" + }, + "committer": { + "name": "The Octocat", + "email": "octocat@nowhere.com" + } + }, + "latest_check_runs_count": 1, + "check_runs_url": "https://api.github.com/repos/octocat/Hello-World/check-suites/5/check-runs" +} diff --git a/tests/resources/check_suite_preferences.json b/tests/resources/check_suite_preferences.json new file mode 100644 index 00000000..23d1716c --- /dev/null +++ b/tests/resources/check_suite_preferences.json @@ -0,0 +1,239 @@ +{ + "preferences": { + "auto_trigger_checks": [ + { + "app_id": 2, + "setting": true + }, + { + "app_id": 4, + "setting": false + } + ] + }, + "repository": { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World", + "description": "This your first repo!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World", + "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", + "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", + "events_url": "https://api.github.com/repos/octocat/Hello-World/events", + "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", + "git_url": "git:github.com/octocat/Hello-World.git", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", + "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", + "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", + "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", + "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", + "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", + "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", + "clone_url": "https://github.com/octocat/Hello-World.git", + "mirror_url": "git:git.example.com/octocat/Hello-World", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", + "svn_url": "https://svn.github.com/octocat/Hello-World", + "homepage": "https://github.com", + "language": null, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "size": 108, + "default_branch": "master", + "open_issues_count": 0, + "is_template": false, + "topics": [ + "octocat", + "atom", + "electron", + "api" + ], + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "archived": false, + "disabled": false, + "visibility": "public", + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "template_repository": { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World-Template", + "full_name": "octocat/Hello-World-Template", + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World-Template", + "description": "This your first repo!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World-Template", + "archive_url": "https://api.github.com/repos/octocat/Hello-World-Template/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World-Template/assignees{/user}", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World-Template/branches{/branch}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World-Template/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World-Template/comments{/number}", + "commits_url": "https://api.github.com/repos/octocat/Hello-World-Template/commits{/sha}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World-Template/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World-Template/contents/{+path}", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World-Template/contributors", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World-Template/deployments", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World-Template/downloads", + "events_url": "https://api.github.com/repos/octocat/Hello-World-Template/events", + "forks_url": "https://api.github.com/repos/octocat/Hello-World-Template/forks", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/tags{/sha}", + "git_url": "git:github.com/octocat/Hello-World-Template.git", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World-Template/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World-Template/issues/events{/number}", + "issues_url": "https://api.github.com/repos/octocat/Hello-World-Template/issues{/number}", + "keys_url": "https://api.github.com/repos/octocat/Hello-World-Template/keys{/key_id}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World-Template/labels{/name}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World-Template/languages", + "merges_url": "https://api.github.com/repos/octocat/Hello-World-Template/merges", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World-Template/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World-Template/notifications{?since,all,participating}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World-Template/pulls{/number}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World-Template/releases{/id}", + "ssh_url": "git@github.com:octocat/Hello-World-Template.git", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World-Template/stargazers", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World-Template/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World-Template/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World-Template/subscription", + "tags_url": "https://api.github.com/repos/octocat/Hello-World-Template/tags", + "teams_url": "https://api.github.com/repos/octocat/Hello-World-Template/teams", + "trees_url": "https://api.github.com/repos/octocat/Hello-World-Template/git/trees{/sha}", + "clone_url": "https://github.com/octocat/Hello-World-Template.git", + "mirror_url": "git:git.example.com/octocat/Hello-World-Template", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World-Template/hooks", + "svn_url": "https://svn.github.com/octocat/Hello-World-Template", + "homepage": "https://github.com", + "language": null, + "forks": 9, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "watchers": 80, + "size": 108, + "default_branch": "master", + "open_issues": 0, + "open_issues_count": 0, + "is_template": true, + "license": { + "key": "mit", + "name": "MIT License", + "url": "https://api.github.com/licenses/mit", + "spdx_id": "MIT", + "node_id": "MDc6TGljZW5zZW1pdA==", + "html_url": "https://api.github.com/licenses/mit" + }, + "topics": [ + "octocat", + "atom", + "electron", + "api" + ], + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "archived": false, + "disabled": false, + "visibility": "public", + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "allow_rebase_merge": true, + "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", + "allow_squash_merge": true, + "allow_auto_merge": false, + "delete_branch_on_merge": true, + "allow_merge_commit": true, + "subscribers_count": 42, + "network_count": 0 + } + } +} diff --git a/tests/resources/list_check_suites_for_ref.json b/tests/resources/list_check_suites_for_ref.json new file mode 100644 index 00000000..6fad9f9e --- /dev/null +++ b/tests/resources/list_check_suites_for_ref.json @@ -0,0 +1,183 @@ +{ + "total_count": 1, + "check_suites": [ + { + "id": 5, + "node_id": "MDEwOkNoZWNrU3VpdGU1", + "head_branch": "master", + "head_sha": "d6fde92930d4715a2b49857d24b940956b26d2d3", + "status": "completed", + "conclusion": "neutral", + "url": "https://api.github.com/repos/github/hello-world/check-suites/5", + "before": "146e867f55c26428e5f9fade55a9bbf5e95a7912", + "after": "d6fde92930d4715a2b49857d24b940956b26d2d3", + "pull_requests": [], + "app": { + "id": 1, + "slug": "octoapp", + "node_id": "MDExOkludGVncmF0aW9uMQ==", + "owner": { + "login": "github", + "id": 1, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", + "url": "https://api.github.com/orgs/github", + "repos_url": "https://api.github.com/orgs/github/repos", + "events_url": "https://api.github.com/orgs/github/events", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": true + }, + "name": "Octocat App", + "description": "", + "external_url": "https://example.com", + "html_url": "https://github.com/apps/octoapp", + "created_at": "2017-07-08T16:18:44-04:00", + "updated_at": "2017-07-08T16:18:44-04:00", + "permissions": { + "metadata": "read", + "contents": "read", + "issues": "write", + "single_file": "write" + }, + "events": [ + "push", + "pull_request" + ] + }, + "repository": { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World", + "description": "This your first repo!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World", + "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", + "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", + "events_url": "https://api.github.com/repos/octocat/Hello-World/events", + "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", + "git_url": "git:github.com/octocat/Hello-World.git", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", + "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", + "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", + "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", + "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", + "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", + "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", + "clone_url": "https://github.com/octocat/Hello-World.git", + "mirror_url": "git:git.example.com/octocat/Hello-World", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", + "svn_url": "https://svn.github.com/octocat/Hello-World", + "homepage": "https://github.com", + "language": null, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "size": 108, + "default_branch": "master", + "open_issues_count": 0, + "is_template": true, + "topics": [ + "octocat", + "atom", + "electron", + "api" + ], + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "archived": false, + "disabled": false, + "visibility": "public", + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", + "delete_branch_on_merge": true, + "subscribers_count": 42, + "network_count": 0 + }, + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "head_commit": { + "id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", + "tree_id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", + "message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.", + "timestamp": "2016-10-10T00:00:00Z", + "author": { + "name": "The Octocat", + "email": "octocat@nowhere.com" + }, + "committer": { + "name": "The Octocat", + "email": "octocat@nowhere.com" + } + }, + "latest_check_runs_count": 1, + "check_runs_url": "https://api.github.com/repos/octocat/Hello-World/check-suites/5/check-runs" + } + ] +}