From 6187cd743f880b7af090710606e8069b1e9a12de Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Jan 28 2017 22:50:15 +0000 Subject: [PATCH 1/5] README.md: new file --- diff --git a/README.md b/README.md new file mode 100644 index 0000000..f40f840 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# fedobuild + +fedobuild is a service that aims to improve the quality of +life of Fedora packagers by automating packaging updates. It +listens on [the fedmsg bus](http://fedmsg.com/) for dist-git +pushes and automatically initiates koji builds and bodhi +updates. + +In order to make use of fedobuild, one must include a +CHANGELOG.yml file in the root of the dist-git repo. The +YAML file must have two keys: the package NEVR, and the +changelog: + +``` +- nevr: foobar-2.1-3 + changelog: | + Dear testers, + + Please test these amazing features in this new release + of foobar: + - Added 5 more bars in which to foo. + - Fixed issue where users couldn't baz. +``` + +Dist-git pushes which update the YAML will automatically +trigger the fedobuild process if the NEVR has not yet been +built in Koji. From 2ac2d734f081d9664a7f6981f00a17c72cd985af Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Jan 28 2017 22:51:22 +0000 Subject: [PATCH 2/5] lib.py: use yaml.safe_load() Since the YAML will be in a very basic format, it's better to use safe_load(). --- diff --git a/fedobuild/lib.py b/fedobuild/lib.py index 329d6e7..121ff8a 100644 --- a/fedobuild/lib.py +++ b/fedobuild/lib.py @@ -59,7 +59,7 @@ def get_changelog(name, namespace, commit): 'returned code: %s' % (namespace, name, req.status_code)) return - return yaml.load(req.text) + return yaml.safe_load(req.text) def validate_changelog(changelog): From ea8e18beb4531030dfe3c4b4467b6dff624b031a Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Jan 28 2017 23:00:13 +0000 Subject: [PATCH 3/5] lib.py: fetch YAML over https Because https > http. --- diff --git a/fedobuild/lib.py b/fedobuild/lib.py index 121ff8a..0a1351e 100644 --- a/fedobuild/lib.py +++ b/fedobuild/lib.py @@ -50,7 +50,7 @@ def run_cmd(cmd, abspath=None, input=None, **kw): def get_changelog(name, namespace, commit): ''' Retrieve the CHANGELOG.yml file of this package at this commit. ''' - url = 'http://pkgs.fedoraproject.org/cgit/%s/%s.git/plain/CHANGELOG.yml?id=%s' % ( + url = 'https://src.fedoraproject.org/cgit/%s/%s.git/plain/CHANGELOG.yml?id=%s' % ( namespace, name, commit) req = requests.get(url) if not req: From 94d0b05666fa02f57d89025c5843d1d0d6f91545 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Jan 28 2017 23:19:13 +0000 Subject: [PATCH 4/5] lib.py: fix typo --- diff --git a/fedobuild/lib.py b/fedobuild/lib.py index 0a1351e..e69a5d1 100644 --- a/fedobuild/lib.py +++ b/fedobuild/lib.py @@ -89,7 +89,7 @@ def get_dist_rawhide(): _log.info('Contacting pkgdb at: %s' % url) req = requests.get(url) if not req: - _log.info('Could not contact pkgdb, error: %s' % re.status_code) + _log.info('Could not contact pkgdb, error: %s' % req.status_code) raise RuntimeError('Could not contact pkgdb') data = req.json() return data["collections"][0]['dist_tag'] From 36249b1dcc821c86d81ec2466fcb13bb657b113d Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Jan 28 2017 23:20:14 +0000 Subject: [PATCH 5/5] codebase: migrate away from "changelog" To make explicit that the YAML data represents Bodhi notes, change the key name to "bodhi-notes". Also change the name of the config file itself to fedobuild.yml, and refer to the derived configuration from the YAML as simply "config". --- diff --git a/README.md b/README.md index f40f840..b0fb51a 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,13 @@ pushes and automatically initiates koji builds and bodhi updates. In order to make use of fedobuild, one must include a -CHANGELOG.yml file in the root of the dist-git repo. The +fedobuild.yml file in the root of the dist-git repo. The YAML file must have two keys: the package NEVR, and the -changelog: +Bodhi notes to testers: ``` - nevr: foobar-2.1-3 - changelog: | + bodhi-notes: | Dear testers, Please test these amazing features in this new release diff --git a/fedobuild/lib.py b/fedobuild/lib.py index e69a5d1..e4c506a 100644 --- a/fedobuild/lib.py +++ b/fedobuild/lib.py @@ -20,7 +20,7 @@ from fedora.client.bodhi import Bodhi2Client _log = logging.getLogger(__name__) -MANDATORY = ['nevr', 'changelog'] +MANDATORY = ['nevr', 'bodhi-notes'] FASUSER = raw_input('FAS username: ') FASPASS = getpass.getpass('FAS password: ') @@ -48,37 +48,38 @@ def run_cmd(cmd, abspath=None, input=None, **kw): return (retcode, out) -def get_changelog(name, namespace, commit): - ''' Retrieve the CHANGELOG.yml file of this package at this commit. ''' - url = 'https://src.fedoraproject.org/cgit/%s/%s.git/plain/CHANGELOG.yml?id=%s' % ( +def get_repo_config(name, namespace, commit): + ''' Retrieve the fedobuild.yml file of this package at this commit. ''' + url = 'https://src.fedoraproject.org/cgit/%s/%s.git/plain/fedobuild.yml?id=%s' % ( namespace, name, commit) + req = requests.get(url) if not req: _log.info( - 'Could not access the CHANGELOG.yml for %s/%s, ' + 'Could not access the fedobuild.yml file for %s/%s, ' 'returned code: %s' % (namespace, name, req.status_code)) return return yaml.safe_load(req.text) -def validate_changelog(changelog): - """ Checks that the changelog has all the mandatory keys and returns a +def validate_config(config): + """ Checks that the YAML has all the mandatory keys and returns a boolean accordingly.""" validate = False - _log.info('changelog: %s' % changelog) - if changelog: + _log.info('config: %s' % config) + if config: validate = True for key in MANDATORY: _log.info('Checking key "%s"' % key) - if key not in changelog[0]: + if key not in config[0]: _log.info( - 'Missing key "%s" in changelog: %s' % ( - key, changelog[0])) + 'Missing key "%s" in YAML: %s' % ( + key, config[0])) validate = False break else: - _log.info('No content in changelog: %s' % changelog) + _log.info('No content in config: %s' % config) return validate @@ -129,10 +130,10 @@ def build_pkg(namespace, name, commit, branch): return out.split('\n')[0].rsplit(' ', 1)[1] -def update_package(changelog, dist): +def update_package(config, dist): """ Checks bodhi if the specified package already has an update and if not create one. """ - build = changelog['nevr'] + dist + build = config['nevr'] + dist bodhi = Bodhi2Client(username=FASUSER, password=FASPASS) data = bodhi.query(builds=build) if len(data['updates']) > 0: @@ -141,12 +142,12 @@ def update_package(changelog, dist): update = bodhi.save( builds=build, - type=changelog.get('update_type'), - bugs=changelog.get('bugzilla'), - notes=changelog.get('changelog'), - close_bugs=changelog.get('close_bug_on_stable'), - suggest=changelog.get('suggest'), - severity=changelog.get('severity'), + type=config.get('update_type'), + bugs=config.get('bugzilla'), + notes=config.get('bodhi-notes'), + close_bugs=config.get('close_bug_on_stable'), + suggest=config.get('suggest'), + severity=config.get('severity'), ) _log.debug('Bodhi said: %s' % update) if 'url' in update: @@ -156,12 +157,12 @@ def update_package(changelog, dist): def process(message): """ For a given message: - - Check if the CHANGELOG.yml file was edited + - Check if the fedobuild.yml file was edited - Retrieve the commit - Retrieve the branches in which this commit is - Fire a build in koji if necessary """ - to_process = 'CHANGELOG.yml' in message['msg']['commit']['stats']['files'] + to_process = 'fedobuild.yml' in message['msg']['commit']['stats']['files'] namespace = message['msg']['commit']['namespace'] name = message['msg']['commit']['repo'] @@ -169,23 +170,23 @@ def process(message): if not to_process: _log.info( - 'No CHANGELOG.yml change in %s/%s: %s' % ( + 'No fedobuild.yml change in %s/%s: %s' % ( namespace, name, commit)) return - _log.info('Changes to CHANGELOG.yml detected') + _log.info('Changes to fedobuild.yml detected') - changelog = get_changelog(name, namespace, commit) - if not validate_changelog(changelog): + config = get_repo_config(name, namespace, commit) + if not validate_config(config): _log.info( - 'Invalid CHANGELOG.yml in %s/%s: %s' % ( + 'Invalid fedobuild.yml in %s/%s: %s' % ( namespace, name, commit)) return - _log.info('CHANGELOG.yml validated') + _log.info('fedobuild.yml validated') branch = message['msg']['commit']['branch'] dist = get_dist(branch) - if not already_built(changelog[0]['nevr'], dist): + if not already_built(config[0]['nevr'], dist): _log.info('Building package in koji') task_id = build_pkg(namespace, name, commit, branch) _log.info('Package builing in task #%s' % task_id) @@ -204,10 +205,10 @@ def post_build(message): commit = message['msg']['commit']['rev'] branch = message['msg']['commit']['branch'] dist = get_dist(branch) - changelog = get_changelog(name, namespace, commit) + config = get_repo_config(name, namespace, commit) if branch != 'master': - update_package(changelog[0], dist) + update_package(config[0], dist) else: _log.info('Package updated in `master`, no need for a bodhi update')