GitLab: s/Gitlab/GitLab/g

This commit is contained in:
James Lu 2019-11-08 19:03:50 -08:00
parent 6382b9d197
commit 726ac377ed
3 changed files with 41 additions and 40 deletions

View File

@ -29,7 +29,7 @@
### ###
""" """
Gitlab: Plugin for communication and notifications with a Gitlab instance GitLab: Plugin for communication and notifications with a GitLab instance
""" """
import supybot import supybot

View File

@ -32,7 +32,7 @@ import supybot.conf as conf
import supybot.registry as registry import supybot.registry as registry
try: try:
from supybot.i18n import PluginInternationalization from supybot.i18n import PluginInternationalization
_ = PluginInternationalization('Gitlab') _ = PluginInternationalization('GitLab')
except: except:
# Placeholder that allows to run the plugin on a bot # Placeholder that allows to run the plugin on a bot
# without the i18n module # without the i18n module
@ -45,70 +45,70 @@ def configure(advanced):
# user or not. You should effect your configuration by manipulating the # user or not. You should effect your configuration by manipulating the
# registry as appropriate. # registry as appropriate.
from supybot.questions import expect, anything, something, yn from supybot.questions import expect, anything, something, yn
conf.registerPlugin('Gitlab', True) conf.registerPlugin('GitLab', True)
Gitlab = conf.registerPlugin('Gitlab') GitLab = conf.registerPlugin('GitLab')
# Settings # Settings
conf.registerChannelValue(Gitlab, 'projects', conf.registerChannelValue(GitLab, 'projects',
registry.Json({}, _("""List of projects"""))) registry.Json({}, _("""List of projects""")))
# Format # Format
conf.registerGroup(Gitlab, 'format') conf.registerGroup(GitLab, 'format')
conf.registerChannelValue(Gitlab, 'use-notices', conf.registerChannelValue(GitLab, 'use-notices',
registry.Boolean(False, _("""Determines whether the bot should announce using NOTICE instead of PRIVMSG."""))) registry.Boolean(False, _("""Determines whether the bot should announce using NOTICE instead of PRIVMSG.""")))
conf.registerChannelValue(Gitlab.format, 'push', conf.registerChannelValue(GitLab.format, 'push',
registry.String(_("""\x02[{project[name]}]\x02 {user_name} pushed \x02{total_commits_count} commit(s)\x02 to \x02{ref}\x02:"""), registry.String(_("""\x02[{project[name]}]\x02 {user_name} pushed \x02{total_commits_count} commit(s)\x02 to \x02{ref}\x02:"""),
_("""Format for push events."""))) _("""Format for push events.""")))
conf.registerChannelValue(Gitlab.format, 'commit', conf.registerChannelValue(GitLab.format, 'commit',
registry.String(_("""\x02[{project[name]}]\x02 {short_id} \x02{short_message}\x02 by {author[name]}"""), registry.String(_("""\x02[{project[name]}]\x02 {short_id} \x02{short_message}\x02 by {author[name]}"""),
_("""Format for commits."""))) _("""Format for commits.""")))
conf.registerChannelValue(Gitlab.format, 'tag', conf.registerChannelValue(GitLab.format, 'tag',
registry.String(_("""\x02[{project[name]}]\x02 {user_name} created a new tag {ref}"""), registry.String(_("""\x02[{project[name]}]\x02 {user_name} created a new tag {ref}"""),
_("""Format for tag push events."""))) _("""Format for tag push events.""")))
conf.registerChannelValue(Gitlab.format, 'issue-open', conf.registerChannelValue(GitLab.format, 'issue-open',
registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 created by {user[name]} {issue[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 created by {user[name]} {issue[url]}"""),
_("""Format for issue/open events."""))) _("""Format for issue/open events.""")))
conf.registerChannelValue(Gitlab.format, 'issue-update', conf.registerChannelValue(GitLab.format, 'issue-update',
registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 updated by {user[name]} {issue[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 updated by {user[name]} {issue[url]}"""),
_("""Format for issue/update events."""))) _("""Format for issue/update events.""")))
conf.registerChannelValue(Gitlab.format, 'issue-close', conf.registerChannelValue(GitLab.format, 'issue-close',
registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 closed by {user[name]} {issue[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 closed by {user[name]} {issue[url]}"""),
_("""Format for issue/close events."""))) _("""Format for issue/close events.""")))
conf.registerChannelValue(Gitlab.format, 'issue-reopen', conf.registerChannelValue(GitLab.format, 'issue-reopen',
registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 reopend by {user[name]} {issue[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Issue \x02#{issue[id]} {issue[title]}\x02 reopend by {user[name]} {issue[url]}"""),
_("""Format for issue/reopen events."""))) _("""Format for issue/reopen events.""")))
conf.registerChannelValue(Gitlab.format, 'merge-request-open', conf.registerChannelValue(GitLab.format, 'merge-request-open',
registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 created by {user[name]} {merge_request[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 created by {user[name]} {merge_request[url]}"""),
_("""Format for merge-request/open events."""))) _("""Format for merge-request/open events.""")))
conf.registerChannelValue(Gitlab.format, 'merge-request-update', conf.registerChannelValue(GitLab.format, 'merge-request-update',
registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 updated by {user[name]} {merge_request[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 updated by {user[name]} {merge_request[url]}"""),
_("""Format for merge-request/open events."""))) _("""Format for merge-request/open events.""")))
conf.registerChannelValue(Gitlab.format, 'merge-request-close', conf.registerChannelValue(GitLab.format, 'merge-request-close',
registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 closed by {user[name]} {merge_request[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 closed by {user[name]} {merge_request[url]}"""),
_("""Format for merge-request/open events."""))) _("""Format for merge-request/open events.""")))
conf.registerChannelValue(Gitlab.format, 'merge-request-reopen', conf.registerChannelValue(GitLab.format, 'merge-request-reopen',
registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 reopened by {user[name]} {merge_request[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 reopened by {user[name]} {merge_request[url]}"""),
_("""Format for merge-request/open events."""))) _("""Format for merge-request/open events.""")))
conf.registerChannelValue(Gitlab.format, 'merge-request-merge', conf.registerChannelValue(GitLab.format, 'merge-request-merge',
registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 merged by {user[name]} {merge_request[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 merged by {user[name]} {merge_request[url]}"""),
_("""Format for merge-request/open events."""))) _("""Format for merge-request/open events.""")))
conf.registerChannelValue(Gitlab.format, 'note-merge-request', conf.registerChannelValue(GitLab.format, 'note-merge-request',
registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 {note[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Merge request \x02#{merge_request[id]} {merge_request[title]}\x02 {note[url]}"""),
_("""Format for note/merge-request events."""))) _("""Format for note/merge-request events.""")))
conf.registerChannelValue(Gitlab.format, 'note-commit', conf.registerChannelValue(GitLab.format, 'note-commit',
registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Commit \x02#{commit[id]}\x02 {commit[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Commit \x02#{commit[id]}\x02 {commit[url]}"""),
_("""Format for note/commit events."""))) _("""Format for note/commit events.""")))
conf.registerChannelValue(Gitlab.format, 'note-issue', conf.registerChannelValue(GitLab.format, 'note-issue',
registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Issue \x02#{issue[id]} {issue[title]}\x02 {note[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Issue \x02#{issue[id]} {issue[title]}\x02 {note[url]}"""),
_("""Format for note/issue events."""))) _("""Format for note/issue events.""")))
conf.registerChannelValue(Gitlab.format, 'note-snippet', conf.registerChannelValue(GitLab.format, 'note-snippet',
registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Snippet \x02#{snippet[id]} {snippet[title]}\x02 {note[url]}"""), registry.String(_("""\x02[{project[name]}]\x02 {user[name]} commented on Snippet \x02#{snippet[id]} {snippet[title]}\x02 {note[url]}"""),
_("""Format for note/snippet events."""))) _("""Format for note/snippet events.""")))

