Skip to content

Commit

Permalink
feat: Use launchpadlib.uris.lookup_web_root
Browse files Browse the repository at this point in the history
There are more Launchpad instances besides production, qastaging, and
staging. Rely on `launchpadlib.uris.lookup_web_root` to map the short
instance names to web root URLs.

Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
  • Loading branch information
bdrung committed Oct 26, 2023
1 parent 7e62625 commit 2c9ccbb
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions apport/crashdb_impl/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from httplib2 import FailedToDecompressContent
from launchpadlib.errors import HTTPError, RestfulError
from launchpadlib.launchpad import Launchpad
from launchpadlib.uris import lookup_web_root
except ImportError:
# if launchpadlib is not available, only client-side reporting will work
Launchpad = None
Expand All @@ -41,6 +42,7 @@
import apport.report
from apport.packaging_impl import impl as packaging

DEFAULT_LAUNCHPAD_INSTANCE = "production"
default_credentials_path = os.path.expanduser("~/.cache/apport/launchpad.credentials")


Expand Down Expand Up @@ -153,7 +155,7 @@ def launchpad(self):
if self.options.get("launchpad_instance"):
launchpad_instance = self.options.get("launchpad_instance")
else:
launchpad_instance = "production"
launchpad_instance = DEFAULT_LAUNCHPAD_INSTANCE

Check warning on line 158 in apport/crashdb_impl/launchpad.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/launchpad.py#L158

Added line #L158 was not covered by tests

auth_dir = os.path.dirname(self.auth)
if auth_dir and not os.path.isdir(auth_dir):
Expand Down Expand Up @@ -222,19 +224,13 @@ def upload(self, report, progress_callback=None, user_message_callback=None):
assert ticket
return ticket

def get_hostname(self):
def get_hostname(self) -> str:
"""Return the hostname for the Launchpad instance."""
launchpad_instance = self.options.get("launchpad_instance")
if launchpad_instance:
if launchpad_instance == "qastaging":
hostname = "qastaging.launchpad.net"
elif launchpad_instance == "staging":
hostname = "staging.launchpad.net"
else:
hostname = "launchpad.dev"
else:
hostname = "launchpad.net"
return hostname
launchpad_instance = self.options.get(

Check warning on line 229 in apport/crashdb_impl/launchpad.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/launchpad.py#L229

Added line #L229 was not covered by tests
"launchpad_instance", DEFAULT_LAUNCHPAD_INSTANCE
)
url = urllib.parse.urlparse(lookup_web_root(launchpad_instance))
return url.netloc

Check warning on line 233 in apport/crashdb_impl/launchpad.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/launchpad.py#L232-L233

Added lines #L232 - L233 were not covered by tests

def get_comment_url(self, report, handle):
"""Return an URL that should be opened after report has been uploaded
Expand Down

0 comments on commit 2c9ccbb

Please sign in to comment.