Ejemplo n.º 1
0
    def __init__(self, file_path, git_credentials=None):
        """
        __build_name - Refer to the field "build-name" in manifest file.
        __repositories - Refer to the field "repositories" in manifest file.
        __downstream_jobs - Refer to the field "downstream-jobs" in manifest file.
        __file_path - The file path of the manifest file
        __name - The file name of the manifest file
        __manifest -The content of the manifest file
        __changed - If manifest is changed, be True; The default value is False
        __git_credentials  - URL, credentials pair for the access to github repos
        gitbit - Class instance of gitbit
        """

        self._build_name = None
        self._build_requirements = None
        self._repositories = []
        self._downstream_jobs = []
        self._file_path = file_path
        self._name = file_path.split('/')[-1]
        self._manifest = None
        self._changed = False

        self._git_credentials = None
        self.gitbit = GitBit(verbose=True)

        if git_credentials:
            self._git_credentials = git_credentials
            self.setup_gitbit()

        self.read_manifest_file(self._file_path)
        self.parse_manifest()
Ejemplo n.º 2
0
    def __init__(self, git_credentials=None):
        """
        Create a repository interface object

        :return:
        """
        self._git_credentials = git_credentials

        self.git = GitBit(verbose=True)
        if self._git_credentials:
            self.setup_gitbit()
Ejemplo n.º 3
0
    def do_one_task(self, name, data, results):
        """
        Perform the actual work of checking out a repository.   This portion of the
        task is performed in a subprocess, and may be performed in parallel with other
        instances.

        name and data will come from the values passed in to add_task()

        :param name:
        :param data:
        data should contain:
           'credentials': a list of Git credentials in URL:VARIABLE_NAME format
           'repo': a repository entry from a manifest file
           'builddir': the location to check out the repository into
        :param results: a shared dictionary for storing results and sharing them to the
                        parent process
        :return: None (all output data stored in results)
        """

        # make sure we have all of the right data that we need to start the build
        if name is None or data is None:
            raise ValueError("name or data not present")

        for key in ['repo', 'builddir']:
            if key not in data:
                raise ValueError("{0} key missing from data: {1}".format(
                    key, data))

        repo = data['repo']
        if 'repository' not in repo:
            raise ValueError("no repository in work {0}".format(repo))

        # data validation okay, so start the work

        print "Starting checkout of {0}".format(name)

        # someplace to start storing results of the commands that will be run
        results['commands'] = []
        git = GitBit(verbose=False)
        if 'credentials' in data and data['credentials'] is not None:
            for credential in data['credentials']:
                url, cred = credential.split(',', 2)
                git.add_credential_from_variable(url, cred)
        repo_url = repo['repository']
        destination_directory_name = strip_suffix(os.path.basename(repo_url),
                                                  ".git")
        # build up a git clone command line
        # clone [ -b branchname ] repository_url [ destination_name ]

        command = ['clone']

        #clone big files with git-lfs is much faster
        if repo.has_key('lfs') and repo['lfs']:
            command = ['lfs', 'clone']

        if 'branch' in repo and repo['branch'] != "":
            command.extend(['-b', repo['branch']])

        command.append(repo_url)

        if 'checked-out-directory-name' in repo:
            # this specifies what the directory name of the checked out repository
            # should be, as opposed to using Git's default (the basename of the repository URL)

            # note to self: do not combine the following two lines again
            destination_directory_name = repo['checked-out-directory-name']
            command.append(destination_directory_name)

        destination_directory = os.path.abspath(
            data['builddir']) + "/" + destination_directory_name
        if os.path.isdir(destination_directory):
            shutil.rmtree(destination_directory)
        self.run_git_command(git, command, data['builddir'], results)

        # the clone has been performed -- now check to see if we need to move the HEAD
        # to point to a specific location within the tree history.   That will be true
        # if there is a commit-id or tag value specified in the repository (which will
        # be the case most of the time).

        reset_id = self._get_reset_value(repo)

        if reset_id is not None:
            working_directory = os.path.join(data['builddir'],
                                             destination_directory_name)

            command = [
                "fetch", "origin", "refs/pull/*:refs/remotes/origin/pr/*"
            ]
            self.run_git_command(git, command, working_directory, results)

            command = ["reset", "--hard", reset_id]
            self.run_git_command(git, command, working_directory, results)

        results['status'] = "success"