|
1 |
| -import re |
2 |
| -import subprocess |
3 |
| - |
4 | 1 | from typing import TYPE_CHECKING
|
5 | 2 | from typing import FrozenSet
|
6 | 3 | from typing import List
|
7 | 4 | from typing import Optional
|
8 |
| -from typing import Tuple |
9 | 5 | from typing import Union
|
10 | 6 |
|
11 |
| -from poetry.core.vcs import git |
12 |
| - |
13 | 7 | from .dependency import Dependency
|
14 | 8 |
|
15 | 9 |
|
16 | 10 | if TYPE_CHECKING:
|
17 | 11 | from .constraints import BaseConstraint
|
18 | 12 |
|
19 | 13 |
|
20 |
| -def extract_org_and_repo_name(parsed_url: git.ParsedUrl) -> Tuple[str, str]: |
21 |
| - repo_name = parsed_url.name |
22 |
| - if ":" not in parsed_url.pathname: |
23 |
| - # https |
24 |
| - org_name = parsed_url.pathname.split("/")[1] |
25 |
| - else: |
26 |
| - # ssh |
27 |
| - org_name = parsed_url.pathname.split("/")[0].replace(":", "") |
28 |
| - repo_name = repo_name.replace(".git", "") |
29 |
| - return org_name, repo_name |
30 |
| - |
31 |
| - |
32 |
| -def get_default_branch(org_name: str, repo_name: str) -> str: |
33 |
| - """ |
34 |
| - gets default branch based on the github api. |
35 |
| - """ |
36 |
| - curl_endpoint = "curl -s -H Accept: application/vnd.github.v3+json https://api.github.com/repos" |
37 |
| - cmd = "{}/{}/{} | grep default_branch".format(curl_endpoint, org_name, repo_name) |
38 |
| - ps = subprocess.Popen( |
39 |
| - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT |
40 |
| - ) |
41 |
| - output = ps.communicate()[0] |
42 |
| - decoded = output.decode("utf-8") |
43 |
| - output_decoded = decoded.split(":")[1] |
44 |
| - result = re.search('"(.*)"', output_decoded) |
45 |
| - return result.group(1) |
46 |
| - |
47 |
| - |
48 | 14 | class VCSDependency(Dependency):
|
49 | 15 | """
|
50 | 16 | Represents a VCS dependency
|
@@ -146,11 +112,6 @@ def base_pep_508_name(self) -> str:
|
146 | 112 | requirement += " @ {}+{}".format(self._vcs, self._source)
|
147 | 113 | else:
|
148 | 114 | requirement += " @ {}+ssh://{}".format(self._vcs, parsed_url.format())
|
149 |
| - |
150 |
| - org_name, repo_name = extract_org_and_repo_name(parsed_url) |
151 |
| - default_branch = get_default_branch(org_name=org_name, repo_name=repo_name) |
152 |
| - default_branch_str = "@{}".format(default_branch) |
153 |
| - requirement += default_branch_str |
154 | 115 | return requirement
|
155 | 116 | if parsed_url.protocol is not None:
|
156 | 117 | requirement += " @ {}+{}@{}".format(self._vcs, self._source, self.reference)
|
|
0 commit comments