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

Pierre Tardy tardyp at gmail.com
Fri Jan 26 18:42:27 UTC 2018


Normally the project name should not be used by buildbot_travis.

I think the problem is that indeed, buildbot_travis setups the change
filters so that it matches the http url, and not ssh url.

Another option is to use https instead of ssh to download the source code.

You can the use the .gitconfig insteadOf trick in your worker environment
in order to tell git to use a https authentication token.

https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth

git config --global url."https://<token>@github.com/".insteadOf
https://github.com/
https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/

IPierre

On Wed, Jan 24, 2018 at 5:37 PM David Alves <davidralves at gmail.com> wrote:

> 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
> _______________________________________________
> users mailing list
> users at buildbot.net
> https://lists.buildbot.net/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.buildbot.net/pipermail/users/attachments/20180126/2b9015ee/attachment.html>


More information about the users mailing list