Skip to content

Commit

Permalink
Rebase-helper integration
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Hracek <phracek@redhat.com>
  • Loading branch information
phracek committed Jan 13, 2016
1 parent 776c7e1 commit b89e566
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 33 deletions.
38 changes: 37 additions & 1 deletion hotness/buildsys.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import logging
import os
import random
Expand All @@ -8,10 +9,14 @@
import subprocess as sp
import tempfile
import time
import six

import koji
import sh

from rebasehelper.application import Application
from rebasehelper.cli import CLI


class Koji(object):
def __init__(self, consumer, config):
Expand Down Expand Up @@ -152,9 +157,40 @@ def handle(self, package, upstream, version, rhbz):
# Copy the patch out of this doomed dir so bz can find it
destination = os.path.join('/var/tmp', filename)
shutil.move(os.path.join(tmp, filename), destination)

return task_id, destination, '[patch] ' + comment
finally:
self.log.debug("Removing %r" % tmp)
shutil.rmtree(tmp)
pass

def rebase_helper(self, package, upstream, tmp, bz):
"""
Rebase helper part which does a rebase a inform package
maintainer whether package was rebased properly.
Output information are in dictionary rh_stuff.
"""
self.log.info("Rebase-helper is going to rebase package")
rh_stuff = {}
result_rh = -1
try:
url = self.git_url.format(package=package)
self.log.info("Cloning %r to %r" % (url, tmp))
sh.git.clone(url, tmp)
os.chdir(tmp)
self.log.info("Rebasehelper package %s %s" % (package, upstream))
argument = ['--non-interactive', '--buildtool', 'fedpkg', upstream]
cli = CLI(argument)
rh_app = Application(cli)
rh_app.set_upstream_monitoring()
result_rh = rh_app.run()
rh_stuff = rh_app.get_rebasehelper_data()
self.log.info("Rebasehelper finish properly")
self.log.info(rh_stuff)

except Exception as ex:
self.log.info('Rebase helper failed with unknown reason. %s' % ex)
return result_rh, rh_stuff

return result_rh, rh_stuff

92 changes: 73 additions & 19 deletions hotness/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
import hotness.cache
import hotness.helpers
import hotness.repository
import os
import shutil
import tempfile
import time
import six

import koji


class BugzillaTicketFiler(fedmsg.consumers.FedmsgConsumer):
Expand Down Expand Up @@ -206,7 +213,9 @@ def _handle_anitya_update(self, upstream, package, msg):
# Is it new to us?
fname = self.yumconfig
try:
version, release = hotness.repository.get_version(package, fname)
version, release = hotness.repository.get_version(package,
fname,
self.config['hotness.pkg_manager'])
except KeyError:
# At this point, we have tried very hard to find the rawhide
# version of the package. If we didn't find it, that means there
Expand Down Expand Up @@ -243,23 +252,68 @@ def _handle_anitya_update(self, upstream, package, msg):
"Skipping scratch build.")
return

self.log.info("Now with #%i, time to do koji stuff" % bz.bug_id)
cwd = os.getcwd()
result_rh = 0
rh_stuff = {}
try:
# Kick off a scratch build..
task_id, patch_filename, description = self.buildsys.handle(
package, upstream, version, bz)

# Map that koji task_id to the bz ticket we want to pursue.
self.triggered_task_ids[task_id] = bz

# Attach the patch to the ticket
self.bugzilla.attach_patch(patch_filename, description, bz)
except Exception as e:
heading = "Failed to kick off scratch build."
note = heading + "\n\n" + str(e)
self.log.warning(heading)
self.log.warning(traceback.format_exc())
self.bugzilla.follow_up(note, bz)
tmp = tempfile.mkdtemp(prefix='thn-rh', dir='/var/tmp')
result_rh, rh_stuff = self.buildsys.rebase_helper(package, upstream, tmp, bz)
if int(result_rh) == 0:
self.log.info('Rebase package %s to %s was SUCCESSFULL' % (package, version))
for number, reference in six.iteritems(rh_stuff['build_logs'],):
note = 'Scratch build completed %s' % reference
self.bugzilla.follow_up(note, bz)
else:
self.log.info('Rebase package %s to %s FAILED. See for details' % (package, version))
self.bugzilla.follow_up('Rebase package %s to %s FAILED' % (package, version), bz)
for number, reference in six.iteritems(rh_stuff['build_logs']):
note = 'Scratch build failed %s' % reference
self.bugzilla.follow_up(note, bz)

