Exemple #1
0
    def commits(self,
                executor: ThreadPoolExecutor,
                range_ref: str,
                limit: int = 0):
        log_lines = git.log(self.path, range_ref)
        if limit > 0:
            log_lines = log_lines[:limit]

        def parse_line(line):
            if line == "":
                return

            match = commit_re.match(line)
            if match is None:
                return

            commit_hash, commit_date = [match[k] for k in (range(1, 3))]
            if commit_hash is None or commit_date is None:
                return

            return commit_hash, isoparse(commit_date)

        # TODO: try
        # return executor.map(log_lines, parse_line)
        return [executor.submit(parse_line, l) for l in log_lines]
def check_changeid_exists(changeid):
    msg = git.log(options=[
        '--basic-regexp', '--grep',
        '^Change-Id: %s$' % changeid, 'origin/master'
    ])
    if not msg:
        return False
    return True
def _check_fixes(v, req):
    """fixes=<changeid|unknown>"""
    if v == "unknown":
        return True
    # log origin/master to avoid having a patch that fixes a previous uncommitted
    # patch that should just be squashed instead
    orig_owner = git.log(options=['--basic-regexp', '--grep', '^Change-Id: *%s$' %v , '--pretty=format:%ae', 'origin/master'])
    if not orig_owner:
        print 'fixes= change-id doesn\'t exist (yet) (or did you mean "unknown"?)'
        return False
    if 'JENKINS_HOME' in os.environ:
        subprocess.call(['ssh', 'git-amr-3.devtools.intel.com', 'gerrit','set-reviewers','-a', orig_owner, git.rev_parse('HEAD')])
    return True
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])