-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issues, Templates, and Action scripts update (#49)
- Loading branch information
Showing
16 changed files
with
2,323 additions
and
1,501 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,39 @@ | ||
--- | ||
name: Add Institution | ||
about: Adding a new institution | ||
title: 'New Institution' | ||
labels: 'add_institution' | ||
assignees: '' | ||
|
||
--- | ||
|
||
# New Institution Request | ||
|
||
To request a new item please ammend the following template below to reflect the items you are interested in. | ||
Conditions on naming conventions and permissable items can be found on the (WIKI)[https://wiki.mipcvs.dev/CMIP6Plus/Rules/institution/] and relevant github page | ||
|
||
<!--- info | ||
We are trialing the addition of new components using the configuration file format. | ||
To use this please fill out the template below keeping the spacing and indentation of the file. | ||
---> | ||
|
||
## Content | ||
|
||
**NOTE** Please review the rules provided in https://wiki.mipcvs.dev/CMIP6Plus/Rules/institution/ before completing this form. Submission of this is an acceptance of any terms outlined in the referenced document at the time. | ||
|
||
To get an institutions ROR code we can see if it exists on ror.org. For the entry below, we have the page: https://ror.org/000fg4e24 | ||
|
||
|
||
|
||
``` configfile | ||
[institutions] | ||
Acronym = "CMIP-IPO" | ||
Full_Name = "Coupled Model Intercomparison Project: International Project Office" | ||
ROR = "000fg4e24" | ||
``` | ||
|
||
|
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,39 @@ | ||
--- | ||
name: Add Consortium | ||
about: Adding a new consortium | ||
title: 'New Consortium' | ||
labels: 'add_consortium' | ||
assignees: '' | ||
|
||
--- | ||
|
||
# Add Consortium Template | ||
|
||
To request a new item please ammend the following template below to reflect the items you are interested in. | ||
Conditions on naming conventions and permissable items can be found on the WIKI and relevant github pages (links to be added. ) | ||
|
||
<!--- info | ||
We are trialing the addition of new components using the configuration file format. | ||
To use this please fill out the template below keeping the spacing and indentation of the file. | ||
---> | ||
|
||
## Contents (what we wish to add) | ||
|
||
|
||
``` configfile | ||
[consortium] | ||
Acronym = "CMIP" | ||
Name = "Coupled Model Intercomparison Project" | ||
[institutions] | ||
cmip6_acronyms = [ | ||
"CMIP-IPO", | ||
"WCRP" | ||
] | ||
``` | ||
|
||
|
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,17 @@ | ||
--- | ||
name: Other | ||
about: Creating a general issue | ||
title: 'Add a descriptive summary here.' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
# General Issue | ||
|
||
Please provided a detailed outline of the problem, discussion or suggestion. | ||
|
||
Make sure to provide the following where it might apply. | ||
|
||
- [ ] Any relevant files or code snippets | ||
- [ ] Where this occurs |
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,96 @@ | ||
|
||
import os,sys,json,ast | ||
import re,configparser | ||
from io import StringIO | ||
|
||
|
||
def parse_md(body): | ||
# remove comments | ||
pattern = r'<!---(.*?)--->' | ||
|
||
# Remove comments using re.sub | ||
body = re.sub(r'/r/n',r'/n', re.sub(pattern, '', body, flags=re.DOTALL)) | ||
|
||
|
||
config_str = re.search(r'```\sconfigfile(.*?)```',body, re.DOTALL).group(1) | ||
print(config_str) | ||
|
||
# Create a file-like object from the string | ||
config_file = StringIO(config_str) | ||
|
||
# Create a ConfigParser object | ||
config = configparser.ConfigParser() | ||
|
||
# Read configuration from the file-like object | ||
config.read_file(config_file) | ||
|
||
# Initialize an empty dictionary to hold the configuration data | ||
config_dict = {} | ||
|
||
# Iterate over sections and options | ||
for section in config.sections(): | ||
config_dict[section] = {} | ||
for option in config.options(section): | ||
config_dict[section][option] = ast.literal_eval(config.get(section, option)) | ||
|
||
return config_dict | ||
|
||
|
||
def dispatch(token,payload,repo): | ||
|
||
import json | ||
from urllib import request | ||
|
||
# Construct the request headers | ||
headers = { | ||
"Accept": "application/vnd.github.everest-preview+json", | ||
"Authorization": f"token {token}", | ||
"Content-Type": "application/json" | ||
} | ||
|
||
# Encode the payload | ||
datapayload = json.dumps(payload).encode('utf-8') | ||
|
||
# Make the POST request | ||
req = request.Request(f"{repo}/dispatches", data=datapayload, headers=headers, method='POST') | ||
|
||
# Perform the request | ||
try: | ||
with request.urlopen(req) as response: | ||
if response.getcode() == 204: | ||
print("Dispatch event triggered successfully.") | ||
else: | ||
print(f"Failed to trigger dispatch event. Status code: {response.getcode()}") | ||
print(response.read().decode('utf-8')) | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
|
||
|
||
def update_issue_title (issue_number,kind,payload): | ||
# change issue name to reflect contents. | ||
print(os.popen(f'gh issue edit {issue_number} --title "Add {kind}: {payload["client_payload"]["name"]}"').read()) | ||
|
||
|
||
def update_issue(issue_number,comment,err=True): | ||
out = os.popen(f'gh issue comment {issue_number} --body "{comment}"') | ||
if err: | ||
print(out) | ||
sys.exit(comment) | ||
|
||
def close_issue(issue_number, comment,err=True): | ||
print(os.popen(f'gh issue close {issue_number} -c "{comment}"')) | ||
if err: sys.exit(comment) | ||
|
||
def jr(file): | ||
return json.load(open(file,'r')) | ||
|
||
def jw(data,file): | ||
return json.dump(data,open(file,'w'), indent=4) | ||
|
||
def getfile(fileend): | ||
import glob | ||
return glob.glob(f'*{fileend}.json') | ||
|
||
def pp(js): | ||
import pprint | ||
pprint.pprint(js) |
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,50 @@ | ||
|
||
import json,sys,os,re | ||
|
||
# Add the current directory to the Python path | ||
# current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
# sys.path.append(current_dir) | ||
|
||
# Get the parent directory of the current file | ||
parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
sys.path.append(parent_dir) | ||
|
||
from action_functions import parse_md, dispatch, update_issue_title | ||
|
||
|
||
issue_number = os.environ.get('ISSUE_NUMBER') | ||
issue_title = os.environ.get('ISSUE_TITLE') | ||
issue_body = os.environ.get('ISSUE_BODY') | ||
issue_submitter = os.environ.get('ISSUE_SUBMITTER') | ||
repo = os.environ.get('REPO').replace('https://github.com','https://api.github.com/repos') | ||
token = os.environ.get('GH_TOKEN') | ||
|
||
|
||
parsed = parse_md(issue_body) | ||
|
||
|
||
''' | ||
Lets submit the data to a dispatch event | ||
''' | ||
|
||
|
||
data = parsed['consortium'] | ||
data['institutions'] = parsed['institutions']['cmip6_acronyms'] | ||
|
||
|
||
kind = __file__.split('/')[-1].replace('.py','') | ||
|
||
payload = { | ||
"event_type": kind, | ||
"client_payload": { | ||
"name": data['acronym'], # we need this to define the pull request | ||
"issue": issue_number, | ||
"author" : issue_submitter, | ||
"data" : json.dumps(data) | ||
} | ||
} | ||
|
||
update_issue_title(issue_number,kind,payload) | ||
|
||
dispatch(token,payload,repo) | ||
|
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,49 @@ | ||
|
||
import json,sys,os,re | ||
|
||
# Add the current directory to the Python path | ||
# current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
# sys.path.append(current_dir) | ||
|
||
# Get the parent directory of the current file | ||
parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
sys.path.append(parent_dir) | ||
|
||
from action_functions import parse_md, dispatch, update_issue_title | ||
|
||
|
||
issue_number = os.environ.get('ISSUE_NUMBER') | ||
issue_title = os.environ.get('ISSUE_TITLE') | ||
issue_body = os.environ.get('ISSUE_BODY') | ||
issue_submitter = os.environ.get('ISSUE_SUBMITTER') | ||
repo = os.environ.get('REPO').replace('https://github.com','https://api.github.com/repos') | ||
token = os.environ.get('GH_TOKEN') | ||
|
||
|
||
parsed = parse_md(issue_body) | ||
|
||
|
||
''' | ||
Lets submit the data to a dispatch event | ||
''' | ||
|
||
|
||
data = parsed['institutions'] | ||
|
||
|
||
kind = __file__.split('/')[-1].replace('.py','') | ||
|
||
payload = { | ||
"event_type": kind, | ||
"client_payload": { | ||
"name": data['acronym'], # we need this to define the pull request | ||
"issue": issue_number, | ||
"author" : issue_submitter, | ||
"data" : json.dumps(data) | ||
} | ||
} | ||
|
||
update_issue_title(issue_number,kind,payload) | ||
|
||
dispatch(token,payload,repo) | ||
|
File renamed without changes.
File renamed without changes.
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,61 @@ | ||
import json, os, sys | ||
from collections import OrderedDict | ||
|
||
# Get the parent directory of the current file | ||
parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
sys.path.append(parent_dir) | ||
|
||
from action_functions import update_issue,jr,jw,getfile,close_issue | ||
|
||
|
||
|
||
# data | ||
issue_number = os.environ['ISSUE'] | ||
data = os.environ['PAYLOAD_DATA'] | ||
data = json.loads(str(data)) | ||
|
||
|
||
# Load Existing | ||
consortiums = jr(getfile('consortiums')[0]) | ||
institutions = jr(getfile('institutions')[0])['institutions'] | ||
|
||
# Add new value and sort | ||
conly = consortiums["consortiums"] | ||
|
||
|
||
if data['acronym'] in conly: | ||
close_issue(issue_number,f'# Closing issue. \n {data["acronym"]} already exists in the consortium list. \n\n Please review request and resubmit.') | ||
|
||
error = '' | ||
inst = {} | ||
for i in data['institutions']: | ||
if i not in institutions: | ||
error += f' - Institution [{i}] does not exists in the institutions file. Please add this to proceed.\n' | ||
else: | ||
inst[i] = f"{i} [{institutions[i]['identifiers']['ror']} - {institutions[i]['identifiers']['institution_name']}]" | ||
|
||
if error: | ||
error = '#Error: \n Pausing submission. Please edit the initial config (above) addressing the issues below to try again. \n\n ' + error | ||
update_issue(issue_number,error) | ||
|
||
|
||
|
||
conly[data['acronym']] = {"name": data['name'], "contains": sorted(list(inst.values()))} | ||
|
||
sorted_consortiums = OrderedDict(sorted(conly.items())) | ||
|
||
|
||
# Update data | ||
data["consortiums"] = sorted_consortiums | ||
|
||
# Serialize back to JSON | ||
new_json_data = jw(data, getfile('consortiums')[0]) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.