Beispiel #1
0
def mail_to_cvs(payload, mailer):
    # safeguard against github getting confused and sending us the entire
    # history
    if len(payload['commits']) > 40:
        return

    for commit in payload['commits']:

        commit_data = get_info_from_commit(commit)

        data = {
            'push': payload,
            'commit': commit,
            'files': '\n'.join(commit_data['files']),
            'diff': commit_data['diff'],
        }

        msg = Message(
            subject='{0}/{1}: {2}'.format(
                payload['repository']['name'],
                payload['ref'].split('/')[-1],
                commit_data['short_commit_msg']),
            sender='{0} <*****@*****.**>'.format(
                commit['committer']['name']
            ),
            recipients=['*****@*****.**'],
            body=templates['commit_email.pt'](**data),
            extra_headers={'Reply-To': commit_data['reply_to']}
        )

        mailer.send_immediately(msg, fail_silently=False)
Beispiel #2
0
def mail_to_cvs(payload, mailer):
    # safeguard against github getting confused and sending us the entire
    # history
    if len(payload['commits']) > 40:
        return

    for commit in payload['commits']:

        commit_data = get_info_from_commit(commit)

        data = {
            'push': payload,
            'commit': commit,
            'files': '\n'.join(commit_data['files']),
            'diff': commit_data['diff'],
        }

        repo_name = payload['repository']['name']
        branch = payload['ref'].split('/')[-1]
        commit_msg = commit_data['short_commit_msg']
        msg = Message(
            subject=f'{repo_name}/{branch}: {commit_msg}',
            sender=f'{commit["committer"]["name"]} <*****@*****.**>',
            recipients=['*****@*****.**'],
            body=templates['commit_email.pt'](**data),
            extra_headers={'Reply-To': commit_data['reply_to']},
        )

        mailer.send_immediately(msg, fail_silently=False)
Beispiel #3
0
 def test_unicode_on_messages(self, mock_get):
     mock_get.content = mock.Mock(return_value='diff data')
     commit_data = COMMIT
     commit_data['message'] = (
         u'Höla què tal\n' u'Files changed:\nM CHÄNGES.rst\nM setup.py'
     )
     data = get_info_from_commit(commit_data)
     self.assertEqual(data['short_commit_msg'], 'Hla qu tal')
     self.assertTrue(
         data['full_commit_msg'].endswith('Files changed:\nM CHNGES.rst\nM setup.py')
     )
Beispiel #4
0
 def test_get_info_from_commit(self, mock_get):
     mock_get.content = mock.Mock(return_value='diff data')
     data = get_info_from_commit(COMMIT)
     self.assertEqual(data['files'], ['M last_commit.txt'])
     self.assertEqual(data['sha'], '4f7caf77eb1384572f4d7d9a90a4888fbcbd68a8')
     self.assertEqual(data['reply_to'], 'mister-roboto <*****@*****.**>')
     self.assertEqual(data['short_commit_msg'], '[fc] Repository: plone.app.upgrade')
     self.assertTrue(
         data['full_commit_msg'].endswith(
             'Files changed:\nM CHANGES.rst\nM setup.py'
         )
     )
Beispiel #5
0
def get_info(payload, repo, branch):
    """ gather information about the commits

    There are three special cases:

    - fake: the commit was made by mr.roboto itself
    - skip: the committer requested to skip CI for this commit,
      usually done by the release team to avoid flooding Jenkins
    - sources_or_checkouts: either sources.cfg or checkouts.cfg has been
      changed (the data stored locally needs to be updated maybe)

    Return the changeset, both a short and a log version, plus the special
    cases.
    """
    timestamp = datetime.datetime.now(GMT1()).isoformat()
    changeset = ''
    changeset_long = ''
    fake = False
    skip = False
    source_or_checkout = False
    for commit in payload['commits']:
        # get the commit data structure
        commit_data = get_info_from_commit(commit)
        files = '\n'.join(commit_data['files'])

        if '[fc]' in commit_data['short_commit_msg']:
            fake = True
        if '[ci skip]' in commit_data['full_commit_msg']:
            skip = True
        if '[ci-skip]' in commit_data['full_commit_msg']:
            skip = True
        if 'sources.cfg' in files or 'checkouts.cfg' in files:
            source_or_checkout = True

        # prepare a changeset text message
        data = {
            'push': payload,
            'commit': commit,
            'files': files,
            'diff': commit_data['diff'],
        }
        changeset += templates['github_commit.pt'](**data)
        changeset_long += templates['jenkins_changeset.pt'](**data)

        # get a timestamp for later usage when creating commits
        timestamp = commit['timestamp']

        msg = f'Commit: on {repo} {branch} {commit["id"]}'
        logger.info(msg)

    return timestamp, changeset, changeset_long, fake, skip, source_or_checkout
Beispiel #6
0
def get_info(payload, repo, branch):
    """ gather information about the commits

    There are three special cases:

    - fake: the commit was made by mr.roboto itself
    - skip: the committer requested to skip CI for this commit,
      usually done by the release team to avoid flooding Jenkins
    - sources_or_checkouts: either sources.cfg or checkouts.cfg has been
      changed (the data stored locally needs to be updated maybe)

    Return the changeset, both a short and a log version, plus the special
    cases.
    """
    timestamp = datetime.datetime.now(GMT1()).isoformat()
    changeset = ''
    changeset_long = ''
    fake = False
    skip = False
    source_or_checkout = False
    for commit in payload['commits']:
        # get the commit data structure
        commit_data = get_info_from_commit(commit)
        files = '\n'.join(commit_data['files'])

        if '[fc]' in commit_data['short_commit_msg']:
            fake = True
        if '[ci skip]' in commit_data['full_commit_msg']:
            skip = True
        if '[ci-skip]' in commit_data['full_commit_msg']:
            skip = True
        if 'sources.cfg' in files or 'checkouts.cfg' in files:
            source_or_checkout = True

        # prepare a changeset text message
        data = {
            'push': payload,
            'commit': commit,
            'files': files,
            'diff': commit_data['diff'],
        }
        changeset += templates['github_commit.pt'](**data)
        changeset_long += templates['jenkins_changeset.pt'](**data)

        # get a timestamp for later usage when creating commits
        timestamp = commit['timestamp']

        msg = f'Commit: on {repo} {branch} {commit["id"]}'
        logger.info(msg)

    return timestamp, changeset, changeset_long, fake, skip, source_or_checkout