Merge lp:~jelmer/brz/github-401s 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/github-401s
Merge into: lp:brz/3.1
Diff against target: 88 lines (+29/-20)
3 files modified
breezy/plugins/github/hoster.py (+9/-3)
breezy/plugins/propose/cmds.py (+17/-14)
breezy/transport/http/__init__.py (+3/-3)
To merge this branch: bzr merge lp:~jelmer/brz/github-401s
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+388429@code.launchpad.net

Commit message

Raise UnexpectedHttpStatus rather than InvalidHttpResponse.

Description of the change

Raise UnexpectedHttpStatus rather than InvalidHttpResponse.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

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-30 18:45:47 +0000
3+++ breezy/plugins/github/hoster.py 2020-07-30 21:38:23 +0000
4@@ -280,9 +280,15 @@
5 'Accept': 'application/vnd.github.v3+json'}
6 if self._token:
7 headers['Authorization'] = 'token %s' % self._token
8- response = self.transport.request(
9- method, urlutils.join(self.transport.base, path),
10- headers=headers, body=body, retries=3)
11+ try:
12+ response = self.transport.request(
13+ method, urlutils.join(self.transport.base, path),
14+ headers=headers, body=body, retries=3)
15+ except UnexpectedHttpStatus as e:
16+ if e.code == 401:
17+ raise GitHubLoginRequired(self)
18+ else:
19+ raise
20 if response.status == 401:
21 raise GitHubLoginRequired(self)
22 return response
23
24=== modified file 'breezy/plugins/propose/cmds.py'
25--- breezy/plugins/propose/cmds.py 2020-07-30 18:15:12 +0000
26+++ breezy/plugins/propose/cmds.py 2020-07-30 21:38:23 +0000
27@@ -37,7 +37,7 @@
28 RegistryOption,
29 )
30 from ...sixish import text_type
31-from ...trace import note
32+from ...trace import note, warning
33 from ... import (
34 propose as _mod_propose,
35 )
36@@ -271,19 +271,22 @@
37
38 def run(self, status='open', verbose=False):
39 for instance in _mod_propose.iter_hoster_instances():
40- for mp in instance.iter_my_proposals(status=status):
41- self.outf.write('%s\n' % mp.url)
42- if verbose:
43- self.outf.write(
44- '(Merging %s into %s)\n' %
45- (mp.get_source_branch_url(),
46- mp.get_target_branch_url()))
47- description = mp.get_description()
48- if description:
49- self.outf.writelines(
50- ['\t%s\n' % l
51- for l in description.splitlines()])
52- self.outf.write('\n')
53+ try:
54+ for mp in instance.iter_my_proposals(status=status):
55+ self.outf.write('%s\n' % mp.url)
56+ if verbose:
57+ self.outf.write(
58+ '(Merging %s into %s)\n' %
59+ (mp.get_source_branch_url(),
60+ mp.get_target_branch_url()))
61+ description = mp.get_description()
62+ if description:
63+ self.outf.writelines(
64+ ['\t%s\n' % l
65+ for l in description.splitlines()])
66+ self.outf.write('\n')
67+ except _mod_propose.HosterLoginRequired as e:
68+ warning('Skipping %r, login required.', instance)
69
70
71 class cmd_land_merge_proposal(Command):
72
73=== modified file 'breezy/transport/http/__init__.py'
74--- breezy/transport/http/__init__.py 2020-07-28 01:24:51 +0000
75+++ breezy/transport/http/__init__.py 2020-07-30 21:38:23 +0000
76@@ -1865,9 +1865,9 @@
77 'Server refuses to fulfill the request (403 Forbidden)'
78 ' for %s' % req.get_full_url())
79 else:
80- raise errors.InvalidHttpResponse(req.get_full_url(),
81- 'Unable to handle http code %d: %s'
82- % (code, msg))
83+ raise errors.UnexpectedHttpStatus(
84+ req.get_full_url(), code,
85+ 'Unable to handle http code: %s' % msg)
86
87
88 class Opener(object):

Subscribers

People subscribed via source and target branches