Skip to content

Instantly share code, notes, and snippets.

@brews
Last active August 16, 2023 20:24
Show Gist options
  • Save brews/3d0df433066e8e9ea78dfc79ad8af3fb to your computer and use it in GitHub Desktop.
Save brews/3d0df433066e8e9ea78dfc79ad8af3fb to your computer and use it in GitHub Desktop.
Trigger a Zenodo DOI for past Github Releases on a public repo.
"""
Trigger a Zenodo DOI for past Github Releases on a public repo.
Modified from @medley56 https://github.com/zenodo/zenodo/issues/1463#issuecomment-1468932469 on 2023-08-16.
"""
import requests
# Fill these in...
repo = "put user/repo here"
token = "paste access token from webhook page in github repo here"
headers = {"Accept": "application/vnd.github.v3+json"}
repo_response = requests.get(f"https://api.github.com/repos/{repo}", headers=headers)
release_response = requests.get(
f"https://api.github.com/repos/{repo}/releases", headers=headers
)
releases = release_response.json()
releases.reverse() # Puts them in order from oldest to newest
for release in releases[3:]: # Publish all old releases
payload = {
"action": "published",
"release": release,
"repository": repo_response.json(),
}
submit_response = requests.post(
f"https://zenodo.org/api/hooks/receivers/github/events/?access_token={token}",
json=payload,
)
print(submit_response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment