Skip to content

Commit

Permalink
allow ignoring users
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdulhadi Celenlioglu committed Oct 9, 2024
1 parent 3df67db commit c2b43e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
```
10 changes: 8 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions notification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c2b43e2

Please sign in to comment.