Skip to content

Commit 80e41bd

Browse files
committed
github API interaction improved
1 parent 3f84149 commit 80e41bd

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

dvcurator/github.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ def search_existing(project_name, token=None, repo=None):
8181
token = {'Authorization': "token " + token.strip()}
8282
projects = requests.get(project_url + "?per_page=100", headers=token)
8383

84-
projects.raise_for_status()
84+
try:
85+
projects.raise_for_status()
86+
except requests.exceptions.HTTPError as http_err:
87+
print(f"HTTP error occurred: {http_err}")
88+
print(f"Response Content: {projects.content}")
89+
return True
90+
except Exception as err:
91+
print(f"Other error occurred: {err}")
92+
return True
8593

8694
# Take the first three words ("lastname - first-of-title") to search
8795
project_name = ' '.join(project_name.split()[:3])
@@ -113,30 +121,41 @@ def create_project(dv, project_name, token, repo=None):
113121
import requests, dvcurator.hosts, dvcurator.dataverse
114122
repo = dvcurator.hosts.curation_repo if not repo else repo
115123

116-
# if (search_existing(project_name, token, repo)):
117-
# print("Project already exists")
118-
# return
124+
if (search_existing(project_name, token, repo)):
125+
print("Error: Project already exists or search failed")
126+
return
119127

120-
# doi = dv['data']['latestVersion']['datasetPersistentId']
121-
# link = dvcurator.hosts.qdr_doi_path + doi
122-
# contact_info = 'Depositor: ' + dvcurator.dataverse.get_citation(dv)['depositor'] + '\n'
123-
# contact_info += 'DV link: ' + link
128+
doi = dv['data']['latestVersion']['datasetPersistentId']
129+
dataset_contact = dvcurator.dataverse.get_citation(dv)['datasetContact'][0]['datasetContactName']['value']
130+
link = dvcurator.hosts.qdr_doi_path + doi
131+
contact_info = 'Depositor: ' + dataset_contact + '\n'
132+
contact_info += 'DV link: ' + link
124133

134+
print(f"Project Name: {project_name}")
135+
print(f"Link: {link}")
136+
print(f"Contact Info: {contact_info}")
125137

126-
url = "https://api.github.com/repos/" + repo + "/dispatches"
138+
url = f"https://api.github.com/repos/{repo}/actions/workflows/new_project.yml/dispatches"
127139
headers = {
128-
"Accept": "application/vnd.github.everest-preview+json",
140+
"Accept": "application/vnd.github.v3+json",
129141
"Content-Type": "application/json",
142+
"X-GitHub-Api-Version": "2022-11-28",
130143
"Authorization": f"token {token}"
131144
}
132145
data = {
133-
"event_type": "trigger-event",
134-
"client_payload": {
146+
"ref": "master",
147+
"inputs": {
135148
"title": project_name,
136-
"desc": "Temporarily missing",
137-
"readme": "temporarilty missing"
149+
"desc": link,
150+
"readme": contact_info
138151
}
139152
}
140-
141-
response = requests.post(url, headers=headers, json=data)
142-
response.raise_for_status()
153+
154+
try:
155+
response = requests.post(url, headers=headers, json=data)
156+
response.raise_for_status()
157+
except requests.exceptions.HTTPError as http_err:
158+
print(f"HTTP error occurred: {http_err}")
159+
print(f"Response Content: {response.content}")
160+
except Exception as err:
161+
print(f"Other error occurred: {err}")

dvcurator/gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def download_extract(self):
229229

230230
def make_github(self):
231231
"""
232-
Run `generate_template()`
232+
Run `create_project()`
233233
"""
234234
if (not self.gh_token.get()):
235235
print("Error: no github token specified")
@@ -239,7 +239,7 @@ def make_github(self):
239239
self.disable_buttons()
240240

241241
t = threading.Thread(target=dvcurator.github.create_project,
242-
args=(self.project_name, self.gh_token.get(), self.curation_repo.get()))
242+
args=(self.metadata, self.project_name, self.gh_token.get(), self.curation_repo.get()))
243243

244244
t.start()
245245
self.schedule_check(t)

0 commit comments

Comments
 (0)