Skip to content

Commit b5fc0af

Browse files
committed
Add docstring to repo initialization utilities
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 9f97451 commit b5fc0af

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

scanpipe/pipes/federatedcode.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545

4646

4747
def url_exists(url, timeout=5):
48+
"""
49+
Check if the given `url` is reachable by doing head request.
50+
Return True if response status is 200, else False.
51+
"""
4852
try:
4953
response = requests.head(url, timeout=timeout)
5054
response.raise_for_status()
@@ -183,14 +187,18 @@ def clone_repository(repo_url, clone_path, logger, shallow_clone=True):
183187

184188

185189
def get_github_org(url):
186-
"""Return Org username from GitHub account URL."""
190+
"""Return org username from GitHub account URL."""
187191
github_account_url = urlparse(url)
188192
path_after_domain = github_account_url.path.lstrip("/")
189193
org_name = path_after_domain.split("/")[0]
190194
return org_name
191195

192196

193197
def create_repository(repo_name, clone_path, logger, shallow_clone=True):
198+
"""
199+
Create and initialize remote FederatedCode `repo_name` repository,
200+
perform local checkout, and return it.
201+
"""
194202
account_url = settings.FEDERATEDCODE_GIT_ACCOUNT_URL
195203
repo_url = urljoin(account_url, repo_name)
196204
headers = {
@@ -222,6 +230,15 @@ def create_repository(repo_name, clone_path, logger, shallow_clone=True):
222230

223231

224232
def get_or_create_repository(repo_name, working_path, logger, shallow_clone=True):
233+
"""
234+
Return local checkout of the FederatedCode `repo_name` repository.
235+
236+
- If local checkout for `repo_name` already exists in `working_path`, return it.
237+
- If no local checkout exists but the remote repository `repo_name` exists,
238+
clone it locally and return the checkout.
239+
- If the remote repository does not exist, create and initialize `repo_name`
240+
repository, perform local checkout, and return it.
241+
"""
225242
repo_url = urljoin(settings.FEDERATEDCODE_GIT_ACCOUNT_URL, repo_name)
226243
clone_path = working_path / repo_name
227244

0 commit comments

Comments
 (0)