def main():
    print('(', end='')
    first = True
    for project in gerrit_project_map(sys.argv[1]):
        if first:
            first = False
        else:
            print('|', end='')
        print('ardana/'+project, end='')
    print(')', end='')
예제 #2
0
def main():
    print('(', end='')
    first = True
    for project in gerrit_project_map(sys.argv[1]):
        if first:
            first = False
        else:
            print('|', end='')
        print('ardana/' + project, end='')
    print(')', end='')
예제 #3
0
 def __init__(self, gerrit_project, url, target_branch, source_workspace):
     self.gerrit_project = gerrit_project
     self.name = gerrit_project_map(target_branch)[gerrit_project]
     self.url = url
     self.target_branch = target_branch
     self.test_branch = 'test-merge'
     self.source_workspace = source_workspace
     self.source_dir = os.path.join(
         self.source_workspace, '%s.git' % self.gerrit_project)
     self._workspace_ready = False
     self._applied_changes = set()
예제 #4
0
 def __init__(self, gerrit_project, url, target_branch, source_workspace):
     self.gerrit_project = gerrit_project
     self.name = gerrit_project_map(target_branch)[gerrit_project]
     self.url = url
     self.target_branch = target_branch
     self.test_branch = 'test-merge'
     self.source_workspace = source_workspace
     self.source_dir = os.path.join(self.source_workspace,
                                    '%s.git' % self.gerrit_project)
     self._workspace_ready = False
     self._applied_changes = set()
예제 #5
0
def gerrit_review(change, label=None, vote=1, message=''):
    if change.gerrit_project not in gerrit_project_map(change.branch):
        print("Skipping - project {} not in the list of "
              "allowed projects ".format(change.gerrit_project))
        return 1

    if not change.is_current:
        print("Skipping - change {} is not current".format(change))
        return 1

    change.review(label, vote, message)

    return 0
예제 #6
0
def gerrit_review(change, label=None, vote=1, message=''):
    if change.gerrit_project not in gerrit_project_map():
        print("Skipping - project {} not in the list of "
              "allowed projects ".format(change.gerrit_project))
        return 1

    if not change.is_current:
        print("Skipping - change {} is not current".format(change))
        return 1

    change.review(label, vote, message)

    return 0
예제 #7
0
def gerrit_merge(change, dry_run=False):
    """
    Attempt to merge a Gerrit change.

    :param change:
    :param dry_run:
    :return:
    """
    project_map = gerrit_project_map(change.branch)

    print('Attempting to merge change {}'.format(change))

    if not change.is_current and not dry_run:
        print("Skipping - change is not current: {}".format(change))
        return 1

    if change.gerrit_project not in project_map:
        print("Skipping - project {} not in the list of "
              "allowed projects ".format(change.gerrit_project))
        return 1

    if change.status != 'NEW':
        print("Skipping - change is {}: {}".format(change.status.lower(),
                                                   change))
        return 1

    if not change.mergeable:
        print("Change cannot be merged due to conflicts: {}".format(change))
        return 1

    if not change.submittable:
        print("Change doesn't meet submit requirements: {}".format(change))
        return 1

    if not check_all_dependencies_satisfied(change):
        msg = "Unable to merge: Commit dependencies are not satisifed."
        print(msg)
        if not dry_run:
            change.review(message=msg)
        return 1

    if not dry_run:
        change.merge()
        print("Change merged: {}".format(change))
    else:
        print("[DRY-RUN] Change can be merged: {}".format(change))

    return 0
예제 #8
0
def gerrit_merge(change, dry_run=False):
    """
    Attempt to merge a Gerrit change.

    :param change:
    :param dry_run:
    :return:
    """
    project_map = gerrit_project_map(change.branch)

    print('Attempting to merge change {}'.format(change))

    if not change.is_current and not dry_run:
        print("Skipping - change is not current: {}".format(change))
        return 1

    if change.gerrit_project not in project_map:
        print("Skipping - project {} not in the list of "
              "allowed projects ".format(change.gerrit_project))
        return 1

    if change.status != 'NEW':
        print("Skipping - change is {}: {}".format(
            change.status.lower(), change))
        return 1

    if not change.mergeable:
        print("Change cannot be merged due to conflicts: {}".format(change))
        return 1

    if not change.submittable:
        print("Change doesn't meet submit requirements: {}".format(change))
        return 1

    if not check_all_dependencies_satisfied(change):
        msg = "Unable to merge: Commit dependencies are not satisifed."
        print(msg)
        if not dry_run:
            change.review(message=msg)
        return 1

    if not dry_run:
        change.merge()
        print("Change merged: {}".format(change))
    else:
        print("[DRY-RUN] Change can be merged: {}".format(change))

    return 0
