diff --git a/Cargo.lock b/Cargo.lock index 55d9bef..70a0b5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -262,18 +262,6 @@ dependencies = [ "pin-utils", ] -[[package]] -name = "getset" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "gimli" version = "0.29.0" @@ -286,7 +274,6 @@ version = "0.1.0" dependencies = [ "anyhow", "chrono", - "getset", "log", "reqwest", "serde", @@ -626,7 +613,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -700,30 +687,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.86" @@ -880,7 +843,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -953,17 +916,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.68" @@ -1089,7 +1041,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", ] [[package]] @@ -1184,12 +1136,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "want" version = "0.3.1" @@ -1226,7 +1172,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn", "wasm-bindgen-shared", ] @@ -1260,7 +1206,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index b099ee6..984f3c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,5 @@ serde_json = "1.0.79" log = "0.4.14" simple_logger = "2.1.0" anyhow = "1.0.53" -getset = "0.1.2" chrono = { version = "0.4.19", features = ["serde"] } url = "2.5.0" diff --git a/src/github.rs b/src/github.rs index ca07436..e47dbaa 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1,53 +1,47 @@ use anyhow::{Context, Result}; use chrono::{DateTime, Utc}; -use getset::Getters; use serde::Deserialize; -#[derive(Deserialize, Getters, Debug)] -#[getset(get = "pub", get_copy = "pub")] +#[derive(Deserialize, Debug)] pub struct GithubPullRequest { - id: usize, - url: String, - html_url: String, - title: String, - user: GithubUser, - draft: bool, - number: usize, - head: GithubBranch, - labels: Vec, - created_at: DateTime, + pub id: usize, + pub url: String, + pub html_url: String, + pub title: String, + pub user: GithubUser, + pub draft: bool, + pub number: usize, + pub head: GithubBranch, + pub labels: Vec, + pub created_at: DateTime, } -#[derive(Deserialize, Getters, Debug)] -#[getset(get = "pub", get_copy = "pub")] +#[derive(Deserialize, Debug)] pub struct GithubBranch { - repo: GithubRepository, + pub repo: GithubRepository, } -#[derive(Deserialize, Getters, Debug)] -#[getset(get = "pub", get_copy = "pub")] +#[derive(Deserialize, Debug)] pub struct GithubRepository { - name: String, + pub name: String, + pub visibility: String, } -#[derive(Deserialize, Getters, Debug)] -#[getset(get = "pub", get_copy = "pub")] +#[derive(Deserialize, Debug)] pub struct GithubLabel { - name: String, + pub name: String, } -#[derive(Deserialize, Getters, Debug)] -#[getset(get = "pub")] +#[derive(Deserialize, Debug)] pub struct GithubUser { - id: usize, - login: String, + pub id: usize, + pub login: String, } -#[derive(Deserialize, Getters, Debug)] -#[getset(get = "pub")] +#[derive(Deserialize, Debug)] pub struct GithubReview { - id: usize, - state: String, + pub id: usize, + pub state: String, } impl GithubPullRequest { @@ -74,7 +68,7 @@ impl GithubPullRequest { } pub async fn reviews(&self, token: &str) -> Result> { - let api_url = format!("{}/reviews", self.url()); + let api_url = format!("{}/reviews", self.url); let response = reqwest::Client::new() .get(&api_url) diff --git a/src/main.rs b/src/main.rs index d0cc6fa..0634caf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -extern crate getset; - mod github; mod google; @@ -11,6 +9,8 @@ use std::env; use github::GithubPullRequest; use google::GoogleChatMessage; +const PUBLIC_REPO: &str = "public"; + async fn scan_repository( repository_name: &str, github_token: &str, @@ -26,56 +26,59 @@ async fn scan_repository( info!("Found {} PR's", pull_requests.len()); for pull_request in pull_requests { - info!( - "Processing PR {}({})", - pull_request.id(), - pull_request.title() - ); + let is_public = pull_request.head.repo.visibility == PUBLIC_REPO; - if *pull_request.draft() { - info!( - "Ignoring PR {}({}) as it is a draft", - pull_request.id(), - pull_request.title() - ); + info!("Processing PR {}({})", pull_request.id, pull_request.title); + + if pull_request.draft { + if is_public { + info!( + "Ignoring PR {}({}) as it is a draft", + pull_request.id, pull_request.title + ); + } continue; } - if ignored_users.contains(&pull_request.user().id().to_string().as_str()) { - info!( - "Ignoring PR {}({}) as it was raised by an ignored user {}({})", - pull_request.id(), - pull_request.title(), - pull_request.user().id(), - pull_request.user().login() - ); + if ignored_users.contains(&pull_request.user.id.to_string().as_str()) { + if is_public { + info!( + "Ignoring PR {}({}) as it was raised by an ignored user {}({})", + pull_request.id, + pull_request.title, + pull_request.user.id, + pull_request.user.login + ); + } continue; } if let Some(announced_users) = announced_users { - if !announced_users.contains(pull_request.user().id()) { - info!("Users to announce: {:?}", announced_users); - info!( + if !announced_users.contains(&pull_request.user.id) { + if is_public { + info!("Users to announce: {:?}", announced_users); + info!( "Ignoring PR {}({}) as it was raised by a user not included in the announced users list {}({})", - pull_request.id(), - pull_request.title(), - pull_request.user().id(), - pull_request.user().login() + pull_request.id, + pull_request.title, + pull_request.user.id, + pull_request.user.login ); + } continue; } } let mut has_ignore_label = false; - for label in pull_request.labels() { - if ignored_labels.contains(&label.name().as_str()) { - info!( - "Ignoring PR {}({}) as it has an ignored label ({})", - pull_request.id(), - pull_request.title(), - label.name() - ); + for label in &pull_request.labels { + if ignored_labels.contains(&label.name.as_str()) { + if is_public { + info!( + "Ignoring PR {}({}) as it has an ignored label ({})", + pull_request.id, pull_request.title, label.name + ); + } has_ignore_label = true; } } @@ -86,24 +89,26 @@ async fn scan_repository( let pull_request_reviews = pull_request.reviews(github_token).await?; - info!( - "Found {} reviews for PR {}({})", - pull_request_reviews.len(), - pull_request.id(), - pull_request.title() - ); + if is_public { + info!( + "Found {} reviews for PR {}({})", + pull_request_reviews.len(), + pull_request.id, + pull_request.title + ); + } let mut has_approved_reviews = false; for pull_request_review in pull_request_reviews { - info!( - "Processing review {} for PR {}({})", - pull_request_review.id(), - pull_request.id(), - pull_request.title() - ); + if is_public { + info!( + "Processing review {} for PR {}({})", + pull_request_review.id, pull_request.id, pull_request.title + ); + } - if pull_request_review.state() == "APPROVED" { + if pull_request_review.state == "APPROVED" { has_approved_reviews = true; } } @@ -200,14 +205,14 @@ async fn main() -> Result<(), Error> { fn make_message(pull_request: GithubPullRequest, show_pr_age: bool) -> String { let message = format!( "<{}|{}#{}> - {}", - pull_request.html_url().replace("https://", ""), - pull_request.head().repo().name(), - pull_request.number(), - pull_request.title() + pull_request.html_url.replace("https://", ""), + pull_request.head.repo.name, + pull_request.number, + pull_request.title ); let age_output = match show_pr_age { - true => format!(" - (_{}_)", get_age(Utc::now(), *pull_request.created_at())), + true => format!(" - (_{}_)", get_age(Utc::now(), pull_request.created_at)), false => "".to_string(), };