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

GitHub Action to update the modules Wiki #300

Open
DaveYesland opened this issue Aug 19, 2021 · 2 comments
Open

GitHub Action to update the modules Wiki #300

DaveYesland opened this issue Aug 19, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@DaveYesland
Copy link
Collaborator

When a new module is added or changed it would be nice to just run a GitHub Action that updates the module details section of the Pacu Wiki. Code is below on how this might be done.

import os
import importlib
from pathlib import Path
​
cat_set = set()
text_list = []
current_directory = os.getcwd()
for root, directories, files in os.walk(Path(__file__).parent/'pacu/modules'):
    modules_directory_path = os.path.realpath(Path(__file__).parent/'pacu/modules')
    specific_module_directory = os.path.realpath(root)
​
    # Skip any directories inside module directories.
    if os.path.dirname(specific_module_directory) != modules_directory_path:
        continue
    # Skip the root directory.
    elif modules_directory_path == specific_module_directory:
        continue
​
    module_name = os.path.basename(root)
​
    for file in files:
        if file == 'main.py':
            # Make sure the format is correct
            module_path = str(Path('pacu/modules')/module_name/'main').replace('/', '.').replace('\\', '.')
            # Import the help function from the module
            module = __import__(module_path, globals(), locals(), ['module_info'], 0)
            importlib.reload(module)
            cat_set.add(module.module_info['category'])
            text_list += [{"cat":module.module_info['category'],"text":f"### {module.module_info['name']}\n> **{module.module_info['one_liner']}**\n\n{module.module_info['description']}\n\n"}]
for cat in cat_set:
    print(f"## {cat}")
    for text in text_list:
        if text["cat"] == cat:
            print(text["text"])

This just prints out the MD formatted text with all the modules and descriptions to match the current wiki format.

@DaveYesland DaveYesland added the enhancement New feature or request label Aug 19, 2021
@RyanJarv
Copy link
Contributor

RyanJarv commented Sep 1, 2021

Note to self: One thing to look into though is if the token included during runs has the ability to make changes to the wiki.

@DaveYesland
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants