From 7dd5c53481486433924c97673dbacca9585602ad Mon Sep 17 00:00:00 2001 From: clemensgg Date: Tue, 26 Dec 2023 15:04:52 +0100 Subject: [PATCH] Onboarding issue test --- .github/ISSUE_TEMPLATE/operator_onboarding.md | 20 ++++++ .../{onboarding.md => operator_onboarding.md} | 0 .github/workflows/operator_onboarding.yml | 35 ++++++++++ scripts/update_ibc_file.py | 65 +++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/operator_onboarding.md rename .github/PULL_REQUEST_TEMPLATE/{onboarding.md => operator_onboarding.md} (100%) create mode 100644 .github/workflows/operator_onboarding.yml create mode 100644 scripts/update_ibc_file.py diff --git a/.github/ISSUE_TEMPLATE/operator_onboarding.md b/.github/ISSUE_TEMPLATE/operator_onboarding.md new file mode 100644 index 0000000..f082c97 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/operator_onboarding.md @@ -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: \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE/onboarding.md b/.github/PULL_REQUEST_TEMPLATE/operator_onboarding.md similarity index 100% rename from .github/PULL_REQUEST_TEMPLATE/onboarding.md rename to .github/PULL_REQUEST_TEMPLATE/operator_onboarding.md diff --git a/.github/workflows/operator_onboarding.yml b/.github/workflows/operator_onboarding.yml new file mode 100644 index 0000000..3757bfc --- /dev/null +++ b/.github/workflows/operator_onboarding.yml @@ -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 }} diff --git a/scripts/update_ibc_file.py b/scripts/update_ibc_file.py new file mode 100644 index 0000000..93ff2fe --- /dev/null +++ b/scripts/update_ibc_file.py @@ -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()