Exemplo n.º 1
0
def codecov_wait(commit):
    def check_codecov_job():
        r = requests.get(
            'https://codecov.io/api/gh/marco-c/gecko-dev/commit/{}?access_token={}'
            .format(commit, secrets[secrets.CODECOV_ACCESS_TOKEN]))
        return True if r.json()['commit']['totals'] is not None else False

    return utils.wait_until(check_codecov_job, 30) is not None
Exemplo n.º 2
0
    def notify(self):
        content = ''

        # Get pushlog and ask the backend to generate the coverage by changeset
        # data, which will be cached.
        r = requests.get(
            'https://hg.mozilla.org/mozilla-central/json-pushes?changeset=%s&version=2&full'
            % self.revision)
        r.raise_for_status()
        push_data = r.json()
        changesets = sum(
            (data['changesets'] for data in push_data['pushes'].values()), [])

        for changeset in changesets:
            desc = changeset['desc'].split('\n')[0]

            if any(text in desc for text in ['r=merge', 'a=merge']):
                continue

            try:
                rev = changeset['node']
                coverage = wait_until(lambda: self.get_coverage_summary(rev),
                                      10)
                if coverage is None:
                    continue

                if coverage['commit_covered'] < 0.2 * coverage['commit_added']:
                    content += '* [%s](https://firefox-code-coverage.herokuapp.com/#/changeset/%s): %d covered out of %d added.\n' % (
                        desc, rev, coverage['commit_covered'],
                        coverage['commit_added'])  # noqa
            except HTTPError as e:
                continue

        if content == '':
            return
        elif len(content) > 102400:
            # Content is 102400 chars max
            content = content[:102000] + '\n\n... Content max limit reached!'

        for email in secrets[secrets.EMAIL_ADDRESSES]:
            self.notify_service.email({
                'address':
                email,
                'subject':
                'Coverage patches for %s' % self.revision,
                'content':
                content,
                'template':
                'fullscreen',
            })
Exemplo n.º 3
0
    def get_mercurial(self, github_commit):
        def get_commit():
            r = requests.get(
                'https://api.pub.build.mozilla.org/mapper/gecko-dev/rev/git/%s'
                % github_commit)

            if r.ok:
                return r.text.split(' ')[1]

            return None

        ret = wait_until(get_commit)
        if ret is None:
            raise Exception('Failed mapping git commit to mercurial commit.')
        return ret
Exemplo n.º 4
0
    def get_commit(self, mercurial_commit):
        def get_commit():
            r = requests.get(
                'https://api.pub.build.mozilla.org/mapper/gecko-dev/rev/hg/%s'
                % mercurial_commit)

            if r.ok:
                return r.text.split(' ')[0]

            return None

        ret = wait_until(get_commit)
        if ret is None:
            raise Exception(
                'Mercurial commit is not available yet on mozilla/gecko-dev.')
        return ret
Exemplo n.º 5
0
def test_wait_until():
    assert utils.wait_until(lambda: False, 1, 1) is None
    assert utils.wait_until(lambda: None, 1, 1) is None
    assert utils.wait_until(lambda: '', 1, 1) is None
    assert utils.wait_until(lambda: True, 1, 1) is not None
    assert utils.wait_until(lambda: 'Prova', 1, 1) is not None

    i = {}

    def try_twice():
        if 'tried' in i:
            return True
        else:
            i['tried'] = True
            return False

    assert utils.wait_until(try_twice, 2, 1) is not None