From 626041469e73fda551cb4c98cf2f7d827d9dbd6a Mon Sep 17 00:00:00 2001 From: Daniel Jettka Date: Fri, 29 Nov 2024 08:45:51 +0100 Subject: [PATCH] update CITATION.cff workflow --- .github/scripts/update_citation.py | 51 +++++++++++++++++++++++++++ .github/workflows/update-citation.yml | 51 +++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .github/scripts/update_citation.py create mode 100644 .github/workflows/update-citation.yml diff --git a/.github/scripts/update_citation.py b/.github/scripts/update_citation.py new file mode 100644 index 000000000..efc7f8c19 --- /dev/null +++ b/.github/scripts/update_citation.py @@ -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.") diff --git a/.github/workflows/update-citation.yml b/.github/workflows/update-citation.yml new file mode 100644 index 000000000..efc7f8c19 --- /dev/null +++ b/.github/workflows/update-citation.yml @@ -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.")