Skip to content

Commit

Permalink
Merge 2e3e6a3 into db644fc
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Sep 29, 2020
2 parents db644fc + 2e3e6a3 commit a6eb2e7
Show file tree
Hide file tree
Showing 25 changed files with 996 additions and 192 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[report]
exclude_lines =
if __name__ == '__main__':
main()
PullBugCLI()
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length=120
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ __pycache__
build
dist
pullbug.egg-info
venv
htmlcov
.coverage
26 changes: 20 additions & 6 deletions .travis.yml
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# CHANGELOG

## v2.0.0 ()

* Added context for GitHub, you can now get personal pull requests in addition to orgs
* Added logging both to console and to a file. Logs will rollover when their size gets too big
* Added various error handling that was missing
* Added unit tests and code coverage
* Bumped character count from 100 to 120 for descriptions on messages
* Assignees are now checked against the assignee array instead of a single assignee if there are multiple
* Bumped pagination from 20 to 100 items (Will need to revisit to allow for more than a single page of 100)
* Updated documentation
* Various settings now have default values

## v1.3.0 (2020-06-01)

* Removed requirements.txt and added dependencies to setup.py
Expand Down
12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

37 changes: 37 additions & 0 deletions Makefile
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
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<div align="center">

# Pull Bug
# Pull Bug 🐛

🐛 Pull Bug is great at bugging you to merge or close your pull/merge requests.
Get bugged via Slack or RocketChat to merge your GitHub pull requests or GitLab merge requests.

[![Build Status](https://travis-ci.com/Justintime50/pull-bug.svg?branch=master)](https://travis-ci.com/Justintime50/pull-bug)
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)
[![Coverage Status](https://coveralls.io/repos/github/Justintime50/pull-bug/badge.svg?branch=master)](https://coveralls.io/github/Justintime50/pull-bug?branch=master)
[![PyPi](https://img.shields.io/pypi/v/pull-bug)](https://pypi.org/project/pull-bug)
[![Licence](https://img.shields.io/github/license/justintime50/pull-bug)](LICENSE)

<img src="assets/showcase.png">

Expand Down Expand Up @@ -41,7 +43,7 @@ gitlab_message = pullbug.Git.gitlab()
message = github_message + gitlab_message

# Send messages
pullbug.Messages.rocket_chat(message)
pullbug.Messages.rocketchat(message)
pullbug.Messages.slack(message)
```

Expand All @@ -64,3 +66,15 @@ pip3 install -e ."[dev]"
# Run linting
pylint pullbug/*.py
```


## TODO

Document all env variables
- GITHUB_CONTEXT: 'users', 'orgs'
- GITLAB_SCOPE: created_by_me, assigned_to_me or all. Defaults to created_by_me
- GITLAB_STATE: opened, closed, locked, or merged
- CHANGE IGNORE_WIP to default to not include WIP

- VALIDATE ARGS FROM ARGPARSE! Only allow input from a list for those that only accept from a list of criteria
- Handle pagination of results that exceed more than 100 for GitHub
16 changes: 0 additions & 16 deletions docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/rocket_chat_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
message = github_message + gitlab_message

# Send message
pullbug.Messages.rocket_chat(message)
pullbug.Messages.rocketchat(message)
8 changes: 5 additions & 3 deletions pullbug/__init__.py
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
173 changes: 173 additions & 0 deletions pullbug/cli.py
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()

0 comments on commit a6eb2e7

Please sign in to comment.