From 7194a46e9a3580e6cd18ffcc299ccf39c0bb7101 Mon Sep 17 00:00:00 2001 From: Mohan Boddu Date: Jul 17 2019 17:21:57 +0000 Subject: Adding package.cfg file to epel branches Signed-off-by: Mohan Boddu --- diff --git a/fedscm_admin/git.py b/fedscm_admin/git.py index f8a0ff6..9fe7574 100644 --- a/fedscm_admin/git.py +++ b/fedscm_admin/git.py @@ -20,7 +20,7 @@ import subprocess as sp import tempfile import shutil import os - +import sys import yaml import click @@ -220,6 +220,16 @@ class GitRepo(object): push_cmd = ['git', 'push'] self._run_git_cmd(push_cmd) + def fetch(self): + """ + Fetches from the Git server + :return: None or GitException + """ + self._assert_cloned() + click.echo('- Fetching from {0}'.format(self.git_url)) + push_cmd = ['git', 'fetch'] + self._run_git_cmd(push_cmd) + def set_monitoring_on_repo(self, namespace, repo, monitoring_level): """ Set the monitoring level of a repo in config.yml @@ -256,3 +266,36 @@ class GitRepo(object): self.add(config_yml_path) self.commit('Adding monitoring for {0}/{1}'.format(namespace, repo)) self.push() + + def create_epel_package_cfg(self, namespace, repo, branch): + """ + Create package.cfg file in epel branch + :param namespace: the dist-git namespace of the package in question. + :param repo: the name of the dist-git repo in question. + :param branch: the name of the branch + :return: None or GitException + """ + self._assert_cloned() + + if self.current_branch != branch: + self.fetch() + self.checkout_branch(branch) + try: + # Open the package.cfg file in the repo + # Write the config needed with epel\d and epel\d-playground + # build targets + # Close the file + # Add the file, commit the changes and push + with open(os.path.join(self.clone_dir, 'package.cfg'), 'w') as pkg_cfg: + pkg_cfg.write("[koji]\n") + pkg_cfg.write("targets = {0} {0}-playground".format(branch)) + pkg_cfg.close() + self.add(pkg_cfg.name) + self.commit("Adding package.cfg file") + self.push() + except IOError: + print("Couldn't create package.cfg file in {0} of {1}/{2} repo, " + "please file a releng ticket".format(branch, namespace, repo)) + sys.exit(1) + finally: + pkg_cfg.close() diff --git a/fedscm_admin/pagure.py b/fedscm_admin/pagure.py index 51c04d1..dc11343 100644 --- a/fedscm_admin/pagure.py +++ b/fedscm_admin/pagure.py @@ -140,9 +140,15 @@ def get_project_git_url(namespace, repo, url_type='ssh', username=None): url = rv_json['urls'].get(url_type) # Insert the username *if* relevant. - if username is not None and url.startswith('ssh://') and '@' not in url: - url = 'ssh://{username}@{rest}'.format( - username=username, rest=url[6:]) + if username is not None and url.startswith('ssh://'): + # Use the FAS username of the person who is processing the tickets. + # username from git url returns '{username}' + # For ex: https://src.fedoraproject.org/api/0/rpms/fedora-repos/git/urls + if '{username}' in url: + url = url.replace('{username}', username) + if '@' not in url: + url = 'ssh://{username}@{rest}'.format( + username=username, rest=url[6:]) return url diff --git a/fedscm_admin/utils.py b/fedscm_admin/utils.py index 888467b..56c1fdd 100644 --- a/fedscm_admin/utils.py +++ b/fedscm_admin/utils.py @@ -768,10 +768,11 @@ def new_git_branch(namespace, repo, branch, use_master=False): fedscm_admin.pagure.new_branch( namespace, repo, branch, from_branch='master') else: - # Use the git url and not ssh since we only need read-only access. The - # new branch will be created using the Pagure API and not git directly. + # Even though the branches are created using pagure api which dont + # require ssh, but for epel\d branches we add package.cfg file. + # This should be pushed using ssh. git_url = fedscm_admin.pagure.get_project_git_url( - namespace, repo, url_type='git', + namespace, repo, url_type='ssh', username=FAS_CLIENT.client.username) git_obj = fedscm_admin.git.GitRepo(git_url) git_obj.clone_repo() @@ -780,6 +781,12 @@ def new_git_branch(namespace, repo, branch, use_master=False): 'git branch can\'t be created.') fedscm_admin.pagure.new_branch( namespace, repo, branch, from_commit=git_obj.first_commit) + # If epel\d branch, then create package.cfg file in that branch + # Remove the check for epel version >= 7 when playground is enabled + # for epel7 + if (bool(re.match(r'^(?:epel)\d+$', branch)) and + int(''.join([i for i in branch if re.match(r'\d', i)])) >= 7): + git_obj.create_epel_package_cfg(namespace, repo, branch) def ticket_requires_approval(issue_type, issue): diff --git a/setup.py b/setup.py index 883b615..383fd93 100644 --- a/setup.py +++ b/setup.py @@ -20,5 +20,5 @@ setup( packages=['fedscm_admin'], package_dir={'fedscm_admin': 'fedscm_admin'}, url='https://pagure.io/fedscm_admin', - version='1.0.7', + version='1.0.8', )