[users at bb.net] Triggering builds on pull request

David Alves davidralves at gmail.com
Wed Jan 24 16:37:04 UTC 2018


I've managed to sort this out, so leaving it here for future reference.

Turns out there were two problems. The first was that I was using a
git@ url, as the bot needed to download the repo through ssh.
The hook matches the remote repo with the local repo based on the
url so these didn't match and nothing would trigger.
The second problem was that the project's name didn't match.
The hook returns <owner>/<repo name> as the project name,
but the project can only have <repo name> as the slash is illegal
so the project would be found but it would ignore this update.

My solution was to subclass the github event handler and rewrite
the payload to make these match. It's kind of hacky but it works.
Any suggestions on how to do this better are welcome.

class CustomGitHubEventHandler(GitHubEventHandler):
    """
    Decorated GitHubEventHandler to be able to use a git@ url and
    a project name that doesn't contain the owner.
    """
    def handle_pull_request(self, payload, event):
        # Swap the repository url from the html one to the ssh one.
        # We need it to be the ssh one so that infra-bot can login,
but if they don't match
        # builds wont be triggered.
        payload['repository']['html_url'] = payload['repository']['ssh_url']
        # Swap the project name with the "short" name, we can't use
the full name to name projects
        # in buildbot and if it gets the wrong name it won't build.
        payload['pull_request']['base']['repo']['full_name'] =
payload['pull_request']['base']['repo']['name']
        return super(CustomGitHubEventHandler,
self).handle_pull_request(payload, event)

On Tue, Jan 23, 2018 at 11:46 AM, David Alves <davidralves at gmail.com> wrote:
> Hi
>
>   I've installed the latest buildbot (with the travis shim) and got it
> to mostly work with a private project hosted on github.
>   I can trigger builds manually (force build)
>   I setup github/buildbot so that the apps can cross post, and fetch.
> I've tested that github can post to bb's webhook, that bb can fetch a
> commit. I haven't seen bb post messages to the pull request.
>   Tailing the log shows that bb is notified when a pull request is
> added/updated. No errors are shown.
>   However this doesn't cause a "try" build to start or a build status
> to be posted to the pull request. I do see the changes posted to
>   Build>Last Changes.
>   Any help would be greatly appreciated.
>
>   Here's a redacted version of my cfg.yml:
>
> env: {}
> not_important_files: []
> projects:
> -   branches:
>     - master
>     github_token: <token>
>     name: <proj name>
>     reporter_context: bb%(prop:TESTS:+/)s%(prop:TESTS)s
>     repository: git at github.com:<org>/<proj name>.git
>     shallow: 100
>     retryFetch: true
>     mode: "full"
>     method: "clobber"
>     stages: []
>     tags: []
>     vcs_type: github
>     treeStableTimer: 1
> stages: []
> workers:
> -   id: <id>
>     name: local-worker
>     number: 5
>     type: LocalWorker
>
>   and the master.cfg:
>
> from buildbot_travis import TravisConfigurator
> c = BuildmasterConfig = {}
> TravisConfigurator(BuildmasterConfig, basedir).fromYaml('cfg.yml')
>
> from buildbot_travis import TravisConfigurator
> from buildbot_travis.configurator import TravisEndpointMatcher
> from buildbot.plugins import util
>
> c['db_url'] = “<conn str>”
> c['buildbotNetUsageData'] = None
> c['buildbotURL'] = “<local url>”
>
> c['www']['authz'] = util.Authz(
>             allowRules = [
>                util.AnyEndpointMatcher(role="admins", defaultDeny=True),
>                util.AnyControlEndpointMatcher(role="admins"),
>             ],
>             roleMatchers = [
>                util.RolesFromGroups(groupPrefix=‘<org name>/‘),
>             ]
>     )
> c['www']['auth'] = util.GitHubAuth(“<client id>”, “<client secret>”,
> apiVersion=4, getTeamsMembership=True)
>
> # GitHub webhook receiver
> c['www']['change_hook_dialects'] = {
>         'github': {
>                 'token': ‘<token>’,
>                 'secret': ‘<secret>’,
>                 'strict': True,
>         }
> }
>
> Best
> David


More information about the users mailing list