Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scheduled CI workflow to detect and fix the plugin entry issue #310

Open
unkcpz opened this issue Mar 20, 2024 · 0 comments
Open

Add scheduled CI workflow to detect and fix the plugin entry issue #310

unkcpz opened this issue Mar 20, 2024 · 0 comments
Assignees

Comments

@unkcpz
Copy link
Member

unkcpz commented Mar 20, 2024

ok updated, when converting to GHA, we don't need that uglyKEYcheck anymore. so i don't bring it here.

import yaml
import requests
from uglyKEYcheck import search_in_url

maindomain = "https://aiidateam.github.io/aiida-registry/"

def load_yaml_file(file_path):
    with open(file_path, 'r') as file:
        return yaml.safe_load(file)

def save_yaml_file(file_path, data):
    with open(file_path, 'w') as file:
        yaml.safe_dump(data, file, sort_keys=False)

def check_if_toml(url):
    new_url = '/'.join(url.split('/')[:-1]) + '/pyproject.toml'
    response = requests.head(new_url, timeout=10)
    if response.status_code == 404:
        return None
    else:
        return new_url

def check_urls(data):
    updates = False
    for plugin, info in data.items():
        url = info.get("plugin_info")
        if url:
            try:
                response = requests.get(url, allow_redirects=True)
                if response.status_code == 404:
                    new_url = check_if_toml(url)
                    if new_url:
                        print(f"{plugin}: returned a 404 status. But *pyproject.toml* detected!")
                        if search_in_url(maindomain+plugin, 'W002'):
                            data[plugin]["plugin_info"] = new_url
                            updates = True
                            print(plugin, ' updated')
                    else:
                        print(f"{plugin}: returned a 404 status. No *pyproject.toml* detected.")
                else:
                    pass
            except requests.RequestException as e:
                print(f"Error checking {plugin}: {url}. Error: {e}")
    return updates

yaml_file_path = 'plugins.yaml'

data = load_yaml_file(yaml_file_path)
if check_urls(data):
    save_yaml_file('plugins-out.yaml', data)
    print("YAML file updated.")

Originally posted by @khsrali in #309 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants