Skip to content

Commit

Permalink
Onboarding issue test
Browse files Browse the repository at this point in the history
  • Loading branch information
clemensgg committed Dec 26, 2023
1 parent b2d1b25 commit 7dd5c53
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/operator_onboarding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Operator Onboarding
about: Use this template to onboard as an operator.
title: 'Operator Onboarding: [Your Name]'
labels: operator-onboarding
---

## IBC Path Selection
Please specify the IBC path (e.g., `cosmoshub-osmosis`) you want to be added to:
- IBC Path:

## Chain Account Information
Please provide your account information for each chain in the selected IBC path:
- Cosmoshub Account:
- [Other Chain] Account:

## Contact Information
Please provide at least one of the following for contact purposes:
- Discord Handle:
- Telegram Handle:
File renamed without changes.
35 changes: 35 additions & 0 deletions .github/workflows/operator_onboarding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Operator Onboarding

on:
issues:
types: [opened, edited]

jobs:
update-ibc-file:
runs-on: ubuntu-latest
outputs:
has_label: ${{ steps.label-check.outputs.has_label }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Check if issue has operator-onboarding label
id: label-check
run: |
LABEL=$(echo '${{ github.event.issue.labels }}' | jq -r '.[] | select(.name == "operator-onboarding").name')
if [ "$LABEL" == "operator-onboarding" ]; then
echo "::set-output name=has_label::true"
else
echo "::set-output name=has_label::false"
fi
- name: Update IBC file and create PR
if: steps.label-check.outputs.has_label == 'true'
run: python .github/scripts/update_ibc_file.py ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 65 additions & 0 deletions scripts/update_ibc_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import json
import sys
import requests

def get_issue_content(issue_number, token):
"""Fetch the content of the issue from GitHub."""
url = f"https://api.github.com/repos/{os.environ['GITHUB_REPOSITORY']}/issues/{issue_number}"
headers = {"Authorization": f"token {token}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
raise Exception(f"Failed to fetch issue content: {response.status_code}")

def parse_issue_content(issue_content):
"""Parse the issue content to extract necessary information."""
body = issue_content['body']
lines = body.split('\n')
data = {}
for line in lines:
if line.startswith('- '):
key, value = line[2:].split(':', 1)
data[key.strip()] = value.strip()
return data

def update_ibc_file(ibc_path, operator_data):
"""Update the respective JSON file in the _IBC folder."""
file_path = f'../_IBC/{ibc_path}.json'
with open(file_path, 'r') as file:
data = json.load(file)

# Determine which chain is 'cosmoshub'
cosmoshub_chain_key = 'chain_1' if data.get('chain_1', {}).get('chain_name', '') == 'cosmoshub' else \
'chain_2' if data.get('chain_2', {}).get('chain_name', '') == 'cosmoshub' else \
None

if cosmoshub_chain_key:
new_operator = {
cosmoshub_chain_key: {
"address": operator_data['Cosmoshub Account']
},
'memo': operator_data.get('Memo', ''),
'name': operator_data.get('Operator Name', ''),
'discord': {'handle': operator_data.get('Discord Handle', '')},
'telegram': {'handle': operator_data.get('Telegram Handle', '')}
}
data['operators'].append(new_operator)
else:
print(f"Cosmoshub chain not found in {ibc_path}.json")

with open(file_path, 'w') as file:
json.dump(data, file, indent=2)

def main():
issue_number = sys.argv[1]
token = os.environ['GITHUB_TOKEN']
issue_content = get_issue_content(issue_number, token)
operator_data = parse_issue_content(issue_content)
ibc_path = operator_data.pop('IBC Path')
update_ibc_file(ibc_path, operator_data)
print(f"Updated {ibc_path}.json with new operator data.")

if __name__ == "__main__":
main()

0 comments on commit 7dd5c53

Please sign in to comment.