def handle_anitya_map_new(self, msg): """ Message handler for projects newly mapped to Fedora in Anitya. This handler is used when a project is mapped to a Fedora package in Anitya. It triggers Anitya to perform a check for the latest upstream version, then compares that to the version in Rawhide. If Rawhide does not have the latest version, a bug is filed. Topic: 'org.release-monitoring.prod.anitya.project.map.new' """ body = msg.body message = body["message"] if message["distro"] != self.distro: _log.info( "New mapping on %s, not for %s. Dropping." % (message["distro"], self.distro) ) return project = message["project"] package = message["new"] upstream = body["project"]["version"] _log.info( "Newly mapped %r to %r bears version %r" % (project, package, upstream) ) if upstream: self._handle_anitya_update(upstream, package, msg) else: _log.info("Forcing an anitya upstream check.") anitya = hotness.anitya.Anitya(self.anitya_url) anitya.force_check(body["project"])
def handle_anitya_map_new(self, msg): """ Message handler for projects newly mapped to Fedora in Anitya. This handler is used when a project is mapped to a Fedora package in Anitya. It triggers Anitya to perform a check for the latest upstream version, then compares that to the version in Rawhide. If Rawhide does not have the latest version, a bug is filed. Topic: 'org.release-monitoring.prod.anitya.project.map.new' """ if msg.distro != self.distro: _log.info("New mapping on %s, not for %s. Dropping." % (msg.distro, self.distro)) return project = msg.project_name package = msg.package_name upstream = msg.project_version _log.info("Newly mapped %r to %r bears version %r" % (project, package, upstream)) if upstream: self._handle_anitya_update(upstream, package, msg) else: _log.info("Forcing an anitya upstream check.") anitya = hotness.anitya.Anitya(self.anitya_url) anitya.force_check(msg.project_id)
def handle_monitor_toggle(self, msg): status = msg['msg']['status'] name = msg['msg']['package']['name'] homepage = msg['msg']['package']['upstream_url'] self.log.info("Considering monitored %r with %r" % (name, homepage)) if not status: self.log.info(".. but it was turned off. Dropping.") return anitya = hotness.anitya.Anitya(self.anitya_url) results = anitya.search_by_homepage(name, homepage) total = results['total'] if total > 1: self.log.info("%i projects with %r %r already exist in anitya." % (total, name, homepage)) return elif total == 1: # The project might exist in anitya, but it might not be mapped to # a Fedora package yet, so map it if necessary. project = results['projects'][0] anitya.login(self.anitya_username, self.anitya_password) reason = None try: anitya.map_new_package(name, project) except hotness.anitya.AnityaException as e: reason = str(e) self.log.warn("Failed to map: %r" % reason) self.publish("project.map", msg=dict(trigger=msg, project=project, success=not bool(reason), reason=reason)) # After mapping, force a check for new tarballs anitya.force_check(project) else: # OTHERWISE, there is *nothing* on anitya about it, so add one. self.log.info("Saw 0 matching projects on anitya. Adding.") anitya.login(self.anitya_username, self.anitya_password) reason = None try: anitya.add_new_project(name, homepage) except hotness.anitya.AnityaException as e: reason = str(e) self.log.warn("Failed to create: %r" % reason) self.publish("project.map", msg=dict(trigger=msg, success=not bool(reason), reason=reason))
def handle_monitor_toggle(self, msg): status = msg['msg']['status'] name = msg['msg']['package']['name'] homepage = msg['msg']['package']['upstream_url'] self.log.info("Considering monitored %r with %r" % (name, homepage)) if not status: self.log.info(".. but it was turned off. Dropping.") return anitya = hotness.anitya.Anitya(self.anitya_url) results = anitya.search(name, homepage) total = results['total'] if total > 1: self.log.info("%i projects with %r %r already exist in anitya." % ( total, name, homepage)) return elif total == 1: # The project might exist in anitya, but it might not be mapped to # a Fedora package yet, so map it if necessary. project = results['projects'][0] anitya.login(self.anitya_username, self.anitya_password) reason = None try: anitya.map_new_package(name, project) except hotness.anitya.AnityaException as e: reason = str(e) self.publish("project.map", msg=dict( trigger=msg, project=project, success=not bool(reason), reason=reason)) # After mapping, force a check for new tarballs anitya.force_check(project) else: # OTHERWISE, there is *nothing* on anitya about it, so add one. self.log.info("Saw 0 matching projects on anitya. Adding.") anitya.login(self.anitya_username, self.anitya_password) reason = None try: anitya.add_new_project(name, homepage) except hotness.anitya.AnityaException as e: reason = str(e) self.publish("project.map", msg=dict( trigger=msg, success=not bool(reason), reason=reason))
def handle_updated_package(self, msg): """ Message handler for updates to packages in pkgdb. When a package is updated in pkgdb, this ensures that if the upstream_url changes in pkgdb, the changes are pushed to Anitya. This can result in either an update to the Anitya project entry, or an entirely new entry if the package did not previously exist in Anitya. Topic: 'org.fedoraproject.prod.pkgdb.package.update', Publish a message to ``project.map`` with the results of the attempt map the package to a project if the project is not already on Anitya. """ _log.info("Handling pkgdb update msg %r" % msg.get('msg_id')) fields = msg['msg']['fields'] if 'upstream_url' not in fields: _log.info("Ignoring package edit with no url change.") return package = msg['msg']['package'] name = package['name'] homepage = package['upstream_url'] _log.info("Trying url change on %s: %s" % (name, homepage)) # There are two possible scenarios here. # 1) the package already *is mapped* in anitya, in which case we can # update the old url there # 2) the package is not mapped there, in which case we handle this like # a new package (and try to create it and map it) anitya = hotness.anitya.Anitya(self.anitya_url) project = anitya.get_project_by_package(name) if project: _log.info("Found project with name %s" % project['name']) anitya.login(self.anitya_username, self.anitya_password) if project['homepage'] == homepage: _log.info("No need to update anitya for %s. Homepages" " are already in sync." % project['name']) return _log.info("Updating anitya url on %s" % project['name']) anitya.update_url(project, homepage) anitya.force_check(project) else: # Just pretend like it's a new package, since its not in anitya. self.handle_new_package(msg, package)
def handle_anitya_map_new(self, msg): message = msg['msg']['message'] if message['distro'] != self.distro: self.log.info("New mapping on %s, not for %s. Dropping." % ( message['distro'], self.distro)) return project = message['project'] package = message['new'] upstream = msg['msg']['project']['version'] self.log.info("Newly mapped %r to %r bears version %r" % ( project, package, upstream)) if upstream: self._handle_anitya_update(upstream, package, msg) else: self.log.info("Forcing an anitya upstream check.") anitya = hotness.anitya.Anitya(self.anitya_url) anitya.force_check(msg['msg']['project'])
def handle_anitya_map_new(self, msg): message = msg['msg']['message'] if message['distro'] != self.distro: self.log.info("New mapping on %s, not for %s. Dropping." % (message['distro'], self.distro)) return project = message['project'] package = message['new'] upstream = msg['msg']['project']['version'] self.log.info("Newly mapped %r to %r bears version %r" % (project, package, upstream)) if upstream: self._handle_anitya_update(upstream, package, msg) else: self.log.info("Forcing an anitya upstream check.") anitya = hotness.anitya.Anitya(self.anitya_url) anitya.force_check(msg['msg']['project'])
def handle_updated_package(self, msg): self.log.info("Handling pkgdb update msg %r" % msg.get('msg_id')) fields = msg['msg']['fields'] if not 'upstream_url' in fields: self.log.info("Ignoring package edit with no url change.") return package = msg['msg']['package'] name = package['name'] homepage = package['upstream_url'] self.log.info("Trying url change on %s: %s" % (name, homepage)) # There are two possible scenarios here. # 1) the package already *is mapped* in anitya, in which case we can # update the old url there # 2) the package is not mapped there, in which case we handle this like # a new package (and try to create it and map it) anitya = hotness.anitya.Anitya(self.anitya_url) project = anitya.get_project_by_package(name) if project: self.log.info("Found project with name %s" % project['name']) anitya.login(self.anitya_username, self.anitya_password) if project['homepage'] == homepage: self.log.info("No need to update anitya for %s. Homepages" " are already in sync." % project['name']) return self.log.info("Updating anitya url on %s" % project['name']) anitya.update_url(project, homepage) anitya.force_check(project) else: # Just pretend like it's a new package, since its not in anitya. self.handle_new_package(msg, package)
def handle_monitor_toggle(self, msg): """ Message handler for packages whose monitoring is adjusted in pkgdb. If a package has its monitoring turned off, this does nothing. If it is turned on, this ensures the package exists in Anitya and forces Anitya to check for the latest version. Topic: 'org.fedoraproject.prod.pkgdb.package.monitor.update' """ status = msg['msg']['status'] name = msg['msg']['package']['name'] homepage = msg['msg']['package']['upstream_url'] _log.info("Considering monitored %r with %r" % (name, homepage)) if not status: _log.info(".. but it was turned off. Dropping.") return anitya = hotness.anitya.Anitya(self.anitya_url) results = anitya.search_by_homepage(name, homepage) total = results['total'] if total > 1: _log.info("%i projects with %r %r already exist in anitya." % (total, name, homepage)) return elif total == 1: # The project might exist in anitya, but it might not be mapped to # a Fedora package yet, so map it if necessary. project = results['projects'][0] anitya.login(self.anitya_username, self.anitya_password) reason = None try: anitya.map_new_package(name, project) except hotness.anitya.AnityaException as e: reason = str(e) _log.warn("Failed to map: %r" % reason) self.publish("project.map", msg=dict(trigger=msg, project=project, success=not bool(reason), reason=reason)) # After mapping, force a check for new tarballs anitya.force_check(project) else: # OTHERWISE, there is *nothing* on anitya about it, so add one. _log.info("Saw 0 matching projects on anitya. Adding.") anitya.login(self.anitya_username, self.anitya_password) reason = None try: anitya.add_new_project(name, homepage) except hotness.anitya.AnityaException as e: reason = str(e) _log.warn("Failed to create: %r" % reason) self.publish("project.map", msg=dict(trigger=msg, success=not bool(reason), reason=reason))