From 3ece67d62d75b0407e3430b3c3d20011c08b62ef Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 29 May 2021 10:23:33 -0600 Subject: [PATCH] Meta/CI: Remove IRC notifications With the increased volume of PRs being opened and merged lately, multiple people have complained that the IRC is absolutely flooded with SerenityBot posts. Remove the IRC notifications from the CI scripts, and the Meta script that handles parsing the github actions context into an IRC message. --- .github/workflows/cmake.yml | 30 --------- Meta/notify_irc.py | 117 ------------------------------------ 2 files changed, 147 deletions(-) delete mode 100755 Meta/notify_irc.py diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ceed8df089..8eea0379fa 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -238,33 +238,3 @@ jobs: ASAN_OPTIONS: "strict_string_checks=1:check_initialization_order=1:strict_init_order=1" UBSAN_OPTIONS: "print_stacktrace=1:print_summary=1:halt_on_error=1" if: ${{ matrix.with-fuzzers == 'NO_FUZZ' }} - - notify_irc: - needs: [build_and_test_serenity, build_and_test_lagom] - runs-on: ubuntu-20.04 - if: always() && github.repository == 'SerenityOS/serenity' && (github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master')) - - steps: - - uses: actions/checkout@v2 - # Sets environment variable env.WORKFLOW_CONCLUSION to one of [neutral, success, skipped, cancelled, timed_out, action_required, failure] - # depending on result of all needs jobs - - uses: technote-space/workflow-conclusion-action@v2 - - # === NOTIFICATIONS === - - - name: Dump event info - if: always() - # Usually unnecessary, but insanely useful if IRC notifications fail. - run: | - cat <<"EOF" - ${{ toJSON(github.event) }} - ${{ toJSON(needs) }} - EOF - - name: Generate IRC message - if: always() - run: | - ${{ github.workspace }}/Meta/notify_irc.py <<"EOF" - ["${{ github.actor }}", ${{ github.run_id }}, "${{ env.WORKFLOW_CONCLUSION }}", - ${{ toJSON(github.event) }} - ] - EOF diff --git a/Meta/notify_irc.py b/Meta/notify_irc.py deleted file mode 100755 index c8e0eaeed6..0000000000 --- a/Meta/notify_irc.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python3 - -import json -import sys -import requests - -# Must be exactly three lines each! -# No trailing newline! (I.e. keep it as backslash-newline-tripleapostrophe.) -TEMPLATE_PUSH = '''\ -{commit}{post_commit} (pushed master: {status}) {compare} https://github.com/SerenityOS/serenity/actions/runs/{run_id}\ -''' -TEMPLATE_PR = '''\ -{title} ({actor} {action}: {status}) {link} https://github.com/SerenityOS/serenity/actions/runs/{run_id}\ -''' -SERENITY_BOT = 'http://94.130.182.143:8080' - - -def compute_lines(wrapper): - actor, run_id, raw_status, event = wrapper - - if raw_status == 'success': - status = 'The build passed.' - elif raw_status == 'failure': - status = 'The build failed.' - else: - status = 'The build {}(?)'.format(raw_status) - - if 'action' not in event: - # This is a push. - if 'commits' not in event or not event['commits']: - show_msg = '??? (No commits in event?!)' - post_commit = '' - else: - commits = event['commits'] - show_commit = commits[-1]['message'] - if 'skip ci' in show_commit or 'ci skip' in show_commit: - print('User requested to skip IRC notification. Okay!') - return False - # First line of the last commit: - show_msg = show_commit.split('\n')[0] - if len(commits) == 1: - post_commit = '' - elif len(commits) == 2: - post_commit = ' (+1 commit)' - else: - post_commit = ' (+{} commits)'.format(len(commits)) - return TEMPLATE_PUSH.format( - actor=actor, - status=status, - run_id=run_id, - commit=show_msg, - post_commit=post_commit, - compare=event.get('compare', '???'), - ) - elif 'pull_request' in event: - # This is a PR. - raw_action = event['action'] - pull_request = event['pull_request'] - # actor, until here, is whoever caused the action to run - - # if it's a PR we want the author's name in the notification. - actor = pull_request['user']['login'] - if raw_action == 'opened': - action = 'opened' - elif raw_action == 'reopened': - # Reduce spam, don't notify about reopened PRs - return False - elif raw_action == 'synchronize': - # Reduce spam, don't notify about PR updates - return False - else: - action = '{}(?)'.format(raw_action) - if pull_request.get('draft', True): - print("This is a draft PR, so IRC won't be notified.") - print('Note: No rebuild occurs when the PR is "un-drafted"!') - return False - return TEMPLATE_PR.format( - actor=actor, - action=action, - status=status, - run_id=run_id, - title=pull_request.get('title', '???'), - link=pull_request.get('_links', {}).get('html', {}).get('href', '???'), - ) - else: - print('Unrecognized event type?!') - return False - - -def send_notification(line): - """Send a message to IRC channel via HTTP bridge. - - Ars: - line (str): message to send - """ - - print('> ' + line) - try: - response = requests.post(SERENITY_BOT, data={'msg': line}) - except BaseException as e: - print('Notification failed: {}: {}'.format(type(e), e)) - else: - print('Notification result: HTTP {}'.format(response.status_code)) - - -def run_on(json_string): - wrapper = json.loads(json_string) - line = compute_lines(wrapper) - if line: - send_notification(line) - - -def run(): - run_on(sys.stdin.read()) - - -if __name__ == '__main__': - run()