Skip to content

Commit

Permalink
Ignore certain users when a repo has the "maintenance" topic
Browse files Browse the repository at this point in the history
  • Loading branch information
AshCorr committed Aug 2, 2024
1 parent d2e9ab6 commit eac7587
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
description: "Comma delimited list of label names to ignore"
required: true
default: "Stale"
github-maintenance-ignored-users:
description: "Comma delimited list of user ID's to ignore on repos tagged as maintenance"
required: true
default: "49699333"
show-pr-age:
description: "Include PR age in chat message output"
required: false
Expand All @@ -38,5 +42,6 @@ runs:
GITHUB_IGNORED_USERS: ${{ inputs.github-ignored-users }}
GITHUB_ANNOUNCED_USERS: ${{ inputs.github-announced-users }}
GITHUB_IGNORED_LABELS: ${{ inputs.github-ignored-labels }}
GITHUB_MAINTENANCE_IGNORED_USERS: ${{ inputs.github-maintenance-ignored-users }}
GOOGLE_WEBHOOK_URL: ${{ inputs.google-webhook-url }}
SHOW_PR_AGE: ${{ inputs.show-pr-age }}
1 change: 1 addition & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct GithubBranch {
pub struct GithubRepository {
pub name: String,
pub visibility: String,
pub topics: Vec<String>,
}

#[derive(Deserialize, Debug)]
Expand Down
29 changes: 28 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async fn scan_repository(
ignored_users: &[&str],
announced_users: &Option<Vec<usize>>,
ignored_labels: &[&str],
ignored_maintenance_users: &[&str],
) -> Result<Vec<GithubPullRequest>, Error> {
info!("\nStarting PR scan of {}", repository_name);

Expand All @@ -29,7 +30,10 @@ async fn scan_repository(
let is_public = pull_request.head.repo.visibility == PUBLIC_REPO;

if is_public {
info!("Processing PR {}({})", pull_request.id, pull_request.title);
info!(
"Processing PR {}({}) by {}",
pull_request.id, pull_request.title, pull_request.user.id
);
}

if pull_request.draft {
Expand All @@ -55,6 +59,25 @@ async fn scan_repository(
continue;
}

if pull_request
.head
.repo
.topics
.contains(&"maintenance".to_string())
&& ignored_maintenance_users.contains(&pull_request.user.id.to_string().as_str())
{
if is_public {
info!(
"Ignoring PR {}({}) as it was raised by a user {}({}) which is ignored in maintenance mode",
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) {
if is_public {
Expand Down Expand Up @@ -145,6 +168,9 @@ async fn main() -> Result<(), Error> {
});
let ignored_labels: String = env::var("GITHUB_IGNORED_LABELS").unwrap_or("".to_string());
let ignored_labels: Vec<&str> = ignored_labels.split(',').collect();
let ignored_maintenance_users: String =
env::var("GITHUB_IGNORED_MAINTENANCE_USERS").unwrap_or("".to_string());
let ignored_maintenance_users: Vec<&str> = ignored_maintenance_users.split(',').collect();
let show_pr_age: bool = env::var("SHOW_PR_AGE")
.map(|v| v == "true")
.unwrap_or(false);
Expand All @@ -159,6 +185,7 @@ async fn main() -> Result<(), Error> {
&ignored_users,
&announced_users,
&ignored_labels,
&ignored_maintenance_users,
)
.await?,
);
Expand Down

0 comments on commit eac7587

Please sign in to comment.