diff --git a/.github/scripts/issueslackbot.py b/.github/scripts/issueslackbot.py deleted file mode 100644 index 989f028..0000000 --- a/.github/scripts/issueslackbot.py +++ /dev/null @@ -1,100 +0,0 @@ -import sys -import os -import datetime -# Import WebClient from Python SDK (github.com/slackapi/python-slack-sdk) -from slack_sdk import WebClient -from slack_sdk.errors import SlackApiError - -# get from environment variables -ISSUE_URL = os.environ.get("ISSUE_URL") -ISSUE_USER = os.environ.get("ISSUE_USER") -ISSUE_USER_IMAGE = os.environ.get("ISSUE_USER_IMAGE") -ISSUE_NUMBER = os.environ.get("ISSUE_NUMBER") -ISSUE_TITLE = os.environ.get("ISSUE_TITLE") -ISSUE_TIME = int(datetime.datetime.timestamp(datetime.datetime.strptime(os.environ.get("ISSUE_TIME"), "%Y-%m-%dT%H:%M:%SZ"))) -ISSUE_BODY = os.environ.get("ISSUE_BODY") -ISSUE_REPO = os.environ.get("ISSUE_REPO") -ISSUE_REPO_URL = os.environ.get("ISSUE_REPO_URL") - -def reportpullrequesturl(channel, slacktoken, msg): - - # WebClient instantiates a client that can call API methods - client = WebClient(token=slacktoken) - - # ID of channel you want to post message to - channel_id = channel - - try: - # Call the conversations.list method using the WebClient - client.chat_postMessage( - channel=channel_id, - text = f'New Issue Created', - blocks= [ - { - "type": "context", - "elements": [ - { - "type": "image", - "image_url": f'{ISSUE_USER_IMAGE}', - "alt_text": "user logo" - }, - { - "type": "mrkdwn", - "text": f'{ISSUE_USER} opened new issue *<{ISSUE_URL}|#{ISSUE_NUMBER}> \n{ISSUE_URL}' - } - ] - }, - { - "type": "divider" - } - ], - attachments= [ - { - "color": "#3ca553", - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": f'*<{ISSUE_URL}|#{ISSUE_NUMBER} {ISSUE_TITLE}>* \n{msg}' - } - }, - { - "type": "context", - "elements": [ - { - "type": "image", - "image_url": 'https://slack-imgs.com/?c=1&o1=wi32.he32.si&url=https%3A%2F%2Fslack.github.com%2Fstatic%2Fimg%2Ffavicon-neutral.png', - "alt_text": "github logo" - }, - { - "type": "mrkdwn", - "text": f'<{ISSUE_REPO_URL}|{ISSUE_REPO}> _|_ _|_ Added by cronbot' - } - ] - } - ] - } - ] - ) - - except SlackApiError as e: - print(f"Error: {e}") - - -def format_pr_template() -> str: - msg = [] - - for line in ISSUE_BODY.splitlines(): - if line[:4] == "### ": - line = '*' + line[4:] + '*' - msg.append(line) - - return "\n".join(msg) - -def main(args): - message = format_pr_template() - reportpullrequesturl(args[1], args[2], message) - -if __name__ == '__main__': - main(sys.argv) \ No newline at end of file diff --git a/.github/scripts/prslackbot.py b/.github/scripts/prslackbot.py deleted file mode 100644 index dae2667..0000000 --- a/.github/scripts/prslackbot.py +++ /dev/null @@ -1,103 +0,0 @@ -import sys -import os -import datetime -# Import WebClient from Python SDK (github.com/slackapi/python-slack-sdk) -from slack_sdk import WebClient -from slack_sdk.errors import SlackApiError - -# get from environment variables -PR_URL = os.environ.get("PR_URL") -PR_USER = os.environ.get("PR_USER") -PR_USER_IMAGE = os.environ.get("PR_USER_IMAGE") -PR_NUMBER = os.environ.get("PR_NUMBER") -PR_TITLE = os.environ.get("PR_TITLE") -PR_TIME = int(datetime.datetime.timestamp(datetime.datetime.strptime(os.environ.get("PR_TIME"), "%Y-%m-%dT%H:%M:%SZ"))) -PR_BODY = os.environ.get("PR_BODY") -PR_REPO = os.environ.get("PR_REPO") -PR_REPO_URL = os.environ.get("PR_REPO_URL") -NUM_COMMIT = os.environ.get("NUM_COMMIT") -HEAD_REPO_NAME = os.environ.get("HEAD_REPO_NAME") -BASE_REPO_NAME = os.environ.get("BASE_REPO_NAME") - -def reportpullrequesturl(channel, slacktoken, msg): - - # WebClient instantiates a client that can call API methods - client = WebClient(token=slacktoken) - - # ID of channel you want to post message to - channel_id = channel - - try: - # Call the conversations.list method using the WebClient - client.chat_postMessage( - channel=channel_id, - text = f'New pull request by KCNilssen', - blocks= [ - { - "type": "context", - "elements": [ - { - "type": "image", - "image_url": f'{PR_USER_IMAGE}', - "alt_text": "user logo" - }, - { - "type": "mrkdwn", - "text": f'{PR_USER} wants to merge {NUM_COMMIT} commits into <{PR_REPO_URL}'+f'/tree/'+f'{BASE_REPO_NAME}|{BASE_REPO_NAME}> from <{PR_REPO_URL}'+f'/tree/'+f'{HEAD_REPO_NAME}|{HEAD_REPO_NAME}> \n{PR_URL}' - } - ] - }, - { - "type": "divider" - } - ], - attachments= [ - { - "color": "#3ca553", - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": f'*<{PR_URL}|#{PR_NUMBER} {PR_TITLE}>* \n{msg}' - } - }, - { - "type": "context", - "elements": [ - { - "type": "image", - "image_url": 'https://slack-imgs.com/?c=1&o1=wi32.he32.si&url=https%3A%2F%2Fslack.github.com%2Fstatic%2Fimg%2Ffavicon-neutral.png', - "alt_text": "github logo" - }, - { - "type": "mrkdwn", - "text": f'<{PR_REPO_URL}|{PR_REPO}> _|_ _|_ Added by cronbot' - } - ] - } - ] - } - ] - ) - - except SlackApiError as e: - print(f"Error: {e}") - - -def format_pr_template() -> str: - msg = [] - - for line in PR_BODY.splitlines(): - if line[:4] == "### ": - line = '*' + line[4:] + '*' - msg.append(line) - - return "\n".join(msg) - -def main(args): - message = format_pr_template() - reportpullrequesturl(args[1], args[2], message) - -if __name__ == '__main__': - main(sys.argv) \ No newline at end of file diff --git a/.github/scripts/pytest_report_issues.py b/.github/scripts/pytest_report_issues.py deleted file mode 100644 index 00e2d31..0000000 --- a/.github/scripts/pytest_report_issues.py +++ /dev/null @@ -1,149 +0,0 @@ -import sys -import re -from slack_sdk import WebClient -from slack_sdk.errors import SlackApiError - -def cronbot_post_uka(slack_webclient_token, channel_id, message, status, linecolor): - - # WebClient instantiates a client that can call API methods - client = WebClient(token=slack_webclient_token) - - try: - # Call the conversations.list method using the WebClient - client.chat_postMessage( - channel=channel_id, - text=f'{status} Test for mlbstatsapi', - attachments= - [ - { - "color": f'{linecolor}', - "blocks": [ - { - "type": "context", - "elements": [ - { - "type": "mrkdwn", - "text": f"```\n{message}\n```" - } - ] - }, - ] - } - ] - ) - - except SlackApiError as e: - print(f"Error: {e}") - -def escape_ansi(line): - ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[@-~]') - return ansi_escape.sub('', line) - -def generate_outputstring(from_list) -> str: - - short_test_summary_info_types = ["FAILED", "ERROR", "SKIPPED", - "XFAILED", "XPASSED", "PASSED"] - - testing_output = "" - - for output in from_list: - - output = escape_ansi(output) - - if len(output) > 78: - - if output[:10] == "==========": - output = output.replace("=", "") - # print ([*output]) - output = '{:=^78}'.format(output[:-2]) + '\r\n' - - elif output[-8] == "[" and output[-3] == "]": - if output[-12:-8] != " ": - output = list(output) - output[-15] = '.' - output[-14] = '.' - output[-13] = '.' - output[-12] = ' ' - output[-11] = ' ' - output[-10] = ' ' - output[-9] = ' ' - output = ''.join(output) - output = output[:72] + output[-8:] - - elif output[:10] == "collecting": - output = ' '.join(output[16:].split()[-3:]) + '\r\n' - - elif output.split()[0] in short_test_summary_info_types: - output_listified = output.split() - output = ' '.join(output_listified[:2]) - output += '\r\n' - - temp_string = ' ' * (len(output_listified[0])) - for word in output_listified[2:]: - if len(temp_string) + 1 + len(word) <= 78: - temp_string+=" " + word - else: - if len(word) > 78 - len(output_listified[0]) + 1: - for char in word: - if len(temp_string) >= 78: - temp_string += '\r\n' - output += temp_string - temp_string = ' ' * (len(output_listified[0]) + 1) - temp_string += char - else: - temp_string += " " + char - else: - temp_string += '\r\n' - output += temp_string - temp_string = ' ' * (len(output_listified[0]) + 1) - temp_string += word - - output += temp_string - output += '\r\n' - - else: - output = output[:75] + "...\r\n" - - if output[0] == "." and output[-8] == "[" and output[-3] == "]": - pass - else: - testing_output+=output - - return testing_output - - -if __name__ == "__main__": - channelid = sys.argv[1] - token = sys.argv[2] - - output_list = [] - - line = None - - for line in sys.stdin: - output_list.append(line) - - if not line: - statusmessage = "failed" - statuscolor = "#cd3920" - elif ("failed" in line or "xfailed" in line): - statusmessage = "Failed" - statuscolor = "#cd3920" - elif ("errors" in line or "error" in line or "SKIPPED" in line): - statusmessage = "Error with" - statuscolor = "#f2a029" - else: - statusmessage = "Successful" - statuscolor = "#3ca553" - - outputbody = generate_outputstring(output_list) - - cronbot_post_uka(token, channelid, outputbody, statusmessage, statuscolor) - - # Once the slack message has been sent, if our periodic test fails, then - # exit with exit code 1. In turn failing the actions job. Print the - # result of the tests before so we have access in github actions to the - # tests results. - if statusmessage == "failed": - print (outputbody) - sys.exit(1) \ No newline at end of file diff --git a/.github/workflows/catch-and-report.yml b/.github/workflows/catch-and-report.yml deleted file mode 100644 index 5cdb34b..0000000 --- a/.github/workflows/catch-and-report.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: External tests - Bidaily - -on: - schedule: - # Run every day at 10:25 am and 4:25 pm PST - - cron: '25 17,23 * * *' - -jobs: - catch_errors_and_report: - - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10"] - - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade pytest - python3 -m pip install --upgrade requests - python3 -m pip install --upgrade slack_sdk - python3 -m pip install --upgrade requests_mock - - name: Test and report - run: | - script -q -c 'python3 -m pytest --tb=no tests/*' /dev/null | python3 ./.github/scripts/pytest_report_issues.py ${{ secrets.BOT_CHANNEL }} ${{ secrets.SLACK_WEBCLIENT_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/issues-slack-bot.yml b/.github/workflows/issues-slack-bot.yml deleted file mode 100644 index 392b84b..0000000 --- a/.github/workflows/issues-slack-bot.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Report Issue Creation - -on: - issues: - types: [opened] - -jobs: - reportNewIssue: - - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10"] - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade slack_sdk - - name: Report Issue - env: - ISSUE_URL: ${{ github.event.issue.html_url }} - ISSUE_USER: ${{ github.event.issue.user.login }} - ISSUE_USER_IMAGE: ${{ github.event.issue.user.avatar_url }} - ISSUE_NUMBER: ${{ github.event.issue.number }} - ISSUE_TITLE: ${{ github.event.issue.title }} - ISSUE_TIME: ${{ github.event.issue.created_at }} - ISSUE_BODY: ${{ github.event.issue.body }} - ISSUE_REPO: ${{ github.event.repository.full_name }} - ISSUE_REPO_URL: ${{ github.event.repository.html_url }} - - run: | - python3 ./.github/scripts/issueslackbot.py ${{ secrets.ISSUE_CHANNEL }} ${{ secrets.SLACK_WEBCLIENT_TOKEN }} - \ No newline at end of file diff --git a/.github/workflows/post-pr-url.yml b/.github/workflows/post-pr-url.yml deleted file mode 100644 index dbffd0a..0000000 --- a/.github/workflows/post-pr-url.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Report push request url - -on: - pull_request: - types: [opened] - -jobs: - reportPR: - - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10"] - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python3 -m pip install --upgrade pip - python3 -m pip install --upgrade slack_sdk - - name: Report PR url - env: - PR_URL: ${{ github.event.pull_request.html_url }} - PR_USER: ${{ github.event.pull_request.user.login }} - PR_USER_IMAGE: ${{ github.event.pull_request.user.avatar_url }} - PR_NUMBER: ${{ github.event.pull_request.number }} - PR_TITLE: ${{ github.event.pull_request.title }} - PR_TIME: ${{ github.event.pull_request.created_at }} - PR_BODY: ${{ github.event.pull_request.body }} - PR_REPO: ${{ github.event.repository.full_name }} - PR_REPO_URL: ${{ github.event.repository.html_url }} - NUM_COMMIT: ${{ github.event.pull_request.commits }} - HEAD_REPO_NAME: ${{ github.event.pull_request.head.ref }} - BASE_REPO_NAME: ${{ github.event.pull_request.base.ref }} - - run: | - python3 ./.github/scripts/prslackbot.py ${{ secrets.PR_CHANNEL }} ${{ secrets.SLACK_WEBCLIENT_TOKEN }}