| # Copyright 2014 the Melange authors. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| from twisted.internet import defer |
| from twisted.python import log |
| |
| from buildbot.changes import gitpoller |
| from buildbot import util |
| |
| |
| class GerritGitPoller(gitpoller.GitPoller): |
| """Custom Gerrit GitPoller. This will poll a remote git repo for |
| changes and submit them to the change master.""" |
| |
| def __init__(self, *args, **kwargs): |
| GitPoller.__init__(self, *args, **kwargs) |
| |
| def _headsFilter(self, branch): |
| """Overrides GitPoller._headsFilter. Filters out remote references |
| that don't begin with 'refs/heads' or 'refs/changes'.""" |
| return branch.startswith("refs/heads/") or branch.startswith( |
| "refs/changes/") |
| |
| @defer.inlineCallbacks |
| def _process_changes(self, newRev, branch): |
| """Read changes from the latest refs/changes/* branch. |
| |
| - Extract details from each commit. |
| - Add changes to database. |
| """ |
| rev = self.lastRev.get(branch) |
| |
| if rev: |
| if rev != newRev: |
| self.changeCount = 1 |
| revList = [newRev] |
| log.msg('New change on branch - %s' %(branch,)) |
| else: |
| self.changeCount = 0 |
| revList = [] |
| else: |
| self.changeCount = 1 |
| revList = [newRev] |
| log.msg('New Branch created - %s' %(branch,)) |
| |
| |
| log.msg('gitpoller: processing %d changes: %s from "%s"' |
| % (self.changeCount, revList, self.repourl)) |
| |
| for rev in revList: |
| dl = defer.DeferredList([ |
| self._get_commit_timestamp(rev), |
| self._get_commit_author(rev), |
| self._get_commit_files(rev), |
| self._get_commit_comments(rev), |
| ], consumeErrors=True) |
| |
| results = yield dl |
| |
| # check for failures |
| failures = [r[1] for r in results if not r[0]] |
| if failures: |
| # just fail on the first error; they're probably all related! |
| raise failures[0] |
| |
| timestamp, author, files, comments = [r[1] for r in results] |
| yield self.master.addChange( |
| author=author, |
| revision=rev, |
| files=files, |
| comments=comments, |
| when_timestamp=util.epoch2datetime(timestamp), |
| branch=self._removeHeads(branch), |
| category=self.category, |
| project=self.project, |
| repository=self.repourl, |
| src='git') |