#30 apply branch naming rules for upstream repos only
Merged 3 years ago by carlwgeorge. Opened 3 years ago by lrossett.
centos/ lrossett/centpkg branch-pattern  into  develop

file modified
+1
@@ -2,3 +2,4 @@ 

  pyOpenSSL

  rpkg

  six

+ GitPython 

\ No newline at end of file

file modified
+47 -5
@@ -19,22 +19,32 @@ 

  import re

  import warnings

  

+ import git

  from pyrpkg import Commands, rpkgError

+ from pyrpkg.utils import cached_property

+ 

  # doc/centpkg_man_page.py uses the 'cli' import

  from . import cli  # noqa

  from .lookaside import StreamLookasideCache, SIGLookasideCache

- from pyrpkg.utils import cached_property

+ 

+ 

+ _DEFAULT_VERSION = '9'

  

  

  class DistGitDirectory(object):

  

      signame = None

-     centosversion = None

+     centosversion = _DEFAULT_VERSION

      projectname = None

      releasename = None

      distrobranch = False

+     repo = None

+     git_origin_substr = 'git@gitlab.com/redhat/centos-stream'

  

-     def __init__(self, branchtext):

+     def __init__(self, branchtext, repo_path=None):

+         if repo_path:

+             # self.repo = git.cmd.Git(repo_path)

+             self.repo = git.repo.Repo(repo_path)

          sigtobranchre = r'c(?P<centosversion>\d+[s]?)-sig-(?P<signame>\w+)-?(?P<projectname>\w+)?-?(?P<releasename>\w+)?'

          distrobranchre = r'c(?P<centosversion>\d+)-?(?P<projectname>\w+)?'

          oldbranchre = r'(?P<signame>\w+)(?P<centosversion>\d)'
@@ -65,7 +75,39 @@ 

              warnings.warn("This branch is deprecated and will be removed soon",

                            DeprecationWarning)

          else:

-             raise ValueError("Branchname: {0} is not valid".format(branchtext))

+             if not self.is_fork():

+                 raise ValueError("Branchname: {0} is not valid".format(branchtext))

+             else:

+                 self.distrobranch = True

+                 self.signame = 'centos'

+                 self.projectname = self.get_origin().split('_')[-1].replace('.git', '')

+ 

+                 warnings.warn('Remote "origin" was detected as a fork, ignoring branch name checking')

+ 

+     def get_origin(self):

+         if self.repo is None:

+             return ''

+         if 'origin' not in self.repo.remotes:

+             return ''

+         urls = [u for u in self.repo.remotes['origin'].urls]

+         if len(urls) == 0:

+             return ''

+         return urls[0]

+ 

+     def is_fork(self):

+         """

+         Check if origin remote repository is using a fork url.

+ 

+         Returns

+         bool

+             A boolean flag indicating if origin remote url is using

+             a forked repository url.

+         """

+         # git+ssh://git@gitlab.com/redhat/centos-stream/rpms/binutils.git

+         if self.repo is None:

+             return False

+         return self.git_origin_substr not in self.get_origin()

+ 

  

      @property

      def target(self):
@@ -105,7 +147,7 @@ 

  

      @property

      def distgitdir(self):

-         return DistGitDirectory(self.branch_merge)

+         return DistGitDirectory(self.branch_merge, repo_path=self.path)

  

      @cached_property

      def lookasidecache(self):

file modified
+25
@@ -1,7 +1,12 @@ 

  import unittest

+ import unittest.mock

+ 

+ import git

  

  from .mixins import CatchWarningsMixin

  from centpkg import DistGitDirectory

+ from centpkg import git as centpkg_git

+ 

  

  class TestDistGitNothing(unittest.TestCase):

      def test_distgit_emptystring(self):
@@ -180,3 +185,23 @@ 

         with self.assertWarns(DeprecationWarning):

             branchstring = 'virt7'

             d = DistGitDirectory(branchstring)

+ 

+ class TestIsFork(unittest.TestCase):

+     def setUp(self):

+         self.branchstring = 'c9s'

+ 

+     def test_none(self):

+         d = DistGitDirectory(self.branchstring)

+         self.assertFalse(d.is_fork())

+ 

+     @unittest.mock.patch.object(centpkg_git.repo.Repo, 'remotes', new=dict(origin=type('Remote', (object,), {'urls': ['ssh://git@git.centos.org/forks/lrossett/centos/centpkg.git']})))

+     @unittest.mock.patch.object(centpkg_git.repo.Repo, '__init__', new=lambda s, p: None)

+     def test_fork_url(self):

+         d = DistGitDirectory(self.branchstring, 'binutils')

+         self.assertTrue(d.is_fork())

+     

+     @unittest.mock.patch.object(centpkg_git.repo.Repo, 'remotes', new=dict(origin=type('Remote', (object,), {'urls': ['git+ssh://git@gitlab.com/redhat/centos-stream/rpms/binutils.git']})))

+     @unittest.mock.patch.object(centpkg_git.repo.Repo, '__init__', new=lambda s, p: None)

+     def test_upstream_url(self):

+         d = DistGitDirectory(self.branchstring, 'binutils')

+         self.assertFalse(d.is_fork()) 

\ No newline at end of file

fixes #19

Ignores the branch naming pattern if origin url is not a upstream one.

2 new commits added

  • do not use branch pattern name if using a forked origin
  • set correct c9s branchre
3 years ago

2 new commits added

  • do not use branch pattern name if using a forked origin
  • set correct c9s branchre
3 years ago

2 new commits added

  • do not use branch pattern name if using a forked origin
  • set correct c9s branchre
3 years ago

2 new commits added

  • do not use branch pattern name if using a forked origin
  • set correct c9s branchre
3 years ago

rebased onto b099fcc7261b891842a8613068a8a2163d7f203c

3 years ago

This one gives me pause because we're targeting compatibility all the way back to EPEL7, which is still on GitPython 1.0.1, as compared to 3.1.x in EPEL8 and Fedora. We'll need to ensure that our usage of the git library work in both cases.

Also, don't forget to add git to requirements.txt.

GitPython has a native Repo object we can use here.

self.repo = git.Repo(repo_path)

If we use the native Repo object I mentioned above, we can avoid shelling out to the git command.

return self.repo.remotes.origin.url

If this is the only place we're using git_origin_substr, I think it would make more sense to just put the string here and not store it as a variable.

rebased onto 2a887c015f540bb6934b42ccd2d05757484a2cf3

3 years ago

It is actually self.repo.remotes.origin.urls since it probably returns more than one url if any, I am always using the first result in this case.

There may be cases where git_origin_substrmay change, such as SIGs, there is no harm in using it with default values in my opinion.

rebased onto b201d4a

3 years ago

Pull-Request has been merged by carlwgeorge

3 years ago

This has been released in version 0.6.5.