|
45 | 45 |
|
46 | 46 |
|
47 | 47 | 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 | + """ |
48 | 52 | try: |
49 | 53 | response = requests.head(url, timeout=timeout) |
50 | 54 | response.raise_for_status() |
@@ -183,14 +187,18 @@ def clone_repository(repo_url, clone_path, logger, shallow_clone=True): |
183 | 187 |
|
184 | 188 |
|
185 | 189 | def get_github_org(url): |
186 | | - """Return Org username from GitHub account URL.""" |
| 190 | + """Return org username from GitHub account URL.""" |
187 | 191 | github_account_url = urlparse(url) |
188 | 192 | path_after_domain = github_account_url.path.lstrip("/") |
189 | 193 | org_name = path_after_domain.split("/")[0] |
190 | 194 | return org_name |
191 | 195 |
|
192 | 196 |
|
193 | 197 | 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 | + """ |
194 | 202 | account_url = settings.FEDERATEDCODE_GIT_ACCOUNT_URL |
195 | 203 | repo_url = urljoin(account_url, repo_name) |
196 | 204 | headers = { |
@@ -222,6 +230,15 @@ def create_repository(repo_name, clone_path, logger, shallow_clone=True): |
222 | 230 |
|
223 | 231 |
|
224 | 232 | 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 | + """ |
225 | 242 | repo_url = urljoin(settings.FEDERATEDCODE_GIT_ACCOUNT_URL, repo_name) |
226 | 243 | clone_path = working_path / repo_name |
227 | 244 |
|
|
0 commit comments