~ubuntu-branches/ubuntu/vivid/fedmsg-meta-fedora-infrastructure/vivid-proposed

« back to all changes in this revision

Viewing changes to fedmsg_meta_fedora_infrastructure/github.py

  • Committer: Package Import Robot
  • Author(s): Nicolas Dandrimont
  • Date: 2014-07-14 22:20:38 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140714222038-mcxbpgmq30ohs102
Tags: 0.2.15-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    __description__ = "Fedora-related Github Repos"
27
27
    __link__ = "https://github.com"
28
28
    __icon__ = "https://apps.fedoraproject.org/img/icons/github.png"
29
 
    __docs__ = "http://developer.github.com/webhooks/#events"
 
29
    __docs__ = "https://developer.github.com/webhooks/#events"
30
30
    __obj__ = "Github Events"
31
31
 
32
32
    def _get_user(self, msg):
33
 
        if 'pusher' in msg['msg']:
 
33
        if msg['msg'].get('commit', None):
 
34
            user = msg['msg']['commit'].get('author', {}).get('login', {})
 
35
            if user:
 
36
                return msg['msg']['fas_usernames'].get(user, user)
 
37
        if msg['msg'].get('pusher', None):
34
38
            pusher = msg['msg']['pusher']['name']
35
39
            return msg['msg']['fas_usernames'].get(pusher, pusher)
36
 
        if 'sender' in msg['msg']:
 
40
        if msg['msg'].get('sender', None):
37
41
            sender = msg['msg']['sender']['login']
38
42
            return msg['msg']['fas_usernames'].get(sender, sender)
39
 
        if 'forkee' in msg['msg']:
 
43
        if msg['msg'].get('forkee', None):
40
44
            forkee = msg['msg']['forkee']['owner']['login']
41
45
            return msg['msg']['fas_usernames'].get(forkee, forkee)
42
46
        return None
53
57
            return None
54
58
 
55
59
    def link(self, msg, **config):
 
60
        if 'target_url' in msg['msg']:
 
61
            return msg['msg']['target_url']
56
62
        if 'compare' in msg['msg']:
57
63
            return msg['msg']['compare']
 
64
        if 'comment' in msg['msg']:
 
65
            return msg['msg']['comment']['html_url']
58
66
        if 'pull_request' in msg['msg']:
59
67
            return msg['msg']['pull_request']['html_url']
60
 
        if 'comment' in msg['msg']:
61
 
            return msg['msg']['comment']['html_url']
62
68
        if 'issue' in msg['msg']:
63
69
            return msg['msg']['issue']['html_url']
64
70
        if 'forkee' in msg['msg']:
93
99
 
94
100
            tmpl = self._('{user} {action} issue #{n} on {repo}')
95
101
            return tmpl.format(user=user, action=action, n=n, repo=repo)
 
102
        elif 'github.pull_request_review_comment' in msg['topic']:
 
103
            n = msg['msg']['pull_request']['number']
 
104
            tmpl = self._('{user} commented on PR #{n} on {repo}')
 
105
            return tmpl.format(user=user, n=n, repo=repo)
 
106
        elif 'github.commit_comment' in msg['topic']:
 
107
            tmpl = self._('{user} commented on a commit on {repo}')
 
108
            return tmpl.format(user=user, repo=repo)
96
109
        elif 'github.create' in msg['topic']:
97
110
            typ = msg['msg']['ref_type']
98
111
            ref = msg['msg']['ref']
99
112
            tmpl = self._('{user} created a new {typ} "{ref}" at {repo}')
100
113
            return tmpl.format(user=user, repo=repo, ref=ref, typ=typ)
 
114
        elif 'github.delete' in msg['topic']:
 
115
            typ = msg['msg']['ref_type']
 
116
            ref = msg['msg']['ref']
 
117
            tmpl = self._('{user} deleted the "{ref}" {typ} at {repo}')
 
118
            return tmpl.format(user=user, repo=repo, ref=ref, typ=typ)
101
119
        elif 'github.fork' in msg['topic']:
102
120
            tmpl = self._('{user} forked {repo}')
103
121
            return tmpl.format(user=user, repo=repo)
 
122
        elif 'github.status' in msg['topic']:
 
123
            description = msg['msg']['description']
 
124
            sha = msg['msg']['sha'][:8]
 
125
            tmpl = self._("{description} for {repo} {sha}")
 
126
            return tmpl.format(description=description, repo=repo, sha=sha)
104
127
        else:
105
128
            pass
106
129
 
116
139
    def objects(self, msg, **config):
117
140
        suffix = '.'.join(msg['topic'].split('.')[3:5])
118
141
        lookup = {
119
 
            'github.push': 'git',
120
 
            'github.pull_request': 'pull_request',
121
 
            'github.issue': 'issue',
 
142
            'github.push': 'tree',
 
143
            'github.issue': 'issues',
122
144
            'github.fork': 'forks',
123
 
            'github.create': 'create',
 
145
            'github.status': 'status',
 
146
            'github.pull_request': 'pull',
 
147
            'github.pull_request_review_comment': 'pull',
 
148
            'github.commit_comment': 'tree',
 
149
            'github.create': None,
 
150
            'github.delete': None,
124
151
        }
125
152
 
126
153
        if suffix not in lookup:
127
154
            return set()
128
155
 
129
 
        base = lookup[suffix] + '/' + self._get_repo(msg)
 
156
        base = self._get_repo(msg)
 
157
        if lookup[suffix]:
 
158
            base = base + "/" + lookup[suffix]
130
159
 
131
160
        items = []
132
161
        if 'commits' in msg['msg']:
140
169
            except KeyError:
141
170
                n = msg['msg']['issue']['number']
142
171
            items = ['%s' % n]
 
172
        elif suffix == 'github.pull_request_review_comment':
 
173
            n = msg['msg']['pull_request']['number']
 
174
            items = ['%s' % n]
143
175
        elif suffix == 'github.fork':
144
176
            items = [self._get_user(msg)]
145
 
        elif suffix == 'github.create':
 
177
        elif suffix == 'github.create' or suffix == 'github.delete':
146
178
            items = ['/'.join([msg['msg']['ref_type'], msg['msg']['ref']])]
 
179
        elif suffix == 'github.status':
 
180
            items = [msg['msg']['commit']['sha']]
 
181
        elif suffix == 'github.commit_comment':
 
182
            items = [msg['msg']['comment']['path']]
147
183
 
148
184
        return set([base + '/' + item for item in items])