Skip to content

Commit

Permalink
Merge pull request #26 from guardian/add-included-users-list
Browse files Browse the repository at this point in the history
Add an option to only announce PRs from specific users
  • Loading branch information
aracho1 authored Jun 6, 2024
2 parents a2cfca8 + f05d272 commit fc5bcb6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ This action automatically sends a message to google chats detailing the list of

**Required** PR labels to ignore when scanning for PR's. Defaults to `Stale`

## `github-announced-users`

**Optional** Only Github users to announce PR's from. If set, other users' PR's will be ignored.

## Example usage

```yaml
Expand All @@ -48,6 +52,9 @@ export GOOGLE_WEBHOOK_URL=https://chats.google.com...
export GITHUB_IGNORED_USERS=49699333
# List of labels to ignore when scanning for PR's
export GITHUB_IGNORED_LABELS=dependencies
# List of users to announce PR's from (if set, other users will be ignored)
# (e.g. 49699333 is dependabot, 19733683 is snykbot, 108136057 is scala steward)
export GITHUB_ANNOUNCED_USERS=49699333,19733683,108136057

cargo run
```
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
description: "Comma delimited list of user ID's to ignore"
required: true
default: "49699333"
github-announced-users:
description: "Comma delimited list of user ID's to announce"
required: false
default: ""
github-ignored-labels:
description: "Comma delimited list of label names to ignore"
required: true
Expand All @@ -32,6 +36,7 @@ runs:
GITHUB_REPOSITORIES: ${{ inputs.github-repositories }}
GITHUB_TOKEN: ${{ inputs.github-token }}
GITHUB_IGNORED_USERS: ${{ inputs.github-ignored-users }}
GITHUB_ANNOUNCED_USERS: ${{ inputs.github-announced-users }}
GITHUB_IGNORED_LABELS: ${{ inputs.github-ignored-labels }}
GOOGLE_WEBHOOK_URL: ${{ inputs.google-webhook-url }}
SHOW_PR_AGE: ${{ inputs.show-pr-age }}
25 changes: 25 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async fn scan_repository(
repository_name: String,
github_token: &String,
ignored_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 @@ -51,6 +52,20 @@ async fn scan_repository(
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;

for label in pull_request.labels() {
Expand Down Expand Up @@ -113,6 +128,15 @@ 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: Option<Vec<i32>> = env::var("GITHUB_ANNOUNCED_USERS")
.ok()
.and_then(|s| {
if s.is_empty() {
None
} else {
Some(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 All @@ -127,6 +151,7 @@ async fn main() -> Result<(), Error> {
repository.to_string(),
&github_token,
&ignored_users,
&announced_users,
&ignored_labels,
)
.await?,
Expand Down

0 comments on commit fc5bcb6

Please sign in to comment.