From 47ed57412a58721a03a8fd8136f2e527cd62b58e Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Apr 07 2020 00:08:12 +0000 Subject: Build forked repo directly in Koji This change allows building changes pushed into the user's forked repo. This doesn't require using '--srpm' param, 'fedpkg (scratch-)build' is enough. Function restricts using multiple git remote records. Otherwise, the original approach works. JIRA: COMPOSE-2963 Relates: #282 Signed-off-by: Ondrej Nosek --- diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py index 24d9f9e..84dd818 100644 --- a/fedpkg/__init__.py +++ b/fedpkg/__init__.py @@ -268,12 +268,28 @@ class Commands(pyrpkg.Commands): in Koji. """ - def construct_build_url(self, *args, **kwargs): + def detect_forked_repo(self): + # detection of forked repository + # consider the only remote record in .git/config with proper url format + if len(self.repo.remotes) == 1: + remote = self.repo.remotes[0] + if len(list(remote.urls)) == 1: + remote_url = next(remote.urls) + match = re.search(r'forks/{0}/\w+/\w+'.format(self.user), remote_url) + if match: + return match.group() + return None + + def construct_build_url(self, repo_name=None, commit_hash=None): """Override build URL for Fedora Koji build In Fedora Koji, anonymous URL should have prefix "git+https://" """ - url = super(Commands, self).construct_build_url(*args, **kwargs) + # do not override parameters passed to the method + if not repo_name and not commit_hash: + repo_name = self.detect_forked_repo() + + url = super(Commands, self).construct_build_url(repo_name, commit_hash) return 'git+{0}'.format(url) def update(self, bodhi_config, template='bodhi.template', bugs=[]):