View File

@ -1,5 +1,6 @@
### ###
# Copyright (c) 2015, Moritz Lipp # Copyright (c) 2015, Moritz Lipp
# Copyright (c) 2018-2019, James Lu <james@overdrivenetworks.com>
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -40,7 +41,7 @@ import supybot.world as world
try: try:
from supybot.i18n import PluginInternationalization from supybot.i18n import PluginInternationalization
from supybot.i18n import internationalizeDocstring from supybot.i18n import internationalizeDocstring
_ = PluginInternationalization('Gitlab') _ = PluginInternationalization('GitLab')
except ImportError: except ImportError:
# Placeholder that allows to run the plugin on a bot # Placeholder that allows to run the plugin on a bot
# without the i18n module # without the i18n module
@ -51,26 +52,26 @@ except ImportError:
return x return x
class GitlabHandler(object): class GitLabHandler(object):
"""Handle gitlab messages""" """Handle gitlab messages"""
def __init__(self, plugin): def __init__(self, plugin):
self.plugin = plugin self.plugin = plugin
self.log = log.getPluginLogger('Gitlab') self.log = log.getPluginLogger('GitLab')
# HACK: instead of refactoring everything, I can just replace this with each handle_payload() call. # HACK: instead of refactoring everything, I can just replace this with each handle_payload() call.
self.irc = None self.irc = None
def handle_payload(self, headers, payload, irc): def handle_payload(self, headers, payload, irc):
if 'X-Gitlab-Event' not in headers: if 'X-GitLab-Event' not in headers:
self.log.info('Invalid header: Missing X-Gitlab-Event entry') self.log.info('Invalid header: Missing X-GitLab-Event entry')
return return
self.irc = irc self.irc = irc
self.log.debug('GitLab: running on network %r', irc.network) self.log.debug('GitLab: running on network %r', irc.network)
event_type = headers['X-Gitlab-Event'] event_type = headers['X-GitLab-Event']
if event_type not in ['Push Hook', 'Tag Push Hook', 'Note Hook', 'Issue Hook', 'Merge Request Hook']: if event_type not in ['Push Hook', 'Tag Push Hook', 'Note Hook', 'Issue Hook', 'Merge Request Hook']:
self.log.info('Unsupported X-Gitlab-Event type') self.log.info('Unsupported X-GitLab-Event type')
return return
# Check if any channel has subscribed to this project # Check if any channel has subscribed to this project
@ -206,15 +207,15 @@ class GitlabHandler(object):
self.irc.queueMsg(announce_msg) self.irc.queueMsg(announce_msg)
class GitlabWebHookService(httpserver.SupyHTTPServerCallback): class GitLabWebHookService(httpserver.SupyHTTPServerCallback):
"""https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/web_hooks/web_hooks.md""" """https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/web_hooks/web_hooks.md"""
name = "GitlabWebHookService" name = "GitLabWebHookService"
defaultResponse = """This plugin handles only POST request, please don't use other requests.""" defaultResponse = """This plugin handles only POST request, please don't use other requests."""
def __init__(self, plugin): def __init__(self, plugin):
self.log = log.getPluginLogger('Gitlab') self.log = log.getPluginLogger('GitLab')
self.gitlab = GitlabHandler(plugin) self.gitlab = GitLabHandler(plugin)
self.plugin = plugin self.plugin = plugin
def _send_error(self, handler, message): def _send_error(self, handler, message):
@ -266,8 +267,8 @@ class GitlabWebHookService(httpserver.SupyHTTPServerCallback):
self._send_ok(handler) self._send_ok(handler)
class Gitlab(callbacks.Plugin): class GitLab(callbacks.Plugin):
"""Plugin for communication and notifications of a Gitlab project """Plugin for communication and notifications of a GitLab project
management tool instance""" management tool instance"""
threaded = True threaded = True
@ -275,11 +276,11 @@ class Gitlab(callbacks.Plugin):
global instance global instance
# Store the super() information so that reloads don't fail # Store the super() information so that reloads don't fail
self.__parent = super(Gitlab, self) self.__parent = super(GitLab, self)
self.__parent.__init__(irc) self.__parent.__init__(irc)
instance = self instance = self
callback = GitlabWebHookService(self) callback = GitLabWebHookService(self)
httpserver.hook('gitlab', callback) httpserver.hook('gitlab', callback)
def die(self): def die(self):
@ -305,7 +306,7 @@ class Gitlab(callbacks.Plugin):
return False return False
class gitlab(callbacks.Commands): class gitlab(callbacks.Commands):
"""Gitlab commands""" """GitLab commands"""
class project(callbacks.Commands): class project(callbacks.Commands):
"""Project commands""" """Project commands"""
@ -378,7 +379,7 @@ class Gitlab(callbacks.Plugin):
list = wrap(list, ['channel']) list = wrap(list, ['channel'])
Class = Gitlab Class = GitLab
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: