-
Notifications
You must be signed in to change notification settings - Fork 25
51 lines (41 loc) · 1.51 KB
/
update-citation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import requests
import yaml
# Repository details
repo_owner = os.getenv("GITHUB_REPOSITORY").split('/')[0]
repo_name = os.getenv("GITHUB_REPOSITORY").split('/')[1]
token = os.getenv("GITHUB_TOKEN")
# GitHub API URL
api_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contributors"
# Fetch contributors
response = requests.get(api_url, headers={"Authorization": f"token {token}"})
if response.status_code != 200:
raise Exception(f"Failed to fetch contributors: {response.json()}")
contributors = response.json()
# Extract contributor details
new_authors = []
for contributor in contributors:
new_authors.append({
"name": contributor.get("login"),
"orcid": None # ORCID integration can be added here
})
# Load existing CITATION.cff
citation_file = "CITATION.cff"
if os.path.exists(citation_file):
with open(citation_file, "r") as file:
citation_data = yaml.safe_load(file)
else:
citation_data = {
"cff-version": "1.2.0",
"message": "If you use this software, please cite it using this metadata.",
}
# Update authors
citation_data["authors"] = new_authors
# Optionally update other fields
citation_data["title"] = citation_data.get("title", repo_name)
citation_data["version"] = "1.0.0" # Update dynamically if needed
citation_data["date-released"] = "2024-11-29" # Update dynamically
# Write back to CITATION.cff
with open(citation_file, "w") as file:
yaml.dump(citation_data, file, sort_keys=False)
print("CITATION.cff updated successfully.")