##// END OF EJS Templates
events: change target to source repo for pull request events...
dan -
r514:b4f9553f default
parent child Browse files
Show More
@@ -18,7 +18,8 b''
18 18
19 19
20 20 from rhodecode.translation import lazy_ugettext
21 from rhodecode.events.repo import RepoEvent
21 from rhodecode.events.repo import (
22 RepoEvent, _commits_as_dict, _issues_as_dict)
22 23
23 24
24 25 class PullRequestEvent(RepoEvent):
@@ -36,8 +37,11 b' class PullRequestEvent(RepoEvent):'
36 37 from rhodecode.model.pull_request import PullRequestModel
37 38 data = super(PullRequestEvent, self).as_dict()
38 39
39 commits = self._commits_as_dict(self.pullrequest.revisions)
40 issues = self._issues_as_dict(commits)
40 commits = _commits_as_dict(
41 commit_ids=self.pullrequest.revisions,
42 repos=[self.pullrequest.source_repo]
43 )
44 issues = _issues_as_dict(commits)
41 45
42 46 data.update({
43 47 'pullrequest': {
@@ -46,6 +50,7 b' class PullRequestEvent(RepoEvent):'
46 50 'pull_request_id': self.pullrequest.pull_request_id,
47 51 'url': PullRequestModel().get_url(self.pullrequest),
48 52 'status': self.pullrequest.calculated_review_status(),
53 'commits': commits,
49 54 }
50 55 })
51 56 return data
@@ -21,9 +21,85 b' import logging'
21 21 from rhodecode.translation import lazy_ugettext
22 22 from rhodecode.model.db import User, Repository, Session
23 23 from rhodecode.events.base import RhodecodeEvent
24 from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError
24 25
25 26 log = logging.getLogger(__name__)
26 27
28 def _commits_as_dict(commit_ids, repos):
29 """
30 Helper function to serialize commit_ids
31
32 :param commit_ids: commits to get
33 :param repos: list of repos to check
34 """
35 from rhodecode.lib.utils2 import extract_mentioned_users
36 from rhodecode.model.db import Repository
37 from rhodecode.lib import helpers as h
38 from rhodecode.lib.helpers import process_patterns
39 from rhodecode.lib.helpers import urlify_commit_message
40
41 if not repos:
42 raise Exception('no repo defined')
43
44 if not isinstance(repos, (tuple, list)):
45 repos = [repos]
46
47 if not commit_ids:
48 return []
49
50 needed_commits = set(commit_ids)
51
52 commits = []
53 reviewers = []
54 for repo in repos:
55 if not needed_commits:
56 return commits # return early if we have the commits we need
57
58 vcs_repo = repo.scm_instance(cache=False)
59 try:
60 for commit_id in list(needed_commits):
61 try:
62 cs = vcs_repo.get_changeset(commit_id)
63 except CommitDoesNotExistError:
64 continue # maybe its in next repo
65
66 cs_data = cs.__json__()
67 cs_data['mentions'] = extract_mentioned_users(cs_data['message'])
68 cs_data['reviewers'] = reviewers
69 cs_data['url'] = h.url('changeset_home',
70 repo_name=repo.repo_name,
71 revision=cs_data['raw_id'],
72 qualified=True
73 )
74 urlified_message, issues_data = process_patterns(
75 cs_data['message'], repo.repo_name)
76 cs_data['issues'] = issues_data
77 cs_data['message_html'] = urlify_commit_message(cs_data['message'],
78 repo.repo_name)
79 commits.append(cs_data)
80
81 needed_commits.discard(commit_id)
82
83 except Exception as e:
84 log.exception(e)
85 # we don't send any commits when crash happens, only full list matters
86 # we short circuit then.
87 return []
88
89 missing_commits = set(commit_ids) - set(c['raw_id'] for c in commits)
90 if missing_commits:
91 log.error('missing commits: %s' % ', '.join(missing_commits))
92
93 return commits
94
95
96 def _issues_as_dict(commits):
97 """ Helper function to serialize issues from commits """
98 issues = {}
99 for commit in commits:
100 for issue in commit['issues']:
101 issues[issue['id']] = issue
102 return issues
27 103
28 104 class RepoEvent(RhodecodeEvent):
29 105 """
@@ -49,51 +125,6 b' class RepoEvent(RhodecodeEvent):'
49 125 })
50 126 return data
51 127
52 def _commits_as_dict(self, commit_ids):
53 """ Helper function to serialize commit_ids """
54
55 from rhodecode.lib.utils2 import extract_mentioned_users
56 from rhodecode.model.db import Repository
57 from rhodecode.lib import helpers as h
58 from rhodecode.lib.helpers import process_patterns
59 from rhodecode.lib.helpers import urlify_commit_message
60 if not commit_ids:
61 return []
62 commits = []
63 reviewers = []
64 vcs_repo = self.repo.scm_instance(cache=False)
65 try:
66 for commit_id in commit_ids:
67 cs = vcs_repo.get_changeset(commit_id)
68 cs_data = cs.__json__()
69 cs_data['mentions'] = extract_mentioned_users(cs_data['message'])
70 cs_data['reviewers'] = reviewers
71 cs_data['url'] = h.url('changeset_home',
72 repo_name=self.repo.repo_name,
73 revision=cs_data['raw_id'],
74 qualified=True
75 )
76 urlified_message, issues_data = process_patterns(
77 cs_data['message'], self.repo.repo_name)
78 cs_data['issues'] = issues_data
79 cs_data['message_html'] = urlify_commit_message(cs_data['message'],
80 self.repo.repo_name)
81 commits.append(cs_data)
82 except Exception as e:
83 log.exception(e)
84 # we don't send any commits when crash happens, only full list matters
85 # we short circuit then.
86 return []
87 return commits
88
89 def _issues_as_dict(self, commits):
90 """ Helper function to serialize issues from commits """
91 issues = {}
92 for commit in commits:
93 for issue in commit['issues']:
94 issues[issue['id']] = issue
95 return issues
96
97 128
98 129 class RepoPreCreateEvent(RepoEvent):
99 130 """
@@ -198,8 +229,9 b' class RepoPushEvent(RepoVCSEvent):'
198 229 data = super(RepoPushEvent, self).as_dict()
199 230 branch_url = repo_url = data['repo']['url']
200 231
201 commits = self._commits_as_dict(self.pushed_commit_ids)
202 issues = self._issues_as_dict(commits)
232 commits = _commits_as_dict(
233 commit_ids=self.pushed_commit_ids, repos=[self.repo])
234 issues = _issues_as_dict(commits)
203 235
204 236 branches = set(
205 237 commit['branch'] for commit in commits if commit['branch'])
General Comments 0
You need to be logged in to leave comments. Login now