-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
996 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[report] | ||
exclude_lines = | ||
if __name__ == '__main__': | ||
main() | ||
PullBugCLI() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length=120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ __pycache__ | |
build | ||
dist | ||
pullbug.egg-info | ||
venv | ||
htmlcov | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
language: python | ||
|
||
python: | ||
- "3.6" | ||
- "3.7" | ||
- "3.8" | ||
- '3.6' | ||
- '3.7' | ||
- '3.8' | ||
|
||
install: | ||
install: | ||
- pip install -e ."[dev]" | ||
|
||
script: | ||
- pylint pullbug/*.py | ||
script: | ||
- flake8 pullbug/*.py | ||
- flake8 test/*.py | ||
- pytest --cov=pullbug | ||
|
||
deploy: | ||
provider: pypi | ||
username: __token__ | ||
password: | ||
secure: ERovLDnoiwXYbsIUy9u+CygvA+Hh3Tf2kAAY6Yenhsrj54HQj+llSBo/l/uor5G8PMtdn7McciddGlh10FLuBq8a1E2SHReDaIiSU/dUdcu5ot9/GHdFkgozmfhMgxbsZsT/XvdbtApP7IXv4DjRE80DIg1hAFzycBLqphMF8xrQGq1aVo72A7jNHtqyH1hdTh8LpPv045L5USbFwiP81Rjjk5kCqd5A7lyneZnRCpbh/WcvqPjDcFoIrLmh/1bdVP1EFyH5yFV9Zfu3TIf7wSXbNC2nC2+bg9kdI3cZ0Y86HZRBNcbC+9QuluFI2hlbhnoAsEbHLAEYfPMxjgr1V9PlEpEw5TfWAVQJJc3ILbfJQ6lyX3K7QuBwRkgpRPgioLw8nzVk2jjsLKhygx3Bf3BR/A4MIgzi7akR+egSZXEHKcoB/LE3EehzzOi5c3hsjn+3CQuSvgmmrp3Oc7Jnze3WOY+bb4QzlQ6IBJrUrpjAYGYBWjRP46mIsbX8nHH3lWOKYnw6zxDf9F2mwOFGXpeHzGMjq9NJfgDXDqLdbETvFL05nRiUVL/SF8kV9Lo7lu+r6YamGkWu/GYpga2mr2DBtVHt9M+JtApORH3ojA6k2xYR0q3I5HMWpMFuYu6LKxQpg1A8CyQtpRM8pOZmLicGpqxlTv5/OhWzEkgLiDY= | ||
on: | ||
tags: true | ||
skip_existing: true | ||
|
||
after_success: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
VIRTUALENV := python3 -m venv | ||
|
||
## help - Display help about make targets for this Makefile | ||
help: | ||
@cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t | ||
|
||
## venv - Install the virtual environment | ||
venv: | ||
$(VIRTUALENV) ~/.venv/pullbug/ | ||
ln -snf ~/.venv/pullbug/ venv | ||
venv/bin/pip install -e ."[dev]" | ||
|
||
## install - Install the project locally | ||
install: | venv | ||
|
||
## clean - Remove the virtual environment and clear out .pyc files | ||
clean: | ||
rm -rf ~/.venv/pullbug/ venv | ||
find . -name '*.pyc' -delete | ||
rm -rf dist | ||
rm -rf build | ||
rm -rf *.egg-info | ||
|
||
## lint - Lint the project | ||
lint: | ||
venv/bin/flake8 pullbug/*.py | ||
venv/bin/flake8 test/*.py | ||
|
||
## test - Test the project | ||
test: | ||
venv/bin/pytest | ||
|
||
## coverage - Test the project and generate an HTML coverage report | ||
coverage: | ||
venv/bin/pytest --cov=pullbug --cov-branch --cov-report=html | ||
|
||
.PHONY: help install clean lint test coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"""Import Pull Bug Modules""" | ||
from .git import Git | ||
from .messages import Messages | ||
# flake8: noqa | ||
from pullbug.github_bug import GithubBug | ||
from pullbug.gitlab_bug import GitlabBug | ||
from pullbug.logger import PullBugLogger | ||
from pullbug.messages import Messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import argparse | ||
import os | ||
import logging | ||
from dotenv import load_dotenv | ||
from pullbug.logger import PullBugLogger | ||
from pullbug.github_bug import GithubBug | ||
from pullbug.gitlab_bug import GitlabBug | ||
|
||
|
||
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN') | ||
GITLAB_API_KEY = os.getenv('GITLAB_API_KEY') | ||
GITLAB_API_URL = os.getenv('GITLAB_API_URL', 'https://gitlab.com/api/v4') | ||
SLACK_BOT_TOKEN = os.getenv('SLACK_BOT_TOKEN') | ||
SLACK_CHANNEL = os.getenv('SLACK_CHANNEL') | ||
ROCKET_CHAT_URL = os.getenv('ROCKET_CHAT_URL') | ||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class PullBugCLI(): | ||
def __init__(self): | ||
"""Initiate CLI args. | ||
""" | ||
# TODO: Validate all these with a set list of options | ||
parser = argparse.ArgumentParser( | ||
description='Get bugged via Slack or RocketChat to merge your GitHub pull requests or GitLab merge requests.' # noqa | ||
) | ||
parser.add_argument( | ||
'-gh', | ||
'--github', | ||
required=False, | ||
action='store_true', | ||
default=False, | ||
help='Get bugged about pull requests from GitHub.' | ||
) | ||
parser.add_argument( | ||
'-gl', | ||
'--gitlab', | ||
required=False, | ||
action='store_true', | ||
default=False, | ||
help='Get bugged about merge requests from GitLab.' | ||
) | ||
parser.add_argument( | ||
'-s', | ||
'--slack', | ||
required=False, | ||
action='store_true', | ||
default=False, | ||
help='Send Pull Bug messages to Slack.' | ||
) | ||
parser.add_argument( | ||
'-rc', | ||
'--rocketchat', | ||
required=False, | ||
action='store_true', | ||
default=False, | ||
help='Send Pull Bug messages to Rocket Chat.' | ||
) | ||
parser.add_argument( | ||
'-w', | ||
'--wip', | ||
required=False, | ||
action='store_true', | ||
default=False, | ||
help='Include "WIP" pull or merge requests.' | ||
) | ||
parser.add_argument( | ||
'-gho', | ||
'--github_owner', | ||
required=False, | ||
type=str, | ||
default='', | ||
help='The GitHub owner to retrieve pull requests from (can be a user or org).' | ||
) | ||
parser.add_argument( | ||
'-ghs', | ||
'--github_state', | ||
required=False, | ||
type=str, | ||
default='open', | ||
help='The GitHub state to retrieve pull requests with. (open | closed | all)' | ||
) | ||
parser.add_argument( | ||
'-ghc', | ||
'--github_context', | ||
required=False, | ||
type=str, | ||
default='orgs', | ||
help='The GitHub context to retrieve pull requests with (users | orgs).' | ||
) | ||
parser.add_argument( | ||
'-glst', | ||
'--gitlab_state', | ||
required=False, | ||
type=str, | ||
default='opened', | ||
help='The GitLab state to retrieve merge requests with. (opened | closed | locked | merged)' | ||
) | ||
parser.add_argument( | ||
'-glsc', | ||
'--gitlab_scope', | ||
required=False, | ||
type=str, | ||
default='all', | ||
help='The GitLab state to retrieve pull requests with. (created_by_me | assigned_to_me | all)' | ||
) | ||
parser.parse_args(namespace=self) | ||
|
||
def run(self): | ||
"""Send command line args to the main run function. | ||
""" | ||
PullBug.run( | ||
github=self.github, | ||
gitlab=self.gitlab, | ||
slack=self.slack, | ||
rocketchat=self.rocketchat, | ||
wip=self.wip, | ||
github_owner=self.github_owner, | ||
github_state=self.github_state, | ||
github_context=self.github_context, | ||
gitlab_state=self.gitlab_state, | ||
gitlab_scope=self.gitlab_scope, | ||
) | ||
|
||
|
||
class PullBug(): | ||
@classmethod | ||
def run(cls, github, gitlab, slack, rocketchat, wip, github_owner, | ||
github_state, github_context, gitlab_state, gitlab_scope): | ||
"""Run Pull Bug based on the configuration. | ||
""" | ||
PullBugLogger._setup_logging(LOGGER) | ||
LOGGER.info('Running Pull Bug...') | ||
load_dotenv() | ||
cls.run_missing_checks | ||
if github: | ||
GithubBug.run(github_owner, github_state, github_context, wip, slack, rocketchat) | ||
if gitlab: | ||
GitlabBug.run(gitlab_scope, gitlab_state, wip, slack, rocketchat) | ||
LOGGER.info('Pull Bug finished bugging!') | ||
|
||
@classmethod | ||
def run_missing_checks(cls, github, gitlab, slack, rocketchat): | ||
"""Check that values are set based on | ||
configuration before proceeding. | ||
""" | ||
if github and not GITHUB_TOKEN: | ||
cls.throw_missing_error('GITHUB_TOKEN') | ||
if gitlab and not GITLAB_API_KEY: | ||
cls.throw_missing_error('GITLAB_API_KEY') | ||
if slack and not SLACK_BOT_TOKEN: | ||
cls.throw_missing_error('SLACK_BOT_TOKEN') | ||
if slack and not SLACK_CHANNEL: | ||
cls.throw_missing_error('SLACK_CHANNEL') | ||
if rocketchat and not ROCKET_CHAT_URL: | ||
cls.throw_missing_error('ROCKET_CHAT_URL') | ||
|
||
@classmethod | ||
def throw_missing_error(cls, missing): | ||
"""Raise an error based on what env variables | ||
are missing. | ||
""" | ||
message = f'No {missing} set. Please correct and try again.' | ||
LOGGER.critical(message) | ||
raise ValueError(message) | ||
|
||
|
||
def main(): | ||
PullBugCLI().run() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.