123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- #! /usr/bin/env python
- # -*- coding: utf8 -*-
- #
- # gitlab irc sender
- # Copyright (C) 2016-2017 Andrei Karas (4144)
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- from code.configuration import Configuration
- from code.core import Core
- class IrcHandler():
- def printPushHeader(self, channel, project, branch, url, data, commits, commitsCount):
- if data["before"] == "0000000000000000000000000000000000000000":
- url = Configuration.gitlab_commits_path.format(
- homepage = url,
- name = commits[0]["id"][:Configuration.commit_size]
- )
- elif commitsCount > 1:
- if len(commits) < commitsCount:
- print("Wrong commits count. Got count {0} and real commits number {1}".format(commitsCount, len(commits)))
- commitsCount = len(commits)
- url = Configuration.gitlab_compare_path.format(
- homepage = url,
- commit1 = data["before"][:Configuration.gitlab_compare_commit_size],
- commit2 = commits[commitsCount - 1]["id"][:Configuration.gitlab_compare_commit_size]
- )
- else:
- url = Configuration.gitlab_commit_path.format(
- homepage = url,
- commit = commits[0]["id"][:Configuration.commit_size]
- )
- Core.messageHandler.add(channel, Configuration.irc_push_header_message.format(
- project = project,
- author = data["user_name"],
- count = commitsCount,
- branch = branch,
- url = url
- ))
- def printCommitAuthor(self, channel, project, data, commit, message):
- Core.messageHandler.add(channel, Configuration.irc_push_commit_message.format(
- project = project,
- author = commit["author"]["name"],
- shortid = commit["id"][:Configuration.commit_size],
- message = message
- ))
- def printCommitMessage(self, channel, messages):
- for msg in messages:
- Core.messageHandler.add(channel, Configuration.irc_push_commit_message_continue.format(
- message = msg
- ))
- def printPushTag(self, channel, project, data, commits, tag, url):
- if data["after"] != "0000000000000000000000000000000000000000":
- url = Configuration.gitlab_commit_path.format(
- homepage = url,
- commit = data["after"][:Configuration.commit_size]
- )
- Core.messageHandler.add(channel, Configuration.irc_push_add_tag_message.format(
- project = project,
- author = data["user_name"],
- shortid = data["after"][:Configuration.commit_size],
- url = url,
- tag = tag
- ))
- else:
- Core.messageHandler.add(channel, Configuration.irc_push_remove_tag_message.format(
- project = project,
- author = data["user_name"],
- tag = tag
- ))
- def printCreateBranch(self, channel, project, data, branch, url):
- after = data["after"]
- if after == "0000000000000000000000000000000000000000":
- Core.messageHandler.add(channel, Configuration.irc_push_delete_branch_message.format(
- project = project,
- author = data["user_name"],
- branch = branch
- ))
- else:
- url = Configuration.gitlab_commits_path.format(
- homepage = url,
- name = branch
- )
- Core.messageHandler.add(channel, Configuration.irc_push_create_branch_message.format(
- project = project,
- author = data["user_name"],
- branch = branch,
- shortid = data["after"][:Configuration.commit_size],
- url = url
- ))
- def printAddCommitNote(self, channel, project, data, commit, url, iid):
- url = Configuration.gitlab_commit_path.format(
- homepage = url,
- commit = "{0}#note_{1}".format(commit["id"][:Configuration.commit_size], iid),
- )
- Core.messageHandler.add(channel, Configuration.irc_push_add_note_message.format(
- project = project,
- author = data["user"]["name"],
- shortid = commit["id"][:Configuration.commit_size],
- url = url
- ))
- def printBuildFailed(self, channel, project, branch, data, commit, url, build_id, build_stage, build_name):
- url = Configuration.gitlab_build_path.format(
- homepage = url,
- build = build_id
- )
- Core.messageHandler.add(channel, Configuration.irc_build_failed_message.format(
- project = project,
- shortid = commit["sha"][:Configuration.commit_size],
- branch = branch,
- url = url,
- build = build_id,
- stage = build_stage,
- name = build_name
- ))
- def printBuildSuccess(self, channel, project, branch, data, commit, url, build_id):
- url = Configuration.gitlab_build_path.format(
- homepage = url,
- build = build_id
- )
- Core.messageHandler.add(channel, Configuration.irc_build_success_message.format(
- project = project,
- shortid = commit["sha"][:Configuration.commit_size],
- branch = branch,
- url = url,
- build = build_id
- ))
- def printStageFailed(self, channel, project, branch, data, commit, url, build_id):
- url = Configuration.gitlab_build_path.format(
- homepage = url,
- build = build_id
- )
- Core.messageHandler.add(channel, Configuration.irc_stage_failed_message.format(
- project = project,
- shortid = commit["sha"][:Configuration.commit_size],
- branch = branch,
- url = url,
- build = build_id
- ))
- def printPipelineFailed(self, channel, project, branch, data, commit, url, pipeline_id):
- url = Configuration.gitlab_pipeline_path.format(
- homepage = url,
- pipeline = pipeline_id
- )
- Core.messageHandler.add(channel, Configuration.irc_pipeline_failed_message.format(
- project = project,
- shortid = commit["id"][:Configuration.commit_size],
- branch = branch,
- url = url,
- pipeline = pipeline_id
- ))
- def printPipelineSuccess(self, channel, project, branch, data, commit, url, pipeline_id):
- url = Configuration.gitlab_pipeline_path.format(
- homepage = url,
- pipeline = pipeline_id
- )
- Core.messageHandler.add(channel, Configuration.irc_pipeline_success_message.format(
- project = project,
- shortid = commit["id"][:Configuration.commit_size],
- branch = branch,
- url = url,
- pipeline = pipeline_id
- ))
- def printMROpened(self, channel, project, branch, source_namespace, source_branch, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_merge_request_opened_message.format(
- project = project,
- branch = branch,
- url = url,
- source_namespace = source_namespace,
- source_branch = source_branch,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printMRClosed(self, channel, project, branch, source_namespace, source_branch, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_merge_request_closed_message.format(
- project = project,
- branch = branch,
- url = url,
- source_namespace = source_namespace,
- source_branch = source_branch,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printMRReopened(self, channel, project, branch, source_namespace, source_branch, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_merge_request_reopened_message.format(
- project = project,
- branch = branch,
- url = url,
- source_namespace = source_namespace,
- source_branch = source_branch,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printMRUpdated(self, channel, project, branch, source_namespace, source_branch, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_merge_request_updated_message.format(
- project = project,
- branch = branch,
- url = url,
- source_namespace = source_namespace,
- source_branch = source_branch,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printMRMerged(self, channel, project, branch, source_namespace, source_branch, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_merge_request_merged_message.format(
- project = project,
- branch = branch,
- url = url,
- source_namespace = source_namespace,
- source_branch = source_branch,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printAddMRNote(self, channel, project, branch, source_namespace, source_branch, data, url, iid):
- Core.messageHandler.add(channel, Configuration.irc_merge_request_add_note_message.format(
- project = project,
- branch = branch,
- url = url,
- source_namespace = source_namespace,
- source_branch = source_branch,
- author = data["user"]["name"],
- id = iid
- ))
- def printAddIssueNote(self, channel, project, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_issue_add_note_message.format(
- project = project,
- url = url,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printAddSnippetNote(self, channel, project, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_snippet_add_note_message.format(
- project = project,
- url = url,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printIssueOpened(self, channel, project, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_issue_opened_message.format(
- project = project,
- url = url,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printIssueClosed(self, channel, project, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_issue_closed_message.format(
- project = project,
- url = url,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printIssueReopened(self, channel, project, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_issue_reopened_message.format(
- project = project,
- url = url,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printIssueUpdated(self, channel, project, data, url, iid, title):
- Core.messageHandler.add(channel, Configuration.irc_issue_updated_message.format(
- project = project,
- url = url,
- author = data["user"]["name"],
- title = title,
- id = iid
- ))
- def printCustomMessage(self, channel, message):
- Core.messageHandler.add(channel, message)
|