diff --git a/.github/workflows/daily_collection.yaml b/.github/workflows/daily_collection.yaml index ce71fc0..d6b879c 100644 --- a/.github/workflows/daily_collection.yaml +++ b/.github/workflows/daily_collection.yaml @@ -2,11 +2,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" schedule: - cron: '0 0 * * *' @@ -50,7 +45,3 @@ jobs: - name: Install dependencies run: | uv pip install .[dev] - - name: Slack alert if failure - run: python -m gitmetrics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} - env: - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/.github/workflows/daily_summarize.yaml b/.github/workflows/daily_summarize.yaml index 309443b..c09f0b3 100644 --- a/.github/workflows/daily_summarize.yaml +++ b/.github/workflows/daily_summarize.yaml @@ -2,11 +2,6 @@ name: Daily Summarize 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" schedule: - cron: '0 1 * * *' @@ -64,11 +59,3 @@ jobs: - name: Install dependencies run: | uv pip install .[dev] - - name: Slack alert if failure - run: | - uv run python -m gitmetrics.slack_utils \ - -r ${{ github.run_id }} \ - -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} \ - -m 'Summarize GitMetrics build failed :fire: :dumpster-fire: :fire:' - env: - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/.github/workflows/traffic_collection.yaml b/.github/workflows/traffic_collection.yaml index 50d06d0..fa4c58a 100644 --- a/.github/workflows/traffic_collection.yaml +++ b/.github/workflows/traffic_collection.yaml @@ -2,11 +2,6 @@ name: Biweekly Traffic 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" schedule: - cron: "0 0 */14 * *" # Runs every 14 days at midnight UTC @@ -48,7 +43,3 @@ jobs: - name: Install dependencies run: | uv pip install .[dev] - - name: Slack alert if failure - run: python -m gitmetrics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} - env: - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/.github/workflows/weekly_collection.yaml b/.github/workflows/weekly_collection.yaml index 87e133f..3e14b3e 100644 --- a/.github/workflows/weekly_collection.yaml +++ b/.github/workflows/weekly_collection.yaml @@ -2,11 +2,6 @@ name: Weekly 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" schedule: - cron: '1 0 * * 0' @@ -56,7 +51,3 @@ jobs: - name: Install dependencies run: | uv pip install .[dev] - - name: Slack alert if failure - run: python -m gitmetrics.slack_utils -r ${{ github.run_id }} -c ${{ github.event.inputs.slack_channel || 'sdv-alerts' }} - env: - SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} diff --git a/gitmetrics/slack_utils.py b/gitmetrics/slack_utils.py deleted file mode 100644 index a317645..0000000 --- a/gitmetrics/slack_utils.py +++ /dev/null @@ -1,98 +0,0 @@ -"""Utility functions for Slack integration.""" - -import argparse -import os - -from slack_sdk import WebClient - -GITHUB_URL_PREFIX = 'https://github.com/sdv-dev/gitmetrics/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'GitMetrics build failed :fire: :dumpster-fire: :fire: 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.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 bee76fe..9aef6a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,6 @@ include = ['gitmetrics', 'gitmetrics.*'] dev = [ "ruff >= 0.9.8", "invoke", - "slack-sdk >= 3.34,<4.0", ] test = [ 'pytest >= 8.1.1',