"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.5.1/buildbot/www/hooks/gitorious.py" (24 Nov 2019, 2911 Bytes) of package /linux/misc/buildbot-2.5.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "gitorious.py" see the Fossies "Dox" file reference documentation.

    1 # This file is part of Buildbot.  Buildbot is free software: you can
    2 # redistribute it and/or modify it under the terms of the GNU General Public
    3 # License as published by the Free Software Foundation, version 2.
    4 #
    5 # This program is distributed in the hope that it will be useful, but WITHOUT
    6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8 # details.
    9 #
   10 # You should have received a copy of the GNU General Public License along with
   11 # this program; if not, write to the Free Software Foundation, Inc., 51
   12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   13 #
   14 # Copyright Buildbot Team Members
   15 #
   16 # note: this file is based on github.py
   17 
   18 
   19 import json
   20 import re
   21 
   22 from dateutil.parser import parse as dateparse
   23 
   24 from twisted.python import log
   25 
   26 from buildbot.util import bytes2unicode
   27 from buildbot.www.hooks.base import BaseHookHandler
   28 
   29 
   30 class GitoriousHandler(BaseHookHandler):
   31 
   32     def getChanges(self, request):
   33         payload = json.loads(bytes2unicode(request.args[b'payload'][0]))
   34         user = payload['repository']['owner']['name']
   35         repo = payload['repository']['name']
   36         repo_url = payload['repository']['url']
   37         project = payload['project']['name']
   38 
   39         changes = self.process_change(payload, user, repo, repo_url, project)
   40         log.msg("Received %s changes from gitorious" % len(changes))
   41         return (changes, 'git')
   42 
   43     def process_change(self, payload, user, repo, repo_url, project):
   44         changes = []
   45         newrev = payload['after']
   46 
   47         branch = payload['ref']
   48         if re.match(r"^0*$", newrev):
   49             log.msg("Branch `%s' deleted, ignoring" % branch)
   50             return []
   51         else:
   52             for commit in payload['commits']:
   53                 files = []
   54                 # Gitorious doesn't send these, maybe later
   55                 # if 'added' in commit:
   56                 #     files.extend(commit['added'])
   57                 # if 'modified' in commit:
   58                 #     files.extend(commit['modified'])
   59                 # if 'removed' in commit:
   60                 #     files.extend(commit['removed'])
   61                 when_timestamp = dateparse(commit['timestamp'])
   62 
   63                 log.msg("New revision: %s" % commit['id'][:8])
   64                 changes.append({
   65                     'author': '%s <%s>' % (commit['author']['name'],
   66                                            commit['author']['email']),
   67                     'files': files,
   68                     'comments': commit['message'],
   69                     'revision': commit['id'],
   70                     'when_timestamp': when_timestamp,
   71                     'branch': branch,
   72                     'revlink': commit['url'],
   73                     'repository': repo_url,
   74                     'project': project
   75                 })
   76 
   77         return changes
   78 
   79 
   80 gitorious = GitoriousHandler