add semantic versioning checks
This commit is contained in:
		@ -6,38 +6,58 @@ except ImportError:
 | 
			
		||||
    # Python < 3
 | 
			
		||||
    from ConfigParser import ConfigParser
 | 
			
		||||
 | 
			
		||||
version = "1.0.4"
 | 
			
		||||
version = "1.0.5"
 | 
			
		||||
 | 
			
		||||
class SemVer(object):
 | 
			
		||||
 | 
			
		||||
    GET_COMMIT_MESSAGE = re.compile(r"Merge branch '(.+)' into ([^\n]+)")
 | 
			
		||||
    GET_COMMIT_MESSAGE = re.compile(r"Merge (branch|pull request) '?(.+)'? (into|from) ([\w/-]+)")
 | 
			
		||||
     #Merge pull request #1 from RightBrain-Networks/feature/PLAT-185-versioning
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        self.merged_branch = None
 | 
			
		||||
        self.main_branch = None
 | 
			
		||||
        self.version_type = None
 | 
			
		||||
 | 
			
		||||
        self.main_branches = self._setting_to_array('main_branches')
 | 
			
		||||
        self.major_branches = self._setting_to_array('major_branches')
 | 
			
		||||
        self.minor_branches = self._setting_to_array('minor_branches')
 | 
			
		||||
        self.patch_branches = self._setting_to_array('patch_branches')
 | 
			
		||||
        self.main_branches = ['development', 'env-test', 'env-stage', 'env-prod']
 | 
			
		||||
        self.major_branches = []
 | 
			
		||||
        self.minor_branches = ['feature', 'RightBrain-Networks/feature']
 | 
			
		||||
        self.patch_branches = ['hotfix', 'bugfix']
 | 
			
		||||
 | 
			
		||||
    def _setting_to_array(self, setting):
 | 
			
		||||
        config = ConfigParser()
 | 
			
		||||
        config.read('./.bumpversion.cfg')
 | 
			
		||||
        value = config.get('semver', setting)
 | 
			
		||||
    #def _setting_to_array(self, setting):
 | 
			
		||||
     #   config = ConfigParser()
 | 
			
		||||
     #   config.read('./.bumpversion.cfg')
 | 
			
		||||
     #   value = config.get('semver', setting)
 | 
			
		||||
     #   print(str(value))
 | 
			
		||||
        
 | 
			
		||||
        #return value.split(',')
 | 
			
		||||
        # filter() removes empty string which is what we get if setting is blank
 | 
			
		||||
        return filter(bool, [v.strip() for v in value.split(',')])
 | 
			
		||||
        #return [v.strip() for v in value.split(',')]
 | 
			
		||||
 | 
			
		||||
    # based on commit message see what branches are involved in the merge
 | 
			
		||||
    
 | 
			
		||||
    def get_branches(self):
 | 
			
		||||
        p = subprocess.Popen(['git', 'log', '-1'], stdout=subprocess.PIPE,
 | 
			
		||||
                             cwd='.')
 | 
			
		||||
        #check current branch
 | 
			
		||||
        b = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=subprocess.PIPE,
 | 
			
		||||
                             cwd='.')
 | 
			
		||||
        message = str(p.stdout.read())
 | 
			
		||||
        br = b.stdout.read().decode('utf-8')
 | 
			
		||||
        #remove newline
 | 
			
		||||
        branch=br.rstrip()
 | 
			
		||||
        print("Main branch is "+branch)
 | 
			
		||||
        matches = self.GET_COMMIT_MESSAGE.search(message)
 | 
			
		||||
        if matches:
 | 
			
		||||
            self.merged_branch = matches.group(1)
 | 
			
		||||
            self.main_branch = matches.group(2)
 | 
			
		||||
            if str(matches.group(4)) == branch:
 | 
			
		||||
                self.merged_branch = matches.group(2)
 | 
			
		||||
            else:
 | 
			
		||||
                self.merged_branch = matches.group(4)
 | 
			
		||||
            self.main_branch = branch
 | 
			
		||||
            #print("group1 "+matches.group(1))
 | 
			
		||||
            #print("group2 "+matches.group(2))
 | 
			
		||||
            #print("group3 "+matches.group(3))
 | 
			
		||||
            #print("group4 "+matches.group(4))
 | 
			
		||||
        
 | 
			
		||||
        return bool(matches)
 | 
			
		||||
 | 
			
		||||
    # based on branches involved see what type of versioning should be done
 | 
			
		||||
@ -78,7 +98,7 @@ class SemVer(object):
 | 
			
		||||
 | 
			
		||||
    def commit_and_push(self):
 | 
			
		||||
        # push versioning commit
 | 
			
		||||
        p = subprocess.Popen(['git', 'push', 'origin', 'develop'],
 | 
			
		||||
        p = subprocess.Popen(['git', 'push', 'origin', self.main_branch],
 | 
			
		||||
                             cwd='.')
 | 
			
		||||
        p.wait()
 | 
			
		||||
 | 
			
		||||
@ -93,6 +113,7 @@ class SemVer(object):
 | 
			
		||||
    # 3) see what type of versioning we should do
 | 
			
		||||
    # 4) version the repo
 | 
			
		||||
    def run(self):
 | 
			
		||||
        print(self.main_branches)
 | 
			
		||||
        if not self.get_branches():
 | 
			
		||||
            raise Exception('No merge found')
 | 
			
		||||
        if self.main_branch not in self.main_branches:
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								semver/__pycache__/__init__.cpython-36.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								semver/__pycache__/__init__.cpython-36.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user