@@ -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 } " )
0 commit comments