Skip to content

Commit

Permalink
v0.5.2 main release
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattsface committed Jan 9, 2023
0 parents commit c283d96
Show file tree
Hide file tree
Showing 176 changed files with 36,398 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Why

Background/reason for the PR, e.g. what problem is being solved by the changes

### What

Overview of the changes made

### Tests

How was this tested? Any additional testing done outside automated tests, or no testing needed?

### Risk and impact

What is the risk level of the change and **why?**

- Minimal / Normal / High

What is the impact if something does go wrong with this PR?
103 changes: 103 additions & 0 deletions .github/scripts/prslackbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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}> _|_ <!date^{PR_TIME}^' + '{date_pretty} at {time}|' + f'{PR_TIME}> _|_ 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)
139 changes: 139 additions & 0 deletions .github/scripts/pytest_report_issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
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"

cronbot_post_uka(token, channelid, generate_outputstring(output_list), statusmessage, statuscolor)
41 changes: 41 additions & 0 deletions .github/workflows/build-and-test-mlbstatsapi-prd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Python Build MLBstats API

on:
push:
branches:
- main
jobs:
build:

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 build
python3 -m pip install --upgrade requests
python3 -m pip install --upgrade requests_mock
- name: Test with mocks with pytest
run: |
python3 -m pytest tests/mock_tests/*
- name: Test external tests with pytest
run: |
python3 -m pytest tests/external_tests/*
- name: build and install
run: |
python3 -m build
python3 -m pip install .
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/build-and-test-mlbstatsapi-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build

on:
push:
branches:
- development

jobs:
build:

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 build
python3 -m pip install --upgrade requests
python3 -m pip install --upgrade requests_mock
- name: Test with mocks with pytest
run: |
python3 -m pytest tests/mock_tests/*
- name: Test external tests with pytest
run: |
python3 -m pytest tests/external_tests/*
- name: build and install
run: |
python3 -m build
python3 -m pip install .
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/



38 changes: 38 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Python Build MLBstats API

on:
push:
branches-ignore:
- 'main'
- 'development'

jobs:
build:
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 build
python3 -m pip install --upgrade requests
python3 -m pip install --upgrade requests_mock
- name: Test with mocks with pytest
run: |
python3 -m pytest tests/mock_tests/*
- name: Test external tests with pytest
run: |
python3 -m pytest tests/external_tests/*
- name: build and install
run: |
python3 -m build
python3 -m pip install .
Loading

0 comments on commit c283d96

Please sign in to comment.