def _check_cc(v, req): """cc=release/LinuxCoreX (can be given multiple times)""" try: git.commit_message('origin/%s' % v) return True except git.ExecutionError: print 'branch "%s" doesn\'t exist' % v return False
def check_prune(defconfig): msg = git.commit_message('HEAD') restriction = None data = None for line in msg.split('\n'): # handle RFC 822 style folded lines if data and line[0].isspace(): data += line[1:] continue else: data = line kv = data.split('=', 1) data = '' if len(kv) != 2: continue k, v = kv if k == 'restriction': restriction = v if restriction != 'nopublic': return 0 # if we want the top-most patch to have no public changes, # remember where we were commit = git.rev_parse() # first reset to the previous patch: git.reset(["-q", "--hard", "HEAD~1"]) git.clean(['-fdxq']) # then prune, commit and remember the state prune(defconfig, False, '.') git.commit_all("prune test", env={ 'GIT_COMMITTER_NAME': 'prune tester', 'GIT_COMMITTER_EMAIL': '', 'GIT_AUTHOR_NAME': 'prune tester', 'GIT_AUTHOR_EMAIL': '', }) pruned_prev = git.rev_parse() # go back to the top commit git.reset(["-q", "--hard", commit]) git.clean(['-fdxq']) # prune this one again prune(defconfig, False, '.') # reset to the previous prune git.reset([pruned_prev]) # and check if anything is left: if git.is_modified(): print("FAILURE: restriction=nopublic patch modifies prune tree") subprocess.call(['git', 'diff']) ret = 1 else: ret = 0 # eases development: git.reset(["-q", "--hard", commit]) return ret
def check_metadata(): msg = git.commit_message("HEAD") required = ['type', 'ticket'] found = {} subj = msg.split('\n')[0] data = None r = 0 for line in msg.split('\n'): # handle RFC 822 style folded lines if data and line[0].isspace(): data += line[1:] continue else: data = line kv = data.split('=', 1) data = '' if len(kv) != 2: continue k, v = kv f = globals().get('_check_%s' % k, None) if f is None: # could be anything not specified since we're parsing # the whole commit message continue if not f(v, required): r |= 2 found[k] = v missing = set(required) - set(found) m = [] for k in missing: m.append("missing " + globals().get('_check_%s' % k, None).__doc__) if missing: print '\n'.join(m) r |= 2 # mandate [BUGFIX] tag if 'type' in found and found['type'] == 'bugfix': if not subj.startswith('[BUGFIX]'): print 'bug fixes require "[BUGFIX] subject"' r |= 2 else: # bugfix might be reverted as part of a cleanup if 'BUGFIX' in subj and not subj.startswith('Revert "'): print 'only bugfixes should have [BUGFIX] tag' r |= 2 return r
def check_branch_changeid(): msg = git.commit_message("HEAD") changeid_re = re.compile('^Change-Id: (I[0-9a-fA-F]{40})$') changeid = None for line in msg.split('\n'): m = changeid_re.match(line) if not m: continue changeid = m.group(1) break if not changeid: return 0 if not check_changeid_exists(changeid): print "Change-Id should exist on master" return 2 return 0
def monitor_chromeos(addrs): cachedir = CACHEDIR if not cachedir: cachedir = os.path.join(os.getcwd(), '..', 'kernel-cache') if not os.path.isdir(cachedir): git.clone(DBTREE, cachedir, options=['--quiet', '--bare']) git.set_origin(DBTREE, cachedir) git.remote_update(cachedir) os.chdir(cachedir) db = git.commit_message('origin/monitor').split('\n') for line in db: for v in VERSIONS: if line.startswith(v.kbranch + ': '): v.start = line.split(': ')[1] prev = None tree_id = git.get_commit_var('origin/monitor', 'T') parent_id = git.rev_parse('origin/monitor') db = [] any_changes = False for v in VERSIONS: if v.ktree != prev: git.set_origin(v.ktree, cachedir) git.remote_update(cachedir) prev = v.ktree range = 'origin/' + v.kbranch if v.start: range = v.start + '..' + range try: log = git.log([ range, '--', 'drivers/net/wireless%s/iwl7000' % v.wifiversion ]) except: # maybe they rebased? try again w/o start range = 'origin/' + v.kbranch log = git.log([ range, '--', 'drivers/net/wireless%s/iwl7000' % v.wifiversion ]) if log: msg = MIMEText(log) msg['Subject'] = 'new changes in %s' % v.kbranch msg['From'] = '*****@*****.**' msg['To'] = ', '.join(addrs) s = smtplib.SMTP(SMTPSERVER) s.sendmail('*****@*****.**', addrs, msg.as_string()) s.quit() any_changes = True db.append(v.kbranch + ': ' + git.rev_parse('origin/%s' % v.kbranch)) db = ['update commit tracker', ''] + db + [''] msg = '\n'.join(db) git.set_origin(DBTREE) if any_changes: new_tree_id = git.commit_tree(tree_id, [parent_id], msg, env={ 'GIT_AUTHOR_NAME': 'cros-monitor', 'GIT_AUTHOR_EMAIL': '', 'GIT_COMMITTER_NAME': 'cros-monitor', 'GIT_COMMITTER_EMAIL': '', }) git.push(['origin', '%s:monitor' % new_tree_id])
def monitor_chromeos(jira): n_tickets = 0 cachedir = CACHEDIR if not cachedir: cachedir = os.path.join(os.getcwd(), '..', 'kernel-cache') if not os.path.isdir(cachedir): debug("Clone database tree to %s..." % cachedir) git.clone(DBTREE, cachedir, options=['--quiet', '--bare']) git.set_origin(DBTREE, cachedir) debug("Update database tree ...") git.remote_update(cachedir) os.chdir(cachedir) db = git.commit_message('origin/monitor').split('\n') for line in db: for v in VERSIONS: if line.startswith(v.kbranch + ': '): v.start = line.split(': ')[1] prev = None tree_id = git.get_commit_var('origin/monitor', 'T') parent_id = git.rev_parse('origin/monitor') db = [] any_changes = False for v in VERSIONS: if v.ktree != prev: git.set_origin(v.ktree, cachedir) debug("Update kernel tree to %s" % v.ktree) git.remote_update(cachedir, env={'https_proxy': PROXY}) prev = v.ktree range = 'origin/' + v.kbranch if v.start: range = v.start + '..' + range log_args_front = [ '--no-merges', '--invert-grep', '--grep=iwl7000-tree:', ] log_args_back = [ '--', 'drivers/net/wireless/iwl7000', ] try: log = git.log(log_args_front + [range] + log_args_back) except: # maybe they rebased? try again w/o start range = 'origin/' + v.kbranch log = git.log(log_args_front + [range] + log_args_back) if log: any_changes = True # create a jira ticket with this info date = time.strftime('%Y-%m-%d') fields = { 'summary': '[%s] google changed tree %s' % (v.kbranch, date), 'description': '{noformat}\n%s\n{noformat}\n' % log, } fields.update(COMMON_JIRA_FIELDS) debug("creating new ticket ...") ticket = jira.create_issue(fields=fields) for watcher in WATCHERS: jira.add_watcher(ticket, watcher) jira.assign_issue(ticket, ASSIGNEE) debug("created ticket %s" % ticket) db.append(v.kbranch + ': ' + git.rev_parse('origin/%s' % v.kbranch)) db = ['update commit tracker', ''] + db + [''] msg = '\n'.join(db) git.set_origin(DBTREE) if any_changes: new_tree_id = git.commit_tree(tree_id, [parent_id], msg, env={ 'GIT_AUTHOR_NAME': 'cros-monitor', 'GIT_AUTHOR_EMAIL': '', 'GIT_COMMITTER_NAME': 'cros-monitor', 'GIT_COMMITTER_EMAIL': '', }) git.push(['origin', '%s:monitor' % new_tree_id])