From ef91057cc94fd2fbe0e3fc75b5823eda3431fee1 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Dec 11 2019 12:26:32 +0000 Subject: PR#1821: browsable api Merges #1821 https://pagure.io/koji/pull-request/1821 Fixes: #1813 https://pagure.io/koji/issue/1813 [RFE] make API browsable in web ui --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index c1f4647..ed9a09d 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2346,10 +2346,7 @@ def anon_handle_list_api(goptions, session, args): if len(args) != 0: parser.error(_("This command takes no arguments")) activate_session(session, goptions) - tmplist = [(x['name'], x) for x in session._listapi()] - tmplist.sort() - funcs = [x[1] for x in tmplist] - for x in funcs: + for x in sorted(session._listapi(), key=lambda x: x['name']): if 'argdesc' in x: args = x['argdesc'] elif x['args']: diff --git a/www/kojiweb/api.chtml b/www/kojiweb/api.chtml new file mode 100644 index 0000000..291d584 --- /dev/null +++ b/www/kojiweb/api.chtml @@ -0,0 +1,15 @@ +#include "includes/header.chtml" + +

API reference

+ + + +#include "includes/footer.chtml" diff --git a/www/kojiweb/includes/header.chtml b/www/kojiweb/includes/header.chtml index d008f4e..421b3f1 100644 --- a/www/kojiweb/includes/header.chtml +++ b/www/kojiweb/includes/header.chtml @@ -74,6 +74,7 @@ $localnav
  • Hosts
  • Reports
  • Search
  • +
  • API
  • diff --git a/www/kojiweb/index.py b/www/kojiweb/index.py index b5880b6..b5ecd78 100644 --- a/www/kojiweb/index.py +++ b/www/kojiweb/index.py @@ -2344,6 +2344,16 @@ def search(environ, start=None, order=None): else: return _genHTML(environ, 'search.chtml') + +def api(environ): + values = _initValues(environ, 'API', 'api') + server = _getServer(environ) + + values['methods'] = sorted(server._listapi(), key=lambda x: x['name']) + + return _genHTML(environ, 'api.chtml') + + def watchlogs(environ, taskID): values = _initValues(environ) if isinstance(taskID, list): diff --git a/www/static/koji.css b/www/static/koji.css index 2f31138..aa0b912 100644 --- a/www/static/koji.css +++ b/www/static/koji.css @@ -146,7 +146,8 @@ body#users #mainNav li#usersTab a, body#hosts #mainNav li#hostsTab a, body#buildtargets #mainNav li#buildtargetsTab a, body#reports #mainNav li#reportsTab a, -body#search #mainNav li#searchTab a { +body#search #mainNav li#searchTab a, +body#api #mainNav li#apiTab a { background-color: #eee; color: #000; }