Skip to content

Commit 8e36588

Browse files
committed
Webhook to generate metapackages for SpaceDock
1 parent 5b7e048 commit 8e36588

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

netkan/netkan/webhooks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .inflate import inflate
1212
from .spacedock_inflate import spacedock_inflate
1313
from .spacedock_add import spacedock_add
14+
from .spacedock_metapackage import spacedock_metapackage
1415
from .github_inflate import github_inflate
1516
from .github_mirror import github_mirror
1617

@@ -43,6 +44,7 @@ def create_app():
4344
app.register_blueprint(inflate)
4445
app.register_blueprint(spacedock_inflate, url_prefix='/sd')
4546
app.register_blueprint(spacedock_add, url_prefix='/sd')
47+
app.register_blueprint(spacedock_metapackage, url_prefix='/sd')
4648
app.register_blueprint(github_inflate, url_prefix='/gh')
4749
app.register_blueprint(github_mirror, url_prefix='/gh')
4850

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from pathlib import Path
2+
from flask import Blueprint, current_app, request, jsonify
3+
4+
from ..common import pull_all
5+
6+
7+
spacedock_metapackage = Blueprint('spacedock_metapackage', __name__) # pylint: disable=invalid-name
8+
9+
10+
# For metapackage hook on SpaceDock
11+
# Handles: https://netkan.ksp-ckan.space/sd/metapackage
12+
# POST form parameters:
13+
# mod_ids: The mods' ID numbers on SpaceDock
14+
@spacedock_metapackage.route('/metapackage', methods=['POST'])
15+
def metapackage_hook():
16+
# Make sure our NetKAN and CKAN-meta repos are up to date
17+
pull_all(current_app.config['repos'])
18+
# Get the relevant netkans
19+
sd_ids = request.form.getlist('mod_ids')
20+
nks = find_netkans(current_app.config['nk_repo'], sd_ids)
21+
if nks:
22+
return jsonify({
23+
'missing': not_found(sd_ids, nks),
24+
'metapackage': mk_metapackage(nks, request.form.get('name'), request.form.get('abstract')),
25+
}), 204
26+
return 'No such modules', 404
27+
28+
29+
def mk_metapackage(netkans, name, abstract):
30+
return {
31+
'spec_version': 'v1.4',
32+
'identifier': 'spacedock_metapackage',
33+
'name': name,
34+
'abstract': abstract,
35+
'kind': 'metapackage',
36+
'version': '1.0',
37+
'license': 'unknown',
38+
'depends': [{'name': nk.identifier} for nk in netkans]
39+
}
40+
41+
42+
def find_netkans(nk_repo, sd_ids):
43+
return [nk for nk in nk_repo.netkans()
44+
if nk.kref_src == 'spacedock' and nk.kref_id in sd_ids]
45+
46+
47+
def not_found(sd_ids, netkans):
48+
nk_ids = {nk.kref_id for nk in netkans}
49+
return [i for i in sd_ids if i not in nk_ids]

0 commit comments

Comments
 (0)