#390 Build forked repo directly in Koji
Opened 4 years ago by onosek. Modified 4 years ago
onosek/fedpkg forked_repo  into  master

file modified
+18 -2
@@ -268,12 +268,28 @@ 

          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=[]):

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 onosek@redhat.com

This is a demonstration of how could this feature looks like. This actually doesn't work, because of Koji restriction:

FAILED: BuildError: src.fedoraproject.org:/forks/onosek/rpms/zlib.git is not in the list of allowed SCMs

Koji defines a list of rules, how SCM URL should be formatted. In 'kojid.conf' there is an option:

allowed_scms=scm.example.com:/cvs/example git.example.org:/example svn.example.org:/users/*:no

It is needed that Koji accepts repo_name in format: 'forks/user/namespace/repo'.

More discussion is needed, whether this is desirable. Forked repo detection may not be 100% and this could potentially cause confusion to users.

Yeah, right now Koji is configured to not allow cloning forks. Some discussion would be needed if this is desirable and if it's actually possible to tell Koji that it can clone from forks, but only make scratch builds for such repos.