Merge lp:~jelmer/brz/hoster-metadata into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/hoster-metadata
Merge into: lp:brz/3.1
Diff against target: 251 lines (+89/-27)
6 files modified
breezy/plugins/github/hoster.py (+8/-0)
breezy/plugins/gitlab/hoster.py (+8/-5)
breezy/plugins/launchpad/hoster.py (+12/-0)
breezy/plugins/propose/__init__.py (+1/-0)
breezy/plugins/propose/cmds.py (+28/-15)
breezy/propose.py (+32/-7)
To merge this branch: bzr merge lp:~jelmer/brz/hoster-metadata
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+388066@code.launchpad.net

Commit message

Add current user, profile url and name metadata to Hoster.

Description of the change

Add current user, profile url and name metadata to Hoster.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/plugins/github/hoster.py'
2--- breezy/plugins/github/hoster.py 2020-07-15 21:51:27 +0000
3+++ breezy/plugins/github/hoster.py 2020-07-24 17:49:00 +0000
4@@ -127,6 +127,8 @@
5 def __repr__(self):
6 return "<%s at %r>" % (type(self).__name__, self.url)
7
8+ name = 'GitHub'
9+
10 @property
11 def url(self):
12 return self._pr['html_url']
13@@ -563,6 +565,12 @@
14 return json.loads(response.text)
15 raise UnexpectedHttpStatus(path, response.status)
16
17+ def get_current_user(self):
18+ return self.current_user['login']
19+
20+ def get_user_url(self, username):
21+ return urlutils.join(self.base_url, username)
22+
23
24 class GitHubMergeProposalBuilder(MergeProposalBuilder):
25
26
27=== modified file 'breezy/plugins/gitlab/hoster.py'
28--- breezy/plugins/gitlab/hoster.py 2020-07-22 22:17:48 +0000
29+++ breezy/plugins/gitlab/hoster.py 2020-07-24 17:49:00 +0000
30@@ -395,9 +395,12 @@
31 project = self._get_project(project['path_with_namespace'])
32 return project
33
34- def _get_logged_in_username(self):
35+ def get_current_user(self):
36 return self._current_user['username']
37
38+ def get_user_url(self, username):
39+ return urlutils.join(self.base_url, username)
40+
41 def _list_paged(self, path, parameters=None, per_page=None):
42 if parameters is None:
43 parameters = {}
44@@ -497,7 +500,7 @@
45 allow_lossy=True, tag_selector=None):
46 (host, base_project, base_branch_name) = parse_gitlab_branch_url(base_branch)
47 if owner is None:
48- owner = self._get_logged_in_username()
49+ owner = self.get_current_user()
50 if project is None:
51 project = self._get_project(base_project)['path']
52 try:
53@@ -523,7 +526,7 @@
54 def get_derived_branch(self, base_branch, name, project=None, owner=None):
55 (host, base_project, base_branch_name) = parse_gitlab_branch_url(base_branch)
56 if owner is None:
57- owner = self._get_logged_in_username()
58+ owner = self.get_current_user()
59 if project is None:
60 project = self._get_project(base_project)['path']
61 try:
62@@ -599,11 +602,11 @@
63 def iter_my_proposals(self, status='open'):
64 state = mp_status_to_status(status)
65 for mp in self._list_merge_requests(
66- owner=self._get_logged_in_username(), state=state):
67+ owner=self.get_current_user(), state=state):
68 yield GitLabMergeProposal(self, mp)
69
70 def iter_my_forks(self):
71- for project in self._list_projects(owner=self._get_logged_in_username()):
72+ for project in self._list_projects(owner=self.get_current_user()):
73 base_project = project.get('forked_from_project')
74 if not base_project:
75 continue
76
77=== modified file 'breezy/plugins/launchpad/hoster.py'
78--- breezy/plugins/launchpad/hoster.py 2020-07-23 01:22:40 +0000
79+++ breezy/plugins/launchpad/hoster.py 2020-07-24 17:49:00 +0000
80@@ -229,6 +229,12 @@
81 self._launchpad = None
82
83 @property
84+ def name(self):
85+ if self._api_base_url == uris.LPNET_SERVICE_ROOT:
86+ return 'Launchpad'
87+ return 'Launchpad at %s' % self.base_url
88+
89+ @property
90 def launchpad(self):
91 if self._launchpad is None:
92 self._launchpad = lp_api.connect_launchpad(self._api_base_url, version='devel')
93@@ -241,6 +247,12 @@
94 def __repr__(self):
95 return "Launchpad(service_root=%s)" % self._api_base_url
96
97+ def get_current_user(self):
98+ return self.launchpad.me.name
99+
100+ def get_user_url(self, username):
101+ return self.launchpad.people[username].web_link
102+
103 def hosts(self, branch):
104 # TODO(jelmer): staging vs non-staging?
105 return plausible_launchpad_url(branch.user_url)
106
107=== modified file 'breezy/plugins/propose/__init__.py'
108--- breezy/plugins/propose/__init__.py 2020-06-01 21:28:34 +0000
109+++ breezy/plugins/propose/__init__.py 2020-07-24 17:49:00 +0000
110@@ -28,6 +28,7 @@
111 plugin_cmds.register_lazy(
112 "cmd_my_merge_proposals", ["my-proposals"],
113 __name__ + ".cmds")
114+plugin_cmds.register_lazy("cmd_hosters", [], __name__ + ".cmds")
115
116
117 def test_suite():
118
119=== modified file 'breezy/plugins/propose/cmds.py'
120--- breezy/plugins/propose/cmds.py 2020-06-21 02:15:25 +0000
121+++ breezy/plugins/propose/cmds.py 2020-07-24 17:49:00 +0000
122@@ -270,21 +270,20 @@
123 closed='Closed merge proposals')]
124
125 def run(self, status='open', verbose=False):
126- for name, hoster_cls in _mod_propose.hosters.items():
127- for instance in hoster_cls.iter_instances():
128- for mp in instance.iter_my_proposals(status=status):
129- self.outf.write('%s\n' % mp.url)
130- if verbose:
131- self.outf.write(
132- '(Merging %s into %s)\n' %
133- (mp.get_source_branch_url(),
134- mp.get_target_branch_url()))
135- description = mp.get_description()
136- if description:
137- self.outf.writelines(
138- ['\t%s\n' % l
139- for l in description.splitlines()])
140- self.outf.write('\n')
141+ for instance in _mod_propose.iter_hoster_instances():
142+ for mp in instance.iter_my_proposals(status=status):
143+ self.outf.write('%s\n' % mp.url)
144+ if verbose:
145+ self.outf.write(
146+ '(Merging %s into %s)\n' %
147+ (mp.get_source_branch_url(),
148+ mp.get_target_branch_url()))
149+ description = mp.get_description()
150+ if description:
151+ self.outf.writelines(
152+ ['\t%s\n' % l
153+ for l in description.splitlines()])
154+ self.outf.write('\n')
155
156
157 class cmd_land_merge_proposal(Command):
158@@ -297,3 +296,17 @@
159 def run(self, url, message=None):
160 proposal = _mod_propose.get_proposal_by_url(url)
161 proposal.merge(commit_message=message)
162+
163+
164+class cmd_hosters(Command):
165+ __doc__ = """List all known hosting sites and user details."""
166+
167+ hidden = True
168+
169+ def run(self):
170+ for instance in _mod_propose.iter_hoster_instances():
171+ current_user = instance.get_current_user()
172+ self.outf.write(
173+ gettext('%s (%s) - user: %s (%s)\n') % (
174+ instance.name, instance.base_url,
175+ current_user, instance.get_user_url(current_user)))
176
177=== modified file 'breezy/propose.py'
178--- breezy/propose.py 2020-06-18 03:08:00 +0000
179+++ breezy/propose.py 2020-07-24 17:49:00 +0000
180@@ -240,6 +240,11 @@
181 # proposals?
182 supports_merge_proposal_labels = None
183
184+ @property
185+ def name(self):
186+ """Name of this instance."""
187+ return "%s at %s" % (type(self).__name__, self.base_url)
188+
189 # Does this hoster support suggesting a commit message in the
190 # merge proposal?
191 supports_merge_proposal_commit_message = None
192@@ -266,7 +271,7 @@
193 :raise HosterLoginRequired: Action requires a hoster login, but none is
194 known.
195 """
196- raise NotImplementedError(self.publish)
197+ raise NotImplementedError(self.publish_derived)
198
199 def get_derived_branch(self, base_branch, name, project=None, owner=None):
200 """Get a derived branch ('a fork').
201@@ -354,6 +359,17 @@
202 """
203 raise NotImplementedError(cls.iter_instances)
204
205+ def get_current_user(self):
206+ """Retrieve the name of the currently logged in user.
207+
208+ :return: Username or None if not logged in
209+ """
210+ raise NotImplementedError(self.get_current_user)
211+
212+ def get_user_url(self, user):
213+ """Rerieve the web URL for a user."""
214+ raise NotImplementedError(self.get_user_url)
215+
216
217 def determine_title(description):
218 """Determine the title for a merge proposal based on full description."""
219@@ -384,6 +400,16 @@
220 raise UnsupportedHoster(branch)
221
222
223+def iter_hoster_instances():
224+ """Iterate over all known hoster instances.
225+
226+ :return: Iterator over Hoster instances
227+ """
228+ for name, hoster_cls in hosters.items():
229+ for instance in hoster_cls.iter_instances():
230+ yield instance
231+
232+
233 def get_proposal_by_url(url):
234 """Get the proposal object associated with a URL.
235
236@@ -391,12 +417,11 @@
237 :raise UnsupportedHoster: if there is no hoster that supports the URL
238 :return: A `MergeProposal` object
239 """
240- for name, hoster_cls in hosters.items():
241- for instance in hoster_cls.iter_instances():
242- try:
243- return instance.get_proposal_by_url(url)
244- except UnsupportedHoster:
245- pass
246+ for instance in iter_hoster_instances():
247+ try:
248+ return instance.get_proposal_by_url(url)
249+ except UnsupportedHoster:
250+ pass
251 raise UnsupportedHoster(url)
252
253

Subscribers

People subscribed via source and target branches