X-Git-Url: https://pwan.org/git/?p=margebot.git;a=blobdiff_plain;f=plugins%2Fmarge.py;fp=plugins%2Fmarge.py;h=27642097acb35081a637c00dc80a027b1f161405;hp=0cbe52550ee4c11b6ec9cb8b647b229bf318bc1f;hb=0f33b2dd8c163878b06ac3290d87de8244ac7b7e;hpb=c33554b8412941e605b4606fb640350db4d9aec8 diff --git a/plugins/marge.py b/plugins/marge.py index 0cbe525..2764209 100755 --- a/plugins/marge.py +++ b/plugins/marge.py @@ -3,7 +3,6 @@ Margebot: A Errbot Plugin for Gitlab MR reminders """ import re from datetime import datetime, timezone -from time import sleep from dateutil import parser from dateutil.tz import tzutc from dateutil.relativedelta import relativedelta @@ -11,50 +10,6 @@ from errbot import BotPlugin, arg_botcmd, botcmd, re_botcmd, webhook from errbot.templating import tenv from errcron.bot import CrontabMixin import gitlab -import requests - -class MargeGitlab(gitlab.Gitlab): - """ - Subclass gitlab.Gitlab so extra_data args can be added - to the addprojecthook() and editprojecthook() methods - """ - - def __init__(self, host, token="", oauth_token="", verify_ssl=True): - super().__init__(host, token, oauth_token, verify_ssl) - - def addprojecthook_extra(self, project_id, url, push=False, issues=False, merge_requests=False, tag_push=False, extra_data=None): - """ - A copy parent addprojecthook with an extra_data field - """ - data = {"id": project_id, "url": url} - if extra_data: - for ed_key, ed_value in extra_data.items(): - data[ed_key] = ed_value - data['push_events'] = int(bool(push)) - data['issues_events'] = int(bool(issues)) - data['merge_requests_events'] = int(bool(merge_requests)) - data['tag_push_events'] = int(bool(tag_push)) - request = requests.post("{0}/{1}/hooks".format(self.projects_url, project_id), - headers=self.headers, data=data, verify=self.verify_ssl) - if request.status_code == 201: - return request.json() - return False - - def editprojecthook_extra(self, project_id, hook_id, url, push=False, issues=False, merge_requests=False, tag_push=False, extra_data=None): - """ - A copy of the parent editprojecthook with an extra_data field - """ - data = {"id": project_id, "hook_id": hook_id, "url": url} - if extra_data: - for ed_key, ed_value in extra_data.items(): - data[ed_key] = ed_value - data['push_events'] = int(bool(push)) - data['issues_events'] = int(bool(issues)) - data['merge_requests_events'] = int(bool(merge_requests)) - data['tag_push_events'] = int(bool(tag_push)) - request = requests.put("{0}/{1}/hooks/{2}".format(self.projects_url, project_id, hook_id), - headers=self.headers, data=data, verify=self.verify_ssl) - return request.status_code == 200 def deltastr(any_delta): @@ -143,7 +98,7 @@ class Marge(BotPlugin, CrontabMixin): Marge.CRONTAB = ['{} .crontab_hook'.format(self.config['CRONTAB'])] gitlab_auth_token = self.config['GITLAB_ADMIN_TOKEN'] verify_ssl = self.config['VERIFY_SSL'] - self.gitlab = MargeGitlab(self.git_host, gitlab_auth_token, verify_ssl=verify_ssl) + self.gitlab = gitlab.Gitlab(self.git_host, gitlab_auth_token, verify_ssl=verify_ssl) self.activate_crontab() self.soak_delta = relativedelta(hours=self.config['CRONTAB_SOAK_HOURS']) @@ -441,7 +396,7 @@ class Marge(BotPlugin, CrontabMixin): return msg else: for a_hook in hooks: - self.log.info('a_hook: {}'.format(a_hook)) + self.log.info('a_hook: {} {}'.format(a_hook, self.webhook_url)) if a_hook['merge_requests_events'] and a_hook['url'].startswith(self.webhook_url): marge_hook = a_hook break @@ -456,12 +411,12 @@ class Marge(BotPlugin, CrontabMixin): self.log.info('watchrepo: {}'.format(msg)) return msg else: - hook_updated = self.gitlab.editprojecthook_extra(target_project_id, marge_hook['id'], url, merge_requests=True, extra_data={'enable_ssl_verification': False}) + hook_updated = self.gitlab.editprojecthook(target_project_id, marge_hook['id'], url, merge_requests=True) s_watch_msg = "Updating room list for {} MRs from {} to {}".format(repo, old_rooms, rooms) s_action = "update" else: - hook_updated = self.gitlab.addprojecthook_extra(target_project_id, url, merge_requests=True, extra_data={'enable_ssl_verification': False}) - s_watch_msg = "Now watching for new MRs in the {} repo to the {} roomi(s)".format(repo, rooms) + hook_updated = self.gitlab.addprojecthook(target_project_id, url, merge_requests=True) + s_watch_msg = "Now watching for new MRs in the {} repo to the {} room(s)".format(repo, rooms) s_action = "add" if not hook_updated: @@ -513,15 +468,6 @@ class Marge(BotPlugin, CrontabMixin): # pragma pylint: disable=unused-argument - @botcmd() - def xyzzy(self, msg, args): - """ - Don't call this command... - """ - yield "/me whispers \"All open MRs have been merged into master.\"" - sleep(5) - yield "(just kidding)" - @re_botcmd(pattern=r"I blame marge(bot)?", prefixed=False, flags=re.IGNORECASE) def dont_blame_margebot(self, msg, match): """ @@ -544,18 +490,17 @@ class Marge(BotPlugin, CrontabMixin): 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): + def margebot_sucks(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 - + 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