-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_utils.py
36 lines (29 loc) · 988 Bytes
/
github_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
GitHub utility helper function module.
"""
from github.Tag import Tag
def get_github_compatible_repo_address(full_url: str) -> str:
"""
Returns GitHub client compatible repository address.
The address returned can be used with official GitHub API client
to access the repository. It will be provided in the following
format: <company>/<repository>
"""
normalized = full_url.strip().lower()
if normalized.startswith("http"):
normalized = normalized.replace("http://", "").replace("https://", "")
if normalized.endswith(".git"):
normalized = normalized[:-4]
chunks = normalized.split("/")
return "/".join(chunks[1:])
def tag_to_text(tag: Tag) -> str:
"""
Creates a text representation of the tag.
:param tag: Tag object
:return: text representation of the tag
"""
return (
f"{tag.name}"
f" @ {tag.commit.commit.last_modified}"
f"by {tag.commit.commit.author.name}"
)