diff --git a/README.md b/README.md index 071cdec..2667b3f 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ You need to set the following environment variables: - `SLACK_TOKEN`: This is your Slack token, which you can obtain [here](https://api.slack.com/authentication/basics). - `DEFAULT_SLACK_EMAIL`: This is the default email address to be notified when the author cannot be identified. +- `IGNORE_USERS`: A comma-separated list of usernames to ignore. ### Build Your Own Image @@ -69,5 +70,6 @@ To run the Docker container: docker run -v ./author_mapping.yml:/config/author_mapping.yml \ -e SLACK_TOKEN=your_slack_token \ -e DEFAULT_SLACK_EMAIL=your_default_email \ + -e IGNORE_USERS="some[bot],another[bot]" \ -p 8080:8080 -d failedkite ``` diff --git a/config.py b/config.py index bb9a6b2..21a88d7 100644 --- a/config.py +++ b/config.py @@ -5,8 +5,10 @@ class Config: def __init__(self): - self.slack_token = self._get_env_variable('SLACK_TOKEN') - self.default_slack_email = self._get_env_variable('DEFAULT_SLACK_EMAIL') + self.slack_token: str = self._get_env_variable('SLACK_TOKEN') + self.default_slack_email: str = self._get_env_variable('DEFAULT_SLACK_EMAIL') + ignore_users: str | None = self._get_optional_env_variable('IGNORE_USERS') + self.ignore_users: list[str] | None = ignore_users.split(',') if ignore_users else None self.author_mapping = self._load_author_mapping('/config/author_mapping.yml') @staticmethod @@ -16,6 +18,10 @@ def _get_env_variable(name): raise ValueError(f"{name} environment variable not set") return value + @staticmethod + def _get_optional_env_variable(name, default=None): + return os.environ.get(name, default) + @staticmethod def _load_author_mapping(file_path): with open(file_path, 'r') as mapping_file: diff --git a/notification_service.py b/notification_service.py index 508ee72..590c71b 100644 --- a/notification_service.py +++ b/notification_service.py @@ -30,6 +30,12 @@ def notify(self, build): email = build_creator.get("email") elif build_author: username = build_author.get("username") + + ignore_users: list[str] | None = self.config.ignore_users + if ignore_users and username in ignore_users: + build_user_message = f"The username={username} was ignored for the failing build url={build_web_url}" + return build_user_message, 200 + slack_email = self.config.author_mapping.get(username) if slack_email: