forked from jayrshah98/GITS2.1-I.R.I.S
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85e24aa
commit e9f3398
Showing
4 changed files
with
96 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
from typing import Dict | ||
import requests | ||
import json | ||
import requests | ||
import subprocess | ||
from urllib.parse import quote | ||
from get_github_owner_repo import get_github_owner_repo | ||
|
||
|
||
def get_file_at_version(path: str, sha: str, token: str) -> Dict[str, str]: | ||
instance = 'https://api.github.com' | ||
def get_file_at_version(path: str, sha: str) -> str: | ||
try: | ||
url = f'{instance}/repos/jwgerlach00/ml_protein_degradation_multitask/contents/{path}?ref={sha}' | ||
headers = {'Authorization': f'Bearer {token}'} | ||
|
||
response = requests.get(url, headers=headers) | ||
|
||
if response.status_code == 404: | ||
return '' | ||
|
||
contents = response.text | ||
return json.loads(content) | ||
|
||
except Exception as error: | ||
print(error) | ||
|
||
# token = 'YOUR-TOKEN-HERE' | ||
# sha = '470ae25' | ||
# path = 'package/src/linkerology_multitask/dataset_creation/LinkerologySampler.py' | ||
# get_file_at_version(path, sha, token) | ||
owner, repo = get_github_owner_repo() | ||
gh_cli_command = [ | ||
"gh", "api", f"repos/{owner}/{repo}/contents/{quote(path)}?ref={sha}", | ||
] | ||
output = subprocess.run( | ||
gh_cli_command, | ||
capture_output=True, | ||
text=True, | ||
check=True | ||
) | ||
output = output.stdout.strip() | ||
output = dict(json.loads(output)) | ||
download_url = output["download_url"] | ||
|
||
content = "" | ||
response = requests.get(download_url); | ||
if response.status_code == 200: | ||
content = response.text | ||
return content | ||
except subprocess.CalledProcessError: | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import subprocess | ||
|
||
def get_github_owner_repo(): | ||
try: | ||
output = subprocess.run( | ||
["git", "config", "--get", "remote.origin.url"], | ||
capture_output=True, | ||
text=True, | ||
check=True | ||
) | ||
origin_url = output.stdout.strip().split('/') | ||
owner = origin_url[-2] | ||
repo = origin_url[-1][0:-4] | ||
return owner, repo | ||
except subprocess.CalledProcessError: | ||
return "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters