-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to only announce PRs from specific users #26
Changes from 6 commits
aebf6f6
e0f019f
a21da03
bf4398d
b2c2a05
629ce54
df509d3
f05d272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ async fn scan_repository( | |
repository_name: String, | ||
github_token: &String, | ||
ignored_users: &Vec<&str>, | ||
announced_users: &Vec<&str>, | ||
ignored_labels: &Vec<&str>, | ||
) -> Result<Vec<GithubPullRequest>, Error> { | ||
info!("Starting PR scan of {}", repository_name); | ||
|
@@ -51,6 +52,18 @@ async fn scan_repository( | |
continue; | ||
} | ||
|
||
if !announced_users.contains(&pull_request.user().id().to_string().as_str()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Wondering if we need to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, thank you for the suggestion! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively check if the Vec is empty and skip this check if it is, I prefer the explicit Optional however. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Ash here, with a preference for the option type. Also, since you know user id's are of type I.e. let announced_users: Option<Vec<i32>> = env::var("GITHUB_ANNOUNCED_USERS")
.ok()
.map(|s| s.split(',').map(|id| id.parse().unwrap()).collect()); And then change the signature of so the final check would look something like 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;
}
} |
||
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; | ||
|
||
for label in pull_request.labels() { | ||
|
@@ -113,6 +126,8 @@ 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 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") | ||
|
@@ -127,6 +142,7 @@ async fn main() -> Result<(), Error> { | |
repository.to_string(), | ||
&github_token, | ||
&ignored_users, | ||
&announced_users, | ||
&ignored_labels, | ||
) | ||
.await?, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure how Github handles this if
inputs.github-announced-users
isn't defined, it might interpet it as an empty string:In which case our code to check if the environment variable is present or not won't correctly detect that the GITHUB_ANNOUNCED_USERS is undefined. Sorry to suggest
Option
but now I'm thinking just checking the length of our announced users array might be better than checking if the variable is present or not!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good spot, thanks @AshCorr. How about we do something like this to handle the empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! Yea that would work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed the change, happy to +1 @AshCorr ?