def prep_new_patches_branch(new_version, local_patches_branch, patches_branch, local_patches=False, bump_only=False, patches_style=None, version_tag_style=None, unattended=False, no_push_patches=False): if patches_style == 'review': if no_push_patches: return new_version_tag = guess.version2tag(new_version, version_tag_style) try: remote, branch = git.remote_branch_split(patches_branch) if unattended: log.warn('Unattended mode: force pushing patches') else: helpers.confirm("Push %s to %s/%s (with --force)?" % (new_version_tag, remote, branch)) git('branch', '--force', local_patches_branch, new_version_tag) git('push', '--force', remote, '%s:%s' % (local_patches_branch, branch)) # push the tag git('push', '--force', remote, new_version_tag) except exception.UserAbort: pass else: if not (local_patches or bump_only): _reset_branch(local_patches_branch, remote_branch=patches_branch)
def prep_new_patches_branch(new_version, local_patches_branch, patches_branch, local_patches=False, bump_only=False, patches_style=None, version_tag_style=None, unattended=False, no_push_patches=False): if patches_style == 'review': if no_push_patches: return new_version_tag = guess.version2tag(new_version, version_tag_style) try: remote, branch = git.remote_branch_split(patches_branch) if unattended: log.warn('Unattended mode: force pushing patches') else: helpers.confirm("Push %s to %s/%s (with --force)?" % ( new_version_tag, remote, branch)) git('branch', '--force', local_patches_branch, new_version_tag) git('push', '--force', remote, '%s:%s' % (local_patches_branch, branch)) # push the tag git('push', '--force', remote, new_version_tag) except exception.UserAbort: pass else: if not (local_patches or bump_only): _reset_branch(local_patches_branch, remote_branch=patches_branch)
def rebase_patches_branch(new_version, local_patches_branch, patches_branch=None, local_patches=False, patches_style=None, version_tag_style=None, bump_only=False): if bump_only: return git.checkout(local_patches_branch) new_version_tag = guess.version2tag(new_version, version_tag_style) git('rebase', new_version_tag, direct=True) if patches_style != 'review': if local_patches or not patches_branch: return if _is_same_commit(local_patches_branch, patches_branch): log.info("%s is up to date, no need for push." % patches_branch) return try: remote, branch = git.remote_branch_split(patches_branch) helpers.confirm("Push %s to %s / %s (with --force)?" % ( local_patches_branch, remote, branch)) git('push', '--force', remote, '%s:%s' % (local_patches_branch, branch)) # push the tag git('push', '--force', remote, new_version_tag) except exception.UserAbort: pass
def get_upstream_patches(version, local_patches_branch, patches_branch=None, upstream_branch=None, new_milestone=None): # TODO: nuke this, looks unused patches = git("log", "--cherry-pick", "--pretty=format:\%s", "%(remote)s...%(local)s" % {'remote': patches_branch, 'local': local_patches_branch}) changes = [p.strip().replace('\\', '') for p in patches.split('\n') if p != ''] if not changes: log.warn("No new patches detected in %s." % local_patches_branch) helpers.confirm("Do you want to continue anyway?", default_yes=False) n_patches = len(changes) changes.insert(0, ("Rebase %s changes from %s" % (n_patches, upstream_branch))) args = {'changes': changes} if n_patches > 0: if new_milestone: new_milestone += '.p%d' % n_patches else: new_milestone = 'p%d' % n_patches args['new_milestone'] = new_milestone return args
def review_patches_branch(local_patches_branch, patches_style=None, bump_only=False): if patches_style != 'review' or bump_only: return try: helpers.confirm("Send %s branch for review?" % local_patches_branch) rpmfactory.review_patch(local_patches_branch) except exception.UserAbort: pass
def review_patches_branch(local_patches_branch, patches_style=None, bump_only=False, unattended=False): if patches_style != 'review' or bump_only: return try: if unattended: log.warn("Unattended mode: sending %s branch for review") else: helpers.confirm("Send %s branch for review?" % local_patches_branch) rpmfactory.review_patch(local_patches_branch) except exception.UserAbort: pass
def check_new_patches(version, local_patches_branch, patches_style=None, local_patches=False, patches_branch=None, changes=None, version_tag_style=None): if not changes: changes = [] if local_patches or patches_style == 'review': head = local_patches_branch else: if not patches_branch: raise exception.RequiredActionArgumentNotAvailable( action='check_new_patches', arg='patches_branch') head = patches_branch version_tag = guess.version2tag(version, version_tag_style) patches = git.get_commit_bzs(version_tag, head) spec = specfile.Spec() n_git_patches = len(patches) n_spec_patches = spec.get_n_patches() n_skip_patches = spec.get_n_excluded_patches() n_ignore_patches = 0 ignore_regex = spec.get_patches_ignore_regex() if ignore_regex: patches = (flatten(_partition_patches(patches, ignore_regex))) n_ignore_patches = n_git_patches - len(patches) patch_subjects = [] for hash, subject, bzs in patches: subj = subject bzstr = ' '.join(map(lambda x: 'rhbz#%s' % x, bzs)) if bzstr != '': subj += ' (%s)' % bzstr patch_subjects.append(subj) n_base_patches = n_skip_patches + n_spec_patches log.debug("Total patches in git:%d spec:%d skip:%d ignore:%d" % ( n_git_patches, n_spec_patches, n_skip_patches, n_ignore_patches)) if n_base_patches > 0: patch_subjects = patch_subjects[0:-n_base_patches] if not patch_subjects: log.warn("No new patches detected in %s." % head) helpers.confirm("Do you want to continue anyway?", default_yes=False) changes.extend(patch_subjects) return {'changes': changes}
def fetch_patches_branch(local_patches_branch, gerrit_patches_chain, force=False): review_n = _review_number(gerrit_patches_chain) gerrit_host, gerrit_port = guess.gerrit_from_repo() query = GerritQuery(gerrit_host, gerrit_port) review = query('--current-patch-set', review_n) current_ps = review.get('currentPatchSet', {}) patchset_n = current_ps.get('number') if not patchset_n: raise exception.CantGuess( msg='Failed to determine current patch set for review: %s' % gerrit_patches_chain) gerrit_ref = _review_ref(review_n, patchset_n) git('fetch', 'patches', gerrit_ref) approvals = current_ps.get('approvals', []) jenkins = [ a for a in approvals if a.get('type') == 'Verified' and a.get('by', {}).get('username') == 'jenkins' ] code_reviews = [ int(a.get('Value', 0)) for a in approvals if a.get('type') == 'Code-Review' ] if not jenkins: verified = 0 else: verified = int(jenkins[0]['value']) if verified != 1: if force: log.warn("Ref %s has not been validated by CI." % gerrit_patches_chain) helpers.confirm("Do you want to continue anyway?", default_yes=False) else: raise exception.UnverifiedPatch() if any(cr < 0 for cr in code_reviews): log.warn("Ref %s has at least one negative review." % gerrit_patches_chain) helpers.confirm("Do you want to continue anyway?", default_yes=False) git('update-ref', 'refs/heads/%s' % local_patches_branch, 'FETCH_HEAD')
def copr_check(release=None, dist=None): osdist = guess.osdist() if osdist == 'RHOS': helpers.confirm("Look like you're trying to build RHOS package in " "public copr.\nProceed anyway?") if not release: raise exception.CantGuess(what='release', why="Specify with -r/--release") if not dist: builds = guess.builds(release=release) for dist_, src in builds: if src.startswith('copr/jruzicka'): dist = dist_ log.info("Autodetected dist: %s" % dist) break if not dist: raise exception.CantGuess(what='dist', why="Specify with -d/--dist") return {'dist': dist}
def fetch_patches_branch(local_patches_branch, gerrit_patches_chain, force=False): review_n = _review_number(gerrit_patches_chain) gerrit_host, gerrit_port = guess.gerrit_from_repo() query = GerritQuery(gerrit_host, gerrit_port) review = query('--current-patch-set', review_n) current_ps = review.get('currentPatchSet', {}) patchset_n = current_ps.get('number') if not patchset_n: raise exception.CantGuess( msg='Failed to determine current patch set for review: %s' % gerrit_patches_chain) gerrit_ref = _review_ref(review_n, patchset_n) git('fetch', 'patches', gerrit_ref) approvals = current_ps.get('approvals', []) jenkins = [a for a in approvals if a.get('type') == 'Verified' and a.get('by', {}).get('username') == 'jenkins'] code_reviews = [int(a.get('Value', 0)) for a in approvals if a.get('type') == 'Code-Review'] if not jenkins: verified = 0 else: verified = int(jenkins[0]['value']) if verified != 1: if force: log.warn( "Ref %s has not been validated by CI." % gerrit_patches_chain) helpers.confirm("Do you want to continue anyway?", default_yes=False) else: raise exception.UnverifiedPatch() if any(cr < 0 for cr in code_reviews): log.warn( "Ref %s has at least one negative review." % gerrit_patches_chain) helpers.confirm("Do you want to continue anyway?", default_yes=False) git('update-ref', 'refs/heads/%s' % local_patches_branch, 'FETCH_HEAD')
def update_rdoinfo_check(update): fail_msg = None warn = False rls = defaultdict(set) for b in update.builds: rls[b.repo].add(b) log.info("Checking update using rdoinfo...".format( t=log.term)) for r, builds in rls.items(): rbuilds = guess.builds(r) rbuilds_ = list(rbuilds) if not rbuilds: msg = 'Unknown OpenStack release: %s' % r log.warn(msg) if not fail_msg: fail_msg = msg continue for b in builds: found = False for dist_, src_ in rbuilds: if b.dist == dist_: found = True rbuilds_ = filter(lambda x: x[0] != b.dist, rbuilds_) break if not found: msg = 'Unexpected %s build: %s' % (r, b.dist) log.warn(msg) if not fail_msg: fail_msg = msg for dist_, src_ in rbuilds_: log.info('Missing %s build: %s' % (r, dist_)) warn = True if fail_msg: raise exception.UpdateCheckFailed(fail=fail_msg) if warn: helpers.confirm("Submit anyway?")
def cbs_build(scratch=False): if git.branch_needs_push() and not scratch: helpers.confirm("It seems local distgit branch needs push. Push " "now?") git('push') cbsbuild.new_build(profile='cbs', scratch=scratch)
def koji_build(): if git.branch_needs_push(): helpers.confirm("It seems local distgit branch needs push. Push " "now?") git('push') kojibuild.new_build()
def new_version_setup(patches_branch=None, local_patches=False, version=None, new_version=None, version_tag_style=None, new_sources=None, no_new_sources=None, unattended=False, bug=None, bump_only=False): args = {} if new_version: # support both version and tag ver, _ = guess.tag2version(new_version) if ver != new_version: new_version = ver args['new_version'] = new_version new_version_tag = guess.version2tag(new_version, version_tag_style) if not bump_only and not git.object_type(new_version_tag): raise exception.InvalidGitRef(ref=new_version_tag) else: ub = guess.upstream_branch() if not git.ref_exists('refs/remotes/%s' % ub): msg = ("Upstream branch not found: %s\n" "Can't guess latest version.\n\n" "a) provide new version (git tag) yourself\n" " $ rdopkg new-version 1.2.3\n\n" "b) add upstream git remote:\n" " $ git remote add -f upstream GIT_URL\n" % ub) raise exception.CantGuess(msg=msg) new_version_tag = git.get_latest_tag(ub) new_version, _ = guess.tag2version(new_version_tag) args['new_version'] = new_version log.info("Latest version detected from %s: %s" % (ub, new_version)) if version == new_version: if unattended: log.info("Package is already at version %s\n" % version) raise exception.UserAbort(exit_code=0) helpers.confirm( msg="It seems the package is already at version %s\n\n" "Run new-version anyway?" % version, default_yes=False) changelog = 'Update to %s' % new_version if bug: changelog += ' (%s)' % bug args['changes'] = [changelog] args['new_patches_base'] = new_version_tag spec = specfile.Spec() rpm_version = spec.get_tag('Version') rpm_milestone = spec.get_milestone() new_rpm_version, new_milestone = specfile.version_parts(new_version) args['new_rpm_version'] = new_rpm_version if new_milestone: args['new_milestone'] = new_milestone if (rpm_version != new_rpm_version or bool(new_milestone) != bool(rpm_milestone)): if new_milestone: args['new_release'] = '0.1' else: args['new_release'] = '1' if not local_patches and not bump_only: if not patches_branch or \ not git.ref_exists('refs/remotes/' + patches_branch): log.warn("Patches branch '%s' not found. Running in --bump-only " "mode." % patches_branch) args['bump_only'] = True if new_sources or no_new_sources: if new_sources and no_new_sources: raise exception.InvalidUsage( msg="DOES NOT COMPUTE: both -n and -N don't make sense.") # new_sources == not no_new_sources else: new_sources = guess.new_sources() args['new_sources'] = new_sources return args
def new_version_setup(patches_branch=None, local_patches=False, version=None, new_version=None, version_tag_style=None, new_sources=None, no_new_sources=None): args = {} if new_version: # support both version and tag ver, _ = guess.tag2version(new_version) if ver != new_version: new_version = ver args['new_version'] = new_version new_version_tag = guess.version2tag(new_version, version_tag_style) else: ub = guess.upstream_branch() if not git.ref_exists('refs/remotes/%s' % ub): msg = ("Upstream branch not found: %s\n" "Can't guess latest version.\n\n" "a) provide new version (git tag) yourself\n" " $ rdopkg new-version 1.2.3\n\n" "b) add upstream git remote:\n" " $ git remote add -f upstream GIT_URL\n" % ub) raise exception.CantGuess(msg=msg) new_version_tag = git.get_latest_tag(ub) new_version, _ = guess.tag2version(new_version_tag) args['new_version'] = new_version log.info("Latest version detected from %s: %s" % (ub, new_version)) if version == new_version: helpers.confirm( msg="It seems the package is already at version %s\n\n" "Run new-version anyway?" % version, default_yes=False) args['changes'] = ['Update to %s' % new_version] args['new_patches_base'] = new_version_tag spec = specfile.Spec() rpm_version = spec.get_tag('Version') rpm_milestone = spec.get_milestone() new_rpm_version, new_milestone = specfile.version_parts(new_version) args['new_rpm_version'] = new_rpm_version if new_milestone: args['new_milestone'] = new_milestone if (rpm_version != new_rpm_version or bool(new_milestone) != bool(rpm_milestone)): if new_milestone: args['new_release'] = '0.1' else: args['new_release'] = '1' if not local_patches: if not patches_branch or \ not git.ref_exists('refs/remotes/' + patches_branch): log.warn("Patches branch '%s' not found. Running in --bump-only " "mode." % patches_branch) args['bump_only'] = True if new_sources or no_new_sources: if new_sources and no_new_sources: raise exception.InvalidUsage( msg="DOES NOT COMPUTE: both -n and -N don't make sense.") # new_sources == not no_new_sources else: new_sources = guess.new_sources() args['new_sources'] = new_sources return args