Caution

Buildbot no longer supports Python 2.7 on the Buildbot master.

2.5.14.8. GitHubCommentPush

from buildbot.plugins import reporters, util

gc = reporters.GitHubCommentPush(token='githubAPIToken',
                                 startDescription='Build started.',
                                 endDescription='Build done.')
factory = util.BuildFactory()
buildbot_bbtools = util.BuilderConfig(
    name='builder-name',
    workernames=['worker1'],
    factory=factory)
c['builders'].append(buildbot_bbtools)
c['services'].append(gc)

GitHubCommentPush publishes a comment on a PR using GitHub Review Comments API.

It requires txrequests package to allow interaction with GitHub REST API.

It is configured with at least a GitHub API token. By default, it will only comment at the end of a build unless a startDescription is provided.

You can create a token from your own GitHub - Profile - Applications - Register new application or use an external tool to generate one.

class buildbot.reporters.github.GitHubCommentPush(token, startDescription=None, endDescription=None, baseURL=None, verbose=False, builders=None)
Parameters
  • token (string) – token used for authentication. (can be a Secret)

  • string startDescription (rendereable) – Custom start message (default: None)

  • string endDescription (rendereable) – Custom end message (default: ‘Build done.’)

  • baseURL (string) – specify the github api endpoint if you work with GitHub Enterprise

  • verbose (boolean) – if True, logs a message for each successful status push

  • builders (list) – only send update for specified builders

  • verify (boolean) – disable ssl verification for the case you use temporary self signed certificates

  • debug (boolean) – logs every requests and their response

Returns

string for comment, must be less than 65536 bytes.

Here’s a complete example of posting build results as a github comment:

@util.renderer
@defer.inlineCallbacks
def getresults(props):
    all_logs=[]
    master = props.master
    steps = yield props.master.data.get(
        ('builders', props.getProperty('buildername'), 'builds',
        props.getProperty('buildnumber'), 'steps'))
    for step in steps:
        if step['results'] == util.Results.index('failure'):
            logs = yield master.data.get(("steps", step['stepid'], 'logs'))
            for l in logs:
                all_logs.append('Step : {0} Result : {1}'.format(
                                    step['name'], util.Results[step['results']]))
                all_logs.append('```')
                l['stepname'] = step['name']
                l['content'] = yield master.data.get(("logs", l['logid'], 'contents'))
                step_logs = l['content']['content'].split('\n')
                include = False
                for i, sl in enumerate(step_logs):
                    all_logs.append(sl[1:])
                all_logs.append('```')
    return '\n'.join(all_logs)

gc = GitHubCommentPush(token='githubAPIToken',
                       endDescription=getresults,
                       context=Interpolate('buildbot/%(prop:buildername)s'))
c['services'].append(gc)