1313
1414
1515def extract_repo_name (repo : Repo , remote : str = "origin" ) -> str :
16+ """Extract the GitHub organization and repository name.
17+
18+ Assumes that the local repo has an appropriately configured remote named `origin`.
19+ """
1620 origin = repo .remote ("origin" )
1721 parsed_url = urlparse (origin .url )
1822 return parsed_url .path .rsplit (":" , 1 )[- 1 ].removesuffix (".git" )
1923
2024
2125def iter_blobs (item : Diff ) -> Generator [BlobDTO , None , None ]:
26+ """Iterate through diff items and produce blobs."""
2227 match (item .change_type ):
2328 case "A" :
2429 # File added
@@ -80,7 +85,17 @@ def iter_blobs(item: Diff) -> Generator[BlobDTO, None, None]:
8085
8186
8287def build_trees (blobs : list [BlobDTO ]) -> TreeDTO :
83- """Build the tree structure from a list of blobs."""
88+ """Build the tree structure from a list of blobs.
89+
90+ Technically, this function is not needed because the GitHub API supports
91+ creating a nested tree in a single operation (and we use this feature).
92+
93+ However, this API detail was not obvious from documentation so the original
94+ implementation created trees recursively and the DTOs still reflect this
95+ possibility. Since these DTOs are more-or-less faithful to git's own object
96+ model, removing the `Tree` structure would make the DTOs a bit less clear,
97+ even if it removed a step.
98+ """
8499 trees : dict [Path , TreeDTO ] = {}
85100
86101 # Create the root tree
@@ -108,6 +123,7 @@ def build_trees(blobs: list[BlobDTO]) -> TreeDTO:
108123
109124
110125def find_parent (commit : Commit ) -> Commit :
126+ """Find the parent of a commit."""
111127 if not commit .parents :
112128 raise ValueError ("Cannot create a repo's initial commit." )
113129
@@ -118,17 +134,20 @@ def find_parent(commit: Commit) -> Commit:
118134
119135
120136def extract_message (commit : Commit ) -> str :
137+ """Extract the commit message of a commit."""
121138 if isinstance (commit .message , str ):
122139 return commit .message
123140 else :
124141 return commit .message .decode ("utf-8" )
125142
126143
127144def read_repo (repo_path : Path ) -> Repo :
145+ """Read a repo from a path."""
128146 return Repo (repo_path )
129147
130148
131149def read_commit (repo : Repo , ref : str ) -> CommitDTO :
150+ """Read a local commit into a DTO representaiton."""
132151 # Find the commit at the given ref in the local repo.
133152 commit = repo .commit (ref )
134153
0 commit comments