예제 #9
0
def build_test_packages(change_ids, obs_linked_project, home_project,
                        obs_repository, build_number):

    print('Attempting to build packages for changes {}'.format(
        ', '.join(change_ids)))

    # The target branch associated with the first change is used for
    # all changes
    branch = None

    # Grab each change for the supplied change_ids
    changes = []
    for id in change_ids:
        c = GerritChange(id, branch=branch)
        branch = branch or c.branch
        changes.append(c)
        # Add the dependent changes to the changes list to process
        changes.extend(c.get_dependencies())

    # Use the default OBS linked project and repository configured for
    # the target branch, if not supplied as arguments
    project_settings = obs_project_settings(branch)
    obs_linked_project = obs_linked_project or \
        project_settings['develproject']
    obs_repository = obs_repository or project_settings['repository']

    # The Jenkins workspace we are building in
    workspace = os.getcwd()
    # The location for package sources
    source_workspace = os.path.join(workspace, 'source')
    cleanup_path(source_workspace)

    if not os.path.exists(source_workspace):
        os.mkdir(source_workspace)

    obs_test_project_name = test_project_name(home_project, build_number)
    obs_test_project_description = "Packages built with gerrit changes: %s" % \
        (', '.join(change_ids).replace('/', '-'))

    obs_project = OBSProject(
        obs_test_project_name, obs_linked_project, obs_repository,
        obs_test_project_description)

    # Keep track of processed changes
    processed_changes = []
    # Keep track of the packages to build as a dict of
    # 'gerrit_project': Package()
    packages = {}

    # We process the supplied changes, as well as their dependencies.
    # If a change has already been processed we skip it to avoid circular
    # dependencies.
    for c in changes:
        if c in processed_changes:
            # Duplicate dependency, skipping..
            continue
        processed_changes.append(c)

        # skip packages that don't have asssociated RPMs
        if c.gerrit_project not in gerrit_project_map(branch):
            print("Warning: Project %s has no RPM, Skipping"
                  % c.gerrit_project)
        else:
            # Create the package if it doesn't exist already
            if c.gerrit_project not in packages:
                # NOTE: The first change processed for a package determines
                #       the target branch for that package. All subsquent
                #       changes must match the target branch.
                packages[c.gerrit_project] = OBSPackage(
                    c.gerrit_project, c.url, c.branch, source_workspace)

            # Merge the change into the package
            packages[c.gerrit_project].add_change(c)

    for project_name, package in gerrit_project_map(branch).items():
        if project_name in packages:
            continue
        url = GERRIT_URL + "/ardana/" + project_name
        packages[project_name] = OBSPackage(
            project_name, url, branch, source_workspace)

    # Add the packages into the obs project and begin building them
    for project_name, package in packages.items():
        obs_project.add_test_package(package)

    # Wait for, and grab, the obs results
    results = obs_project.wait_for_all_results()

    # Cleanup created files
    obs_project.cleanup_test_packages()
    cleanup_path(source_workspace)

    return results
예제 #10
0
def build_test_packages(change_ids, obs_linked_project, home_project,
                        obs_repository, build_number):

    print('Attempting to build packages for changes {}'.format(
        ', '.join(change_ids)))

    # The target branch associated with the first change is used for
    # all changes
    branch = None

    # Grab each change for the supplied change_ids
    changes = []
    for id in change_ids:
        c = GerritChange(id, branch=branch)
        branch = branch or c.branch
        changes.append(c)
        # Add the dependent changes to the changes list to process
        changes.extend(c.get_dependencies())

    # Use the default OBS linked project and repository configured for
    # the target branch, if not supplied as arguments
    project_settings = obs_project_settings(branch)
    obs_linked_project = obs_linked_project or \
        project_settings['develproject']
    obs_repository = obs_repository or project_settings['repository']

    # The Jenkins workspace we are building in
    workspace = os.getcwd()
    # The location for package sources
    source_workspace = os.path.join(workspace, 'source')
    cleanup_path(source_workspace)

    if not os.path.exists(source_workspace):
        os.mkdir(source_workspace)

    obs_test_project_name = test_project_name(home_project, build_number)
    obs_test_project_description = "Packages built with gerrit changes: %s" % \
        (', '.join(change_ids).replace('/', '-'))

    obs_project = OBSProject(obs_test_project_name, obs_linked_project,
                             obs_repository, obs_test_project_description)

    # Keep track of processed changes
    processed_changes = []
    # Keep track of the packages to build as a dict of
    # 'gerrit_project': Package()
    packages = {}

    # We process the supplied changes, as well as their dependencies.
    # If a change has already been processed we skip it to avoid circular
    # dependencies.
    for c in changes:
        if c in processed_changes:
            # Duplicate dependency, skipping..
            continue
        processed_changes.append(c)

        # skip packages that don't have asssociated RPMs
        if c.gerrit_project not in gerrit_project_map(branch):
            print("Warning: Project %s has no RPM, Skipping" %
                  c.gerrit_project)
        else:
            # Create the package if it doesn't exist already
            if c.gerrit_project not in packages:
                # NOTE: The first change processed for a package determines
                #       the target branch for that package. All subsquent
                #       changes must match the target branch.
                packages[c.gerrit_project] = OBSPackage(
                    c.gerrit_project, c.url, c.branch, source_workspace)

            # Merge the change into the package
            packages[c.gerrit_project].add_change(c)

    for project_name, package in gerrit_project_map(branch).items():
        if project_name in packages:
            continue
        url = GERRIT_URL + "/ardana/" + project_name
        packages[project_name] = OBSPackage(project_name, url, branch,
                                            source_workspace)

    # Add the packages into the obs project and begin building them
    for project_name, package in packages.items():
        obs_project.add_test_package(package)

    # Wait for, and grab, the obs results
    results = obs_project.wait_for_all_results()

    # Cleanup created files
    obs_project.cleanup_test_packages()
    cleanup_path(source_workspace)

    return results
예제 #11
0
def main():
    parts = sys.argv[1].split('/')
    subproject = parts[1]
    print(gerrit_project_map()[subproject])