Skip to content

update CITATION.cff workflow #1

update CITATION.cff workflow

update CITATION.cff workflow #1

import os

Check failure on line 1 in .github/workflows/update-citation.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/update-citation.yml

Invalid workflow file

You have an error in your yaml syntax on line 1
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.")