Exemplo n.º 1
0
 def _files_to_update(working_directory):
     logger.info('UpdateMavenVersion: creating list of files to update')
     for dir_name, dirs, files in os.walk(working_directory):
         for file_name in files:
             if 'pom.xml' in file_name.lower():
                 file_path = os.path.join(dir_name, file_name)
                 yield file_path
Exemplo n.º 2
0
 def _get_working_directory(self):
     logger.info('UpdateMavenVersion: getting working directory')
     working_directory = self.working_directory
     if working_directory is None:
         working_directory = '%(home)s/tmp/repos' % \
                             {'home': os.path.expanduser('~')}
     return working_directory
Exemplo n.º 3
0
 def execute(self, jenkins_job=None):
     """
     Modifies SCM branch name for given job.
     :param jenkins_job: Jenkins job
     """
     logger.info('ChangeGitRevision: updating SCM branch')
     self.modify_scm_branch(jenkins_job, self.revision)
     logger.info('ChangeGitRevision: SCM branch updated')
Exemplo n.º 4
0
 def _replace_in_file(self, file_path):
     logger.info(
         'UpdateMavenVersion: updating version in file %(file_path)s'
         % {'file_path': file_path})
     with open(file_path) as f:
         s = f.read()
     s = s.replace(self.old_version, self.new_version)
     with open(file_path, 'w') as f:
         f.write(s)
Exemplo n.º 5
0
 def execute(self, jenkins_job=None):
     """
     Creates a new tag in the remote using given tag name.
     :param jenkins_job: Jenkins job
     """
     logger.info('CreateGitTag: creating git tag "%s"' % self._tag)
     scm_urls = self.get_scm_url(jenkins_job)
     for url in scm_urls:
         self._create_remote_tag(jenkins_job, url)
     logger.info('CreateGitTag: git tag created')
Exemplo n.º 6
0
 def _create_remote_tag(self, jenkins_job, url):
     repo = self._get_repo(jenkins_job, url)
     if self._tag not in repo.tags:
         git.TagReference.create(repo=repo, path=self._tag)
         origin = repo.remotes['origin']
         origin.push(tags=True, progress=PrintProgress())
         logger.info('All changes pushed to the remote')
     else:
         print('Given tag %(tag)s already exists - skipping step' %
               {'tag': self._tag})
Exemplo n.º 7
0
    def _clone_repo(self, url, branch, jenkins_job):
        logger.info('Cloning repository %(url)s' % {'url': url})
        if not self._repo_dir_exists():
            os.makedirs(self.repo_dir_path)

        repo_path = os.path.join(self.repo_dir_path, jenkins_job.name)
        cloned_repo = git.Repo.clone_from(url=url, to_path=repo_path,
                                          branch=branch)
        logger.info('Repository %(url)s cloned to dir "%(dir)s"'
                    % {'url': url, 'dir': repo_path})
        return cloned_repo
Exemplo n.º 8
0
 def execute(self, jenkins_job=None):
     """
     Executes current action for the given Jenkins job
     :param jenkins_job: Jenkins job
     """
     logger.info('CopyJobWithNewVersion: starting to create job copy')
     # TODO: check if the job with given name already exists and eventually
     # skip this step
     job_name = jenkins_job.name
     new_job_name = job_name.replace(self.old_version, self.new_version)
     jenkins_job.jenkins.create_job(new_job_name, jenkins_job.get_config())
     logger.info('CopyJobWithNewVersion: job copy created')
Exemplo n.º 9
0
    def execute(self, jenkins_job=None):
        """
        Adds a new branch to the remote using given branch name.
        :param jenkins_job: Jenkins job
        """
        logger.info(
            'CreateGitBranch: creating new branch "%s"' % self._branch_name)
        scm_urls = self.get_scm_url(jenkins_job)

        for url in scm_urls:
            repo = self._get_repo(jenkins_job, url)
            new_branch = repo.create_head(self._branch_name)
            origin = repo.remotes['origin']
            origin.push(new_branch, progress=PrintProgress())
        logger.info('CreateGitBranch: branch created')
Exemplo n.º 10
0
    def execute(self, jenkins_job=None):
        logger.info('UpdateMavenVersion: Starting versions update')
        working_directory = os.path \
            .join(self._get_working_directory(), jenkins_job.name)

        logger.info('UpdateMavenVersion: Running task in directory %(dir)s'
                    % {'dir': working_directory})
        r = git.Repo(working_directory)

        files_to_update = self._files_to_update(working_directory)
        for file_path in files_to_update:
            self._replace_in_file(file_path)
            r.index.add([file_path])
        logger.info('UpdateMavenVersion: committing changes')
        origin = r.remotes['origin']
        head = r.create_head('master', origin.refs['master'])
        head.repo.heads['master'].checkout()
        head.repo.index.commit('Update module version')
        origin.push(head, progress=PrintProgress())
        logger.info('UpdateMavenVersion: version update finished')