From 26d061f640f797cd4552b68ee9eefde4259c0ec9 Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Jul 28 2016 09:11:24 +0000 Subject: Add docstring for pagure-ci --- diff --git a/pagure/lib/pagure_ci.py b/pagure/lib/pagure_ci.py index 8d29540..4d678a5 100644 --- a/pagure/lib/pagure_ci.py +++ b/pagure/lib/pagure_ci.py @@ -24,10 +24,14 @@ JENKINS_TRIGGER_URL = '{base}job/{project}/buildWithParameters' class HookInactive(Exception): + """To handle when the hook is inactive""" pass def process_pr(logger, cfg, pr_id, repo, branch): + """Function to process the PR, it POST the + data to the Jenkins URL to trigger build + """ if cfg.active: post_data(logger, JENKINS_TRIGGER_URL.format( @@ -41,8 +45,10 @@ def process_pr(logger, cfg, pr_id, repo, branch): def process_build(logger, cfg, build_id): + """Function is used to get the build info + from jenkins and flag that particular PR + """ if cfg.active: - # Get details from Jenkins jenk = jenkins.Jenkins(cfg.jenkins_url) build_info = jenk.get_build_info(cfg.jenkins_name, build_id) result = build_info['result'] @@ -78,6 +84,7 @@ def process_build(logger, cfg, build_id): def post_data(logger, *args, **kwargs): + """POST data to jenkins and reports a response""" resp = requests.post(*args, **kwargs) logger.debug('Received response status %s', resp.status_code) if resp.status_code < 200 or resp.status_code >= 300: @@ -86,6 +93,7 @@ def post_data(logger, *args, **kwargs): def pagure_ci_flag(logger, repo, username, url, result, requestid): + """Flag the pull-request in pagure""" comment, percent = { 'SUCCESS': ('Build successful', 100), diff --git a/pagureCI/consumer.py b/pagureCI/consumer.py index fcdf347..187b894 100644 --- a/pagureCI/consumer.py +++ b/pagureCI/consumer.py @@ -10,6 +10,7 @@ PAGURE_FORK_REPO = '{base}forks/{user}/{name}.git' class Integrator(fedmsg.consumers.FedmsgConsumer): + """Integrates Jenkins with Pagure""" topic = [ 'io.pagure.prod.pagure.pull-request.comment.added', 'io.pagure.prod.pagure.pull-request.new', @@ -23,6 +24,9 @@ class Integrator(fedmsg.consumers.FedmsgConsumer): super(Integrator, self).__init__(hub) def consume(self, msg): + """Pagure CI consumer which consumes message from + fedmsg and triggers Jenkins build. + """ topic, msg = msg['topic'], msg['body'] self.log.info("Received %r, %r", topic, msg.get('msg_id', None)) msg = msg['msg'] @@ -40,6 +44,7 @@ class Integrator(fedmsg.consumers.FedmsgConsumer): self.log.info('Hook Inactive for project %r', str(exc)) def trigger_build(self, msg): + """Triggers or requests to start a build in Jenkins""" pr_id = msg['pullrequest']['id'] project = msg['pullrequest']['project']['name'] branch = msg['pullrequest']['branch_from'] @@ -52,11 +57,13 @@ class Integrator(fedmsg.consumers.FedmsgConsumer): pagure_ci.process_pr(self.log, cfg, pr_id, repo, branch) def process_build(self, msg): + """Extracts the information from the build and flag the pull-request""" for cfg in jenkins_hook.get_configs(msg['project'], jenkins_hook.Service.JENKINS): pagure_ci.process_build(self.log, cfg, msg['build']) def get_repo(cfg, msg): + """Formats the URL for pagure repo""" url = PAGURE_MAIN_REPO if msg['pullrequest']['repo_from']['parent']: url = PAGURE_FORK_REPO @@ -67,10 +74,10 @@ def get_repo(cfg, msg): def is_rebase(msg): + """Returns Rebase if the Pull-request is rebased""" if msg['pullrequest']['status'] != 'Open': return False try: - print msg return msg['pullrequest']['comments'][-1]['notification'] except (IndexError, KeyError): return False