generated from ModelAtlasofTheEarth/mate-model-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bc52402
Showing
26 changed files
with
953 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
name: Publish model | ||
description: Update model with doi and publish | ||
title: "Publish model" | ||
labels: ["model published"] | ||
|
||
body: | ||
|
||
- type: input | ||
id: doi | ||
attributes: | ||
label: -> doi | ||
placeholder: "https://doi.org/10.47366/sabia.v5n1a3" | ||
description: "Provide the doi of your published model" | ||
validations: | ||
required: true |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
from github import Github, Auth | ||
|
||
# Environment variables | ||
token = os.environ.get("GITHUB_TOKEN") | ||
repo_name = os.environ.get("REPO_NAME") | ||
|
||
# Get repo | ||
auth = Auth.Token(token) | ||
g = Github(auth=auth) | ||
repo = g.get_repo(repo_name) | ||
|
||
# Find if any of the issues has the published label | ||
published = False | ||
|
||
for issue in repo.get_issues(): | ||
for label in issue.labels: | ||
if 'published' in label.name: | ||
published = True | ||
|
||
print(published) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import base64 | ||
from github import Github, Auth | ||
|
||
# Environment variables | ||
token = os.environ.get("GITHUB_TOKEN") | ||
source_repo_owner = os.environ.get("SOURCE_REPO_OWNER") | ||
source_repo_name = os.environ.get("SOURCE_REPO_NAME") | ||
source_path = os.environ.get("SOURCE_PATH") | ||
target_repo_owner = os.environ.get("TARGET_REPO_OWNER") | ||
target_repo_name = os.environ.get("TARGET_REPO_NAME") | ||
target_branch_name = os.environ.get("TARGET_REPO_BRANCH") | ||
target_path = os.environ.get("TARGET_PATH") | ||
|
||
auth = Auth.Token(token) | ||
g = Github(auth=auth) | ||
source_repo = g.get_repo(f"{source_repo_owner}/{source_repo_name}") | ||
target_repo = g.get_repo(f"{target_repo_owner}/{target_repo_name}") | ||
|
||
def copy_files(contents, target_path): | ||
for content in contents: | ||
if content.type == "dir": | ||
# Get the contents of the directory and copy recursively | ||
copy_files(source_repo.get_contents(content.path), f"{target_path}/{content.name}") | ||
else: | ||
# Check if the file already exists in the target repo | ||
try: | ||
target_file = target_repo.get_contents(f"{target_path}/{content.name}", ref=target_branch_name) | ||
# File exists, compare contents | ||
if content.sha != target_file.sha: | ||
# Contents differ, update the file | ||
source_file_content = base64.b64decode(source_repo.get_git_blob(content.sha).content) | ||
target_repo.update_file(f"{target_path}/{content.name}",f"Updating {content.name}", source_file_content, target_file.sha, branch=target_branch_name) | ||
except: | ||
# Copy file to target repository | ||
source_file_content = base64.b64decode(source_repo.get_git_blob(content.sha).content) | ||
target_repo.create_file(f"{target_path}/{content.name}", f"Copying {content.name}", source_file_content, branch=target_branch_name) | ||
|
||
# Get contents of source directory | ||
source_contents = source_repo.get_contents(source_path) | ||
|
||
# Start copying files | ||
copy_files(source_contents, target_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from github import Github, Auth | ||
|
||
# Environment variables | ||
token = os.environ.get("GITHUB_TOKEN") | ||
repo_owner = os.environ.get("REPO_OWNER") | ||
repo_name = os.environ.get("REPO_NAME") | ||
branch_name = os.environ.get("BRANCH_NAME") | ||
|
||
auth = Auth.Token(token) | ||
g = Github(auth=auth) | ||
repo = g.get_repo(f"{repo_owner}/{repo_name}") | ||
|
||
# Check if the branch name already exists | ||
try: | ||
assert repo.get_git_ref(f"heads/{branch_name}").ref is not None | ||
print("Branch already exists") | ||
|
||
# Create new branch if it doesn't | ||
except: | ||
base_ref = repo.get_git_ref(f"heads/{repo.default_branch}") | ||
|
||
repo.create_git_ref(f"refs/heads/{branch_name}", base_ref.object.sha) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import json | ||
from ruamel.yaml import YAML | ||
import csv | ||
import os | ||
from io import StringIO | ||
|
||
def create_or_update_json_entry(rocrate, keys_path, new_value): | ||
""" | ||
Create or update a nested JSON entry in a ro-crate structure. | ||
Args: | ||
rocrate (dict): The main ro-crate dictionary. | ||
keys_path (str): Dot-separated path to the key that needs updating. | ||
new_value (any): New value to be inserted or updated. | ||
""" | ||
# Split the keys path into individual components | ||
keys = keys_path.split('.') | ||
prefix = "" | ||
structure = rocrate | ||
|
||
# Traverse through the nested structure using keys except the last one | ||
for key in keys[:-1]: | ||
key = prefix + key | ||
|
||
# Handle potential './' prefix logic | ||
if key == "": | ||
prefix = "." | ||
continue | ||
else: | ||
prefix = "" | ||
|
||
if isinstance(structure, list): | ||
# Find the item with matching '@id' key | ||
for item in structure: | ||
if item.get("@id") == key: | ||
structure = item | ||
break | ||
else: | ||
print(f"Key '{key}' not found.") | ||
return | ||
elif key in structure: | ||
structure = structure[key] | ||
else: | ||
print(f"Key '{key}' not found.") | ||
return | ||
|
||
# The final key where the new value should be placed | ||
last_key = keys[-1] | ||
|
||
# Update the value at the final key | ||
if last_key in structure: | ||
if isinstance(structure[last_key], list): | ||
# Prepend only if the new value is not already in the list | ||
if new_value not in structure[last_key]: | ||
structure[last_key].insert(0, new_value) | ||
else: | ||
# Convert existing non-list value to a list if needed | ||
structure[last_key] = [new_value, structure[last_key]] | ||
else: | ||
# If the key doesn't exist, create a new list with the new value | ||
structure[last_key] = [new_value] | ||
|
||
|
||
def navigate_and_assign(source, path, value): | ||
"""Navigate through a nested dictionary and assign a value to the specified path.""" | ||
keys = path.split('.') | ||
for i, key in enumerate(keys[:-1]): | ||
if key.isdigit(): # If the key is a digit, it's an index for a list | ||
key = int(key) | ||
while len(source) <= key: # Extend the list if necessary | ||
source.append({}) | ||
source = source[key] | ||
else: | ||
if i < len(keys) - 2 and keys[i + 1].isdigit(): # Next key is a digit, so ensure this key leads to a list | ||
source = source.setdefault(key, []) | ||
else: # Otherwise, it leads to a dictionary | ||
source = source.setdefault(key, {}) | ||
# Assign the value to the final key | ||
if keys[-1].isdigit(): # If the final key is a digit, it's an index for a list | ||
key = int(keys[-1]) | ||
while len(source) <= key: # Extend the list if necessary | ||
source.append(None) | ||
source[key] = value | ||
else: | ||
source[keys[-1]] = value | ||
|
||
|
||
def read_yaml_with_header(file_path): | ||
""" | ||
Read YAML content inside YAML header delimiters '---' | ||
""" | ||
|
||
with open(file_path,'r') as file: | ||
data = file.read() | ||
|
||
yaml = YAML() | ||
yaml_content = yaml.load(data.strip('---\n')) | ||
|
||
return yaml_content | ||
|
||
def update_csv_content(file_path, field, value): | ||
# Read the CSV file and update the field value | ||
updated_rows = [] | ||
field_exists = False | ||
with open(file_path, mode='r', newline='') as file: | ||
reader = csv.reader(file) | ||
for row in reader: | ||
if row and row[0] == field: | ||
row[1] = value | ||
field_exists = True | ||
updated_rows.append(row) | ||
|
||
# If the field does not exist, add a new line | ||
if not field_exists: | ||
updated_rows.append([field, value]) | ||
|
||
# Convert the updated rows back into a CSV-formatted string | ||
updated_csv_content = StringIO() | ||
writer = csv.writer(updated_csv_content) | ||
writer.writerows(updated_rows) | ||
updated_csv_string = updated_csv_content.getvalue() | ||
|
||
return updated_csv_string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import json | ||
import requests | ||
from github import Github, Auth | ||
|
||
# Environment variables | ||
token = os.environ.get("TOKEN") | ||
repo_name = os.environ.get("REPO") | ||
org = os.environ.get("ORG") | ||
|
||
repos = [] | ||
|
||
# Get org | ||
auth = Auth.Token(token) | ||
g = Github(auth=auth) | ||
org = g.get_organization(org) | ||
|
||
# Find repos created from this template | ||
for repo in org.get_repos(): | ||
repo_json = requests.get(repo.url).json() | ||
if 'template_repository' in repo_json: | ||
if repo_json['template_repository']['name'] == repo_name: | ||
repos.append(repo.name) | ||
|
||
print(json.dumps(repos)) |
Oops, something went wrong.