Replace url_contains function with the 'in' operator

Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
This commit is contained in:
Erik Oosting 2021-01-12 11:07:01 +01:00 committed by GitHub
parent 888312333b
commit 023c82475c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,14 +26,11 @@ def resolve_source(pkg: Dict, repo: str, url: str) -> str:
stripped = path.parts[4:]
if path.parts[3].endswith("source"):
def url_contains(host: str) -> bool:
return url.find(host) != -1
canonical_url = url
# if we want to add the option of specifying branches, we have to update this
if url_contains("github"):
if "github" in url:
canonical_url += "/blob/master/"
elif url_contains("gitlab"):
elif "gitlab" in url:
canonical_url += "/-/blob/master/"
attrPath = "/".join(stripped)
location = f"{canonical_url}{attrPath}"
@ -49,7 +46,7 @@ def resolve_source(pkg: Dict, repo: str, url: str) -> str:
attrPath = "/".join(stripped[1:])
location = f"{prefixes[stripped[0]]}{attrPath}"
return f"{location}#L{line}"
elif position is not None and position.find("nur-combined") > -1:
elif position is not None and "nur-combined" in position:
path_str, line = position.rsplit(":", 1)
stripped = path_str.partition(f"nur-combined/repos/{repo}")[2]
return f"{prefix}{stripped}#L{line}"