Skip to content

Commit

Permalink
refactor and change announced_users type
Browse files Browse the repository at this point in the history
  • Loading branch information
aracho1 committed Jun 4, 2024
1 parent 629ce54 commit df509d3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn scan_repository(
repository_name: String,
github_token: &String,
ignored_users: &Vec<&str>,
announced_users: &Vec<&str>,
announced_users: &Option<Vec<i32>>,
ignored_labels: &Vec<&str>,
) -> Result<Vec<GithubPullRequest>, Error> {
info!("Starting PR scan of {}", repository_name);
Expand Down Expand Up @@ -52,16 +52,18 @@ async fn scan_repository(
continue;
}

if !announced_users.contains(&pull_request.user().id().to_string().as_str()) {
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()
);
continue;
if let Some(announced_users) = announced_users {
if !announced_users.contains(&pull_request.user().id()) {
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()
);
continue;
}
}

let mut has_ignore_label = false;
Expand Down Expand Up @@ -126,8 +128,9 @@ async fn main() -> Result<(), Error> {
env::var("GOOGLE_WEBHOOK_URL").context("GOOGLE_WEBHOOK_URL must be set")?;
let ignored_users: String = env::var("GITHUB_IGNORED_USERS").unwrap_or("".to_string());
let ignored_users: Vec<&str> = ignored_users.split(",").collect();
let announced_users: String = env::var("GITHUB_ANNOUNCED_USERS").unwrap_or("".to_string());
let announced_users: Vec<&str> = announced_users.split(",").collect();
let announced_users: Option<Vec<i32>> = env::var("GITHUB_ANNOUNCED_USERS")
.ok()
.map(|s| s.split(',').map(|id| id.parse().unwrap()).collect());
let ignored_labels: String = env::var("GITHUB_IGNORED_LABELS").unwrap_or("".to_string());
let ignored_labels: Vec<&str> = ignored_labels.split(",").collect();
let show_pr_age: bool = env::var("SHOW_PR_AGE")
Expand Down

0 comments on commit df509d3

Please sign in to comment.