From 7546efc1a7287876c12f4112892554d813bdda6a Mon Sep 17 00:00:00 2001 From: Plamen Valentinov Kolev Date: Tue, 23 Sep 2025 18:35:31 +0200 Subject: [PATCH] Remove slack utils and slack alerting from Git Metrics --- .github/workflows/daily_collection.yaml | 12 --- .github/workflows/daily_summarization.yaml | 13 --- pymetrics/slack_utils.py | 105 --------------------- pyproject.toml | 1 - 4 files changed, 131 deletions(-) delete mode 100644 pymetrics/slack_utils.py diff --git a/.github/workflows/daily_collection.yaml b/.github/workflows/daily_collection.yaml index 9810d74..cb15800 100644 --- a/.github/workflows/daily_collection.yaml +++ b/.github/workflows/daily_collection.yaml @@ -3,10 +3,6 @@ name: Daily Collection on: workflow_dispatch: inputs: - slack_channel: - description: Slack channel to post the error message to if the builds fail. - required: false - default: "sdv-alerts-debug" max_days_pypi: description: 'Maximum number of days to collect, starting from today for PyPI.' required: false @@ -80,11 +76,3 @@ jobs: - name: Install pip and dependencies run: | uv pip install -e .[dev] - - name: Slack alert if failure - run: | - uv run python -m pymetrics.slack_utils \ - -r ${{ github.run_id }} \ - -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} \ - -m 'Daily Collection PyMetrics failed :fire: :dumpster-fire: :fire:' - env: - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/daily_summarization.yaml b/.github/workflows/daily_summarization.yaml index f777855..6ca01b6 100644 --- a/.github/workflows/daily_summarization.yaml +++ b/.github/workflows/daily_summarization.yaml @@ -2,11 +2,6 @@ name: Daily Summarization on: workflow_dispatch: - inputs: - slack_channel: - description: Slack channel to post the error message to if the summarize job fail. - required: false - default: "sdv-alerts-debug" schedule: - cron: '0 1 * * *' @@ -67,11 +62,3 @@ jobs: - name: Install pip and dependencies run: | uv pip install .[dev] - - name: Slack alert if failure - run: | - uv run python -m pymetrics.slack_utils \ - -r ${{ github.run_id }} \ - -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} \ - -m 'Daily Summarization PyMetrics failed :fire: :dumpster-fire: :fire:' - env: - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} \ No newline at end of file diff --git a/pymetrics/slack_utils.py b/pymetrics/slack_utils.py deleted file mode 100644 index c48ab71..0000000 --- a/pymetrics/slack_utils.py +++ /dev/null @@ -1,105 +0,0 @@ -"""Utility functions for Slack integration.""" - -import argparse -import os - -from slack_sdk import WebClient - -GITHUB_URL_PREFIX = 'https://github.com/sdv-dev/pymetrics/actions/runs/' -DEFAULT_SLACK_CHANNEL = 'sdv-alerts-debug' - - -def _get_slack_client(): - """Create an authenticated Slack client. - - Returns: - WebClient: - An authenticated Slack WebClient instance. - """ - token = os.getenv('SLACK_TOKEN') - client = WebClient(token=token) - return client - - -def post_slack_message(channel, text): - """Post a message to a Slack channel. - - Args: - channel (str): - The name of the channel to post to. - text (str): - The message to send to the channel. - - Returns: - SlackResponse: - Response from Slack API call - """ - client = _get_slack_client() - response = client.chat_postMessage(channel=channel, text=text) - if not response['ok']: - error = response.get('error', 'unknown_error') - msg = f'{error} occured trying to post message to {channel}' - raise RuntimeError(msg) - - return response - - -def post_slack_message_in_thread(channel, text, thread_ts): - """Post a message as a threaded reply in a Slack channel. - - Args: - channel (str): - The name of the channel to post to. - text (str): - The message to send as a reply in the thread. - thread_ts (str): - The timestamp of the message that starts the thread. - - Returns: - SlackResponse: - Response from Slack API call. - """ - client = _get_slack_client() - response = client.chat_postMessage(channel=channel, text=text, thread_ts=thread_ts) - if not response['ok']: - error = response.get('error', 'unknown_error') - msg = f'{error} occurred trying to post threaded message to {channel}' - raise RuntimeError(msg) - - return response - - -def send_alert(args): - """Send an alert message to a slack channel.""" - url = GITHUB_URL_PREFIX + args.run_id - message = f'{args.message} See errors <{url}|here>' - post_slack_message(args.channel, message) - - -def get_parser(): - """Get the parser.""" - parser = argparse.ArgumentParser(description='Function to alert when a Github workflow fails.') - parser.add_argument('-r', '--run-id', type=str, help='The id of the github run.') - parser.add_argument( - '-c', - '--channel', - type=str, - help='The slack channel to post to.', - default=DEFAULT_SLACK_CHANNEL, - ) - parser.add_argument( - '-m', - '--message', - type=str, - help='The message to post.', - default='PyMetrics build failed :fire: :dumpster-fire: :fire:', - ) - parser.set_defaults(action=send_alert) - - return parser - - -if __name__ == '__main__': - parser = get_parser() - args = parser.parse_args() - args.action(args) diff --git a/pyproject.toml b/pyproject.toml index b1d0de7..595e1a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,6 @@ include = ['pymetrics', 'pymetrics.*'] dev = [ "ruff>=0.9.8", "invoke", - "slack-sdk>=3.34,<4.0", ] test = [ 'pytest >= 8.1.1',