Merge lp:~matiasb/locolander/repo-services-fixes into lp:locolander

Proposed by Matias Bordese
Status: Merged
Merged at revision: 15
Proposed branch: lp:~matiasb/locolander/repo-services-fixes
Merge into: lp:locolander
Diff against target: 128 lines (+33/-15)
4 files modified
locolander/locolanderweb/tests/test_models.py (+1/-1)
locolander/repos/github.py (+7/-4)
locolander/repos/launchpad.py (+1/-1)
locolander/repos/tests/test_github.py (+24/-9)
To merge this branch: bzr merge lp:~matiasb/locolander/repo-services-fixes
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Review via email: mp+174577@code.launchpad.net

Commit message

- Fixed LP regex validation.
- Updated GitHub source/target returned values.

Description of the change

- Fixed LP regex validation.
- Updated GitHub source/target returned values.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'locolander/locolanderweb/tests/test_models.py'
2--- locolander/locolanderweb/tests/test_models.py 2013-07-06 23:19:29 +0000
3+++ locolander/locolanderweb/tests/test_models.py 2013-07-13 19:29:25 +0000
4@@ -34,7 +34,7 @@
5 'locolander',
6 'launchpad.net',
7 'launchpad.net/foo',
8- ###'lp:launchpad.net/foo',
9+ 'lp:launchpad.net/foo',
10 'https://github.com/username',
11 'git@github.com:foo/dippi-dapi',
12 )
13
14=== modified file 'locolander/repos/github.py'
15--- locolander/repos/github.py 2013-06-23 15:12:30 +0000
16+++ locolander/repos/github.py 2013-07-13 19:29:25 +0000
17@@ -23,6 +23,9 @@
18 # GitHub API access
19 self.gh = GitHub()
20
21+ def _get_clone_url(self, username, repo_name):
22+ return "https://github.com/%s/%s.git" % (username, repo_name)
23+
24 def _is_approved_comment(self, repo, comment):
25 # this is an 'approved' comment by a commiter
26 lines = comment.body.split('\n')
27@@ -55,10 +58,10 @@
28 approved.append({
29 # XXX: needs UTC processing?
30 'date_created': pull.created_at,
31- ### 'source_repo': self.gh.repository(*pull.base.repo),
32- 'source': pull.base.ref,
33- ### 'target_repo': self.gh.repository(*pull.head.repo),
34- 'target': pull.head.ref,
35+ 'source': "%s %s" % (self._get_clone_url(*pull.base.repo),
36+ pull.base.ref),
37+ 'target': "%s %s" % (self._get_clone_url(*pull.head.repo),
38+ pull.head.ref),
39 'reviewers': last_comment.user.login, # csv
40 'commit_message': commit_message,
41 })
42
43=== modified file 'locolander/repos/launchpad.py'
44--- locolander/repos/launchpad.py 2013-07-06 23:19:29 +0000
45+++ locolander/repos/launchpad.py 2013-07-13 19:29:25 +0000
46@@ -11,7 +11,7 @@
47
48
49 CACHE_DIR = os.path.join(os.path.expanduser('~'), '.launchpadlib', 'cache')
50-LAUNCHPAD_LP_RE = re.compile(r'^lp:(?:~[^/]+/)?([^/]+)(?:/[^/]+)?$')
51+LAUNCHPAD_LP_RE = re.compile(r'^lp:(?:~[^/]+/)?([^/\.]+)(?:/[^/]+)?$')
52 LAUNCHPAD_HTTPS_RE = re.compile(
53 r'^http(s)?://launchpad.net/(?:~[^/]+/)?([^/]+)$')
54
55
56=== modified file 'locolander/repos/tests/test_github.py'
57--- locolander/repos/tests/test_github.py 2013-07-06 22:26:19 +0000
58+++ locolander/repos/tests/test_github.py 2013-07-13 19:29:25 +0000
59@@ -25,12 +25,12 @@
60 class FakePullRequest(object):
61 """Fake GitHub pull request."""
62
63- def __init__(self, status=None, is_approved=False):
64+ def __init__(self, base, head, status=None, is_approved=False):
65 self.is_approved = is_approved
66 self.status = status
67 self.created_at = datetime.now()
68- self.base = FakeRepo()
69- self.head = FakeRepo()
70+ self.base = FakeRepo(name=base)
71+ self.head = FakeRepo(name=head)
72
73 def iter_issue_comments(self):
74 is_collaborator = self.is_approved
75@@ -42,8 +42,10 @@
76 class FakeRepo(object):
77 """Fake GitHub project repo."""
78
79- def __init__(self, is_approved=False):
80+ def __init__(self, name, is_approved=False):
81+ self.name = name
82 self.is_approved = is_approved
83+ self.repo = ('user', self.name)
84 self.ref = 'master'
85 self.status = 'no-approved'
86 if is_approved:
87@@ -51,10 +53,11 @@
88
89 def iter_pulls(self, state):
90 if self.is_approved:
91- pulls = [FakePullRequest(),
92- FakePullRequest(status='approved', is_approved=True)]
93+ pulls = [FakePullRequest('source', self.name),
94+ FakePullRequest('source', self.name,
95+ status='approved', is_approved=True)]
96 else:
97- pulls = [FakePullRequest()]
98+ pulls = [FakePullRequest('source', self.name)]
99 return pulls
100
101 def is_collaborator(self, username):
102@@ -67,8 +70,8 @@
103 def __init__(self):
104 self.data = {}
105 repos = {
106- 'test-repo': FakeRepo(is_approved=True),
107- 'another-repo': FakeRepo(),
108+ 'test-repo': FakeRepo(name='test-repo', is_approved=True),
109+ 'another-repo': FakeRepo(name='another-repo'),
110 }
111 self.data['test-user'] = repos
112
113@@ -116,3 +119,15 @@
114 for key in expected_keys:
115 self.assertIn(key, mp)
116 self.assertEqual(mp['commit_message'], 'commit msg')
117+
118+ def test_approved_mp_source_target(self):
119+ mps = self.gh.approved_requests_for_project_url(
120+ 'git@github.com:test-user/test-repo.git')
121+ self.assertEqual(len(mps), 1)
122+ mp = mps[0]
123+
124+ self.assertIsInstance(mp, dict)
125+ self.assertEqual(
126+ mp['source'], 'https://github.com/user/source.git master')
127+ self.assertEqual(
128+ mp['target'], 'https://github.com/user/test-repo.git master')

Subscribers

People subscribed via source and target branches

to all changes: