mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-10-08 14:54:36 +00:00
Merge pull request #379 from brostosjoined/main
Automate plugin metadata insertion
This commit is contained in:
commit
087c34e69b
2 changed files with 65 additions and 1 deletions
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
|
|
@ -40,6 +40,11 @@ jobs:
|
|||
with:
|
||||
commit_message: "[ci] auto-format"
|
||||
branch: ${{ github.head_ref }}
|
||||
- name: Apply Plugin Metadata
|
||||
run: |
|
||||
LAST_COMMIT_HASH=$(git log --pretty=format:'%H' -n 1)
|
||||
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "$LAST_COMMIT_HASH")
|
||||
python test/auto_apply_plugin_metadata.py "$CHANGED_FILES"
|
||||
|
||||
- name: Apply Version Metadata
|
||||
run: |
|
||||
|
|
|
|||
59
test/auto_apply_plugin_metadata.py
Normal file
59
test/auto_apply_plugin_metadata.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import ast
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def update_plugin_json(plugin_info, category):
|
||||
name = next(iter(plugin_info))
|
||||
details = plugin_info[name]
|
||||
|
||||
with open(f"plugins/{category}/{category}.json", 'r+') as file:
|
||||
data = json.load(file)
|
||||
try:
|
||||
# Check if plugin is already in the json
|
||||
plugin = data['plugins'][name]
|
||||
plugman_version = int(next(iter(data["plugins"][name]["versions"])).replace('.', ''))
|
||||
current_version = int(next(iter(details["versions"])).replace('.', ''))
|
||||
# `or` In case another change was made on the plugin while still on pr
|
||||
if current_version > plugman_version or current_version == plugman_version:
|
||||
plugin["versions"][next(iter(details["versions"]))] = None
|
||||
# Ensure latest version appears first
|
||||
plugin["versions"] = dict(sorted(plugin["versions"].items(), reverse=True))
|
||||
plugin["description"] = details["description"]
|
||||
plugin["external_url"] = details["external_url"]
|
||||
plugin["authors"] = details["authors"]
|
||||
elif current_version < plugman_version:
|
||||
raise Exception('Version cant be lower than the previous')
|
||||
except KeyError:
|
||||
data["plugins"][name] = details
|
||||
file.seek(0)
|
||||
json.dump(data, file, indent=2, ensure_ascii=False)
|
||||
# Ensure old content is removed
|
||||
file.truncate()
|
||||
|
||||
|
||||
def extract_ba_plugman(plugins: str) -> dict | list:
|
||||
for plugin in plugins:
|
||||
if "plugins/" in plugin:
|
||||
# Split the path and get the part after 'plugins/'
|
||||
parts = plugin.split("plugins/")[1].split("/")
|
||||
category = parts[0] # First part after plugins/
|
||||
|
||||
with open(plugin, "r") as f:
|
||||
tree = ast.parse(f.read())
|
||||
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Assign):
|
||||
# Check if the assignment matches our variable name
|
||||
if len(node.targets) == 1 and getattr(node.targets[0], "id", None) == 'ba_plugman':
|
||||
# Convert AST node to a Python object safely
|
||||
# return ast.literal_eval(node.value)
|
||||
update_plugin_json(ast.literal_eval(node.value), category)
|
||||
break
|
||||
else:
|
||||
raise ValueError(f"Variable ba_plugman not found.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
plugins = sys.argv
|
||||
extract_ba_plugman(plugins)
|
||||
Loading…
Add table
Add a link
Reference in a new issue