Skip to content

Commit

Permalink
update CITATION.cff workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jettka committed Nov 29, 2024
1 parent 1c1514f commit 6260414
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/scripts/update_citation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.")
51 changes: 51 additions & 0 deletions .github/workflows/update-citation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.")

0 comments on commit 6260414

Please sign in to comment.