"""
Margebot: A Errbot Plugin for Gitlab MR reminders
"""
+import re
from datetime import datetime, timezone
from time import sleep
from dateutil import parser
import gitlab
import requests
-
class MargeGitlab(gitlab.Gitlab):
"""
Subclass gitlab.Gitlab so extra_data args can be added
Marge.CRONTAB = ['{} .crontab_hook'.format(self.config['CRONTAB'])]
gitlab_auth_token = self.config['GITLAB_ADMIN_TOKEN']
verify_ssl = self.config['VERIFY_SSL']
- # self.gitlab = gitlab.Gitlab(self.git_host, gitlab_auth_token, verify_ssl=verify_ssl)
self.gitlab = MargeGitlab(self.git_host, gitlab_auth_token, verify_ssl=verify_ssl)
self.activate_crontab()
"""
self.log.info("webhook: request: {}, rooms: {}".format(request, rooms))
- self.log.info("state: {}".format(request['object_attributes']['state']))
+ # self.log.info("state: {}".format(request['object_attributes']['state']))
# verify it's a merge request
if request['object_kind'] != 'merge_request':
return {'sender': sender, 'msg_list': msg_list}
- # -----------------------------------------------------------
- # webhook maintenance commands
-
- @arg_botcmd('rooms', type=str)
- @arg_botcmd('repo', type=str)
+ @arg_botcmd('rooms', type=str, help="Comma-separated room list without @conference-room suffix")
+ @arg_botcmd('repo', type=str, help="repo to start watching for MRs in NAMESPACE/PROJECT_NAME format")
def watchrepo(self, msg, repo, rooms):
"""
Add the margebot webhook to a repo, and prepopulate any open MRs in the repo with margebot
- args: repo: gitlab repo name in the 'NAMESPACE/PROJECT_NAME' format
- rooms: comma separates list of rooms to notify when the webhook triggers
"""
self.log.info("msg={}".format(msg))
self.log.info("repo={}".format(repo))
# If no hooks, will it return False or [] ?
marge_hook = None
hooks = self.gitlab.getprojecthooks(target_project_id)
- if not hooks:
+ self.log.error("hooks = {}".format(hooks))
+ if hooks is False:
msg = "Couldn't find {} hooks".format(repo)
self.log.error("watchrepo: {}".format(msg))
return msg
for state in ['opened', 'reopened']:
page = 1
mr_list = self.gitlab.getmergerequests(target_project_id, page=page, per_page=100, state=state)
- while not mr_list and mr_list != []:
+ while (mr_list is not False) and (mr_list != []):
for an_mr in mr_list:
mr_count += 1
self.log.info('watchrepo: an_mr WATS THE ID\n{}'.format(an_mr))
return "{}\n{}".format(s_watch_msg, mr_msg)
# pragma pylint: disable=unused-argument
- @botcmd()
- def hello(self, msg, args):
- """
- A simple command to check if the bot is responding
- """
- return "Hi there"
@botcmd()
def xyzzy(self, msg, args):
sleep(5)
yield "(just kidding)"
- @re_botcmd(pattern=r"I blame [Mm]arge([Bb]ot)?")
+ @re_botcmd(pattern=r"I blame marge(bot)?", prefixed=False, flags=re.IGNORECASE)
def dont_blame_margebot(self, msg, match):
"""
margebot is innocent.
"""
- yield "(」゚ロ゚)」NOOOooooo say it ain't so."
+ yield u"(\u300D\uFF9F\uFF9B\uFF9F)\uFF63NOOOooooo say it ain't so."
- @re_botcmd(pattern=r"good bot")
+ @re_botcmd(pattern=r"good bot", prefixed=False, flags=re.IGNORECASE)
def best_bot(self, msg, match):
"""
margebot is the best.
"""
yield "Best bot"
+ @re_botcmd(pattern=r"magfest", prefixed=False, flags=re.IGNORECASE)
+ def margefest(self, msg, args):
+ """
+ margefest4ever
+ """
+ return "More like MargeFest, amirite ?"
+
+ @re_botcmd(pattern=r"margebot sucks", prefixed=False, flags=re.IGNORECASE)
+ def bring_it_up_with_the_steering_committee(self, msg, args):
+ """
+ Bring it up with the committee
+ """
+ return "Bring it up with the Margebot steering committee."
+
+ @re_botcmd(pattern=r".*", prefixed=True)
+ def catchall(self, msg,args):
+ """
+ Don't have the bot complain about unknown commands if the first word in a msg is its name
+ """
+ return
+
+
# pragma pylint: enable=unused-argument
Setup.py
"""
# pragma pylint: disable=invalid-name
+from distutils.errors import DistutilsSetupError
+from distutils.filelist import FileList
+import os
from setuptools import setup
+import setuptools.command.sdist
+import setuptools.command.upload
+import setuptools.command.install
+
+# Errbot plugins aren't distributed as eggs so stub out the sdist, install and upload commands
+
+class ErrbotSdistCommand(setuptools.command.sdist.sdist):
+ """
+ No sdist command for now.
+ """
+ def run(self):
+ raise DistutilsSetupError("No sdist for Errbot plugins.")
+
+
+class ErrbotUploadCommand(setuptools.command.upload.upload):
+ """
+ Don't try uploading Errbot plugins to pypi
+ """
+ def run(self):
+ raise DistutilsSetupError("No uploading Errbot plugins to pypi.")
+
+
+class ErrbotInstallCommand(setuptools.command.install.install):
+ """
+ Short circuit the install command
+ """
+ def run(self):
+ raise DistutilsSetupError("No install command - copy the ./plugin files to a 'Marge' directory under your Errbot's plugins directory.")
+
with open('requirements.txt') as f:
install_required = f.read().splitlines()
tests_required = f.read().splitlines()
setup(
- name='Margebot',
+ name='Marge',
version='1.0.0',
- # packages=['plugins'],
- data_files=[('/opt/errbot/plugins/Marge',
- ['./plugins/marge.plug',
- './plugins/marge.py',
- './plugins//templates/reviews.md',
- 'README.md',
- 'LICENCE'])],
license='GPLv3',
description='A Errbot plugin for reminding you about outstanding Gitlab merge requests',
long_description=open('README.md').read(),
url='https://pwan.org/git/?p=margebot.git;a=summary',
author='JudeN',
author_email='margebot_spam@pwan.org',
- include_package_data=True,
+ include_package_data=True,
install_requires=install_required,
setup_requires=['pytest-runner'],
tests_require=tests_required,
+
+ cmdclass={
+ 'install' : ErrbotInstallCommand,
+ 'sdist' : ErrbotSdistCommand,
+ 'upload' : ErrbotUploadCommand,
+ }
)