1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

# This file is part of Buildbot.  Buildbot is free software: you can 

# redistribute it and/or modify it under the terms of the GNU General Public 

# License as published by the Free Software Foundation, version 2. 

# 

# This program is distributed in the hope that it will be useful, but WITHOUT 

# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 

# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 

# details. 

# 

# You should have received a copy of the GNU General Public License along with 

# this program; if not, write to the Free Software Foundation, Inc., 51 

# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 

# 

# Copyright Buildbot Team Members 

 

# code inspired/copied from contrib/github_buildbot 

#  and inspired from code from the Chromium project 

# otherwise, Andrew Melo <andrew.melo@gmail.com> wrote the rest 

# but "the rest" is pretty minimal 

 

from buildbot.util import json 

 

def getChanges(request, options=None): 

        """ 

        Consumes a naive build notification (the default for now) 

        basically, set POST variables to match commit object parameters: 

        revision, revlink, comments, branch, who, files, links 

         

        files, links and properties will be de-json'd, the rest are interpreted as strings 

        """ 

 

        def firstOrNothing( value ): 

            """ 

            Small helper function to return the first value (if value is a list) 

            or return the whole thing otherwise 

            """ 

            if ( type(value) == type([])): 

                return value[0] 

            else: 

                return value 

 

        args = request.args 

 

        # first, convert files, links and properties 

        files = None 

        if args.get('files'): 

            files = json.loads( args.get('files')[0] ) 

        else: 

            files = [] 

 

        properties = None 

        if args.get('properties'): 

            properties = json.loads( args.get('properties')[0] ) 

        else: 

            properties = {} 

 

        revision = firstOrNothing(args.get('revision')) 

        when     = firstOrNothing(args.get('when')) 

        author = firstOrNothing(args.get('author')) 

        if not author: 

            author = firstOrNothing(args.get('who')) 

        comments = firstOrNothing(args.get('comments')) 

        isdir = firstOrNothing(args.get('isdir',0)) 

        branch = firstOrNothing(args.get('branch')) 

        category = firstOrNothing(args.get('category')) 

        revlink = firstOrNothing(args.get('revlink')) 

        repository = firstOrNothing(args.get('repository')) 

        project = firstOrNothing(args.get('project')) 

 

        chdict = dict(author=author, files=files, comments=comments, 

                isdir=isdir, revision=revision, when=when, 

                branch=branch, category=category, revlink=revlink, 

                properties=properties, repository=repository, 

                project=project) 

        return ([ chdict ], None)