for patch in rh_stuff['patches']:
self.bugzilla.follow_up(patch, bz)
for check_name, log in six.iteritems(rh_stuff['checkers']):
if log is None:
continue
rh_checkers = "Result from checker %s." % check_name
self.bugzilla.attach_patch(log, rh_checkers, bz)
for log in rh_stuff['logs']:
rh_logs = "Log %s provided by rebase-helper." % log
self.bugzilla.attach_patch(log, rh_logs, bz)
shutil.rmtree(tmp)
os.chdir(cwd)

except Exception as ex:
self.log.info('Rebase helper failed with unknown reason. %s' % ex.message)
self.bugzilla.follow_up('Rebase helper failed. See logs and attachments in this bugzilla %s' % ex.message, bz)
for patch in rh_stuff['patches']:
self.bugzilla.follow_up(patch, bz)
for check_name, log in six.iteritems(rh_stuff['checkers']):
if log is None:
continue
rh_checkers = "Result from checker %s." % check_name
self.bugzilla.attach_patch(log, rh_checkers, bz)
for log in rh_stuff['logs']:
rh_logs = "Log %s provided by rebase-helper." % log
self.bugzilla.attach_patch(log, rh_logs, bz)
shutil.rmtree(tmp)
os.chdir(cwd)
self.log.info("Now with #%i, time to do koji stuff" % bz.bug_id)
try:
# Kick off a scratch build..
task_id, patch_filename, description = self.buildsys.handle(
package, upstream, version, bz)

# Map that koji task_id to the bz ticket we want to pursue.
self.triggered_task_ids[task_id] = bz
# Attach the patch to the ticket
self.bugzilla.attach_patch(patch_filename, description, bz)
except Exception as e:
heading = "Failed to kick off scratch build."
note = heading + "\n\n" + str(e)
self.log.warning(heading)
self.log.warning(traceback.format_exc())
self.bugzilla.follow_up(note, bz)

def handle_buildsys_scratch(self, msg):
instance = msg['msg']['instance']
Expand Down Expand Up @@ -297,8 +351,8 @@ def handle_buildsys_scratch(self, msg):
text2 = "%s %s" % (subtitle, url)

# Followup on bugs we filed
if task_id in self.triggered_task_ids:
bugs.append((self.triggered_task_ids.pop(task_id), text1))
#if task_id in self.triggered_task_ids:
# bugs.append((self.triggered_task_ids.pop(task_id), text1))

# Also follow up on Package Review requests, but only if the package is
# not already in Fedora (it would be a waste of time to query bugzilla
Expand Down
20 changes: 8 additions & 12 deletions hotness/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ def force_cache_refresh(yumconfig):
@cache.cache_on_arguments()
def build_nvr_dict(yumconfig):
pkg_manager = get_pkg_manager()
cmdline = []
if pkg_manager == 'yum':
cmdline = ["/usr/bin/repoquery"]
else:
cmdline = [os.path.join("/usr/bin", pkg_manager),
"repoquery"]
cmdline.extend(["--config", yumconfig,
"--quiet",
#"--archlist=src",
"--all",
"--qf",
"%{name}\t%{version}\t%{release}"])
log.info(os.getcwd())
cmdline = [os.path.join("/usr/bin", pkg_manager),
"repoquery",
"--config", yumconfig,
"--quiet",
"--all",
"--qf",
"%{name}\t%{version}\t%{release}"]

log.info("Running %r" % ' '.join(cmdline))
repoquery = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dogpile.cache",
"requests",
"sh",
"python-six",
"six",
"fedmsg_meta_fedora_infrastructure",
],
packages=find_packages(),
Expand Down

0 comments on commit b89e566

Please sign in to comment.