-- app.lua -- Entry point for git HTTP site implementation -- Copyright (c) 2020 Joshua 'joshuas3' Stockin -- local lyaml = require("lyaml") local utils = require("utils") local git = require("git_commands") local request = require("request") local tabulate = require("tabulate") local html = require("html") local parsed_uri = request.parse_uri() local content if parsed_uri.repo == nil then -- home page, list of repositories else -- repo found local repo for _,r in pairs(yaml_config) do if parsed_uri.repo == r.name then repo = r break end end if repo then local repo_dir = repo.location.dev local view = parsed_uri.parts[2] or "tree" local branch if pcall(function() -- if branch is real branch = git.get_head(repo_dir, parsed_uri.parts[3]) -- if parts[3] is nil, defaults to "HEAD" end) then if view == "tree" then -- directory display (with automatic README rendering) -- /repo/tree/branch/[DIRECTORY PATH] local path = parsed_uri.parts table.remove(path, 3) -- branch table.remove(path, 2) -- "tree" table.remove(path, 1) -- repo if #path > 0 then path = table.concat(path, "/").."/" else path = "" end content = html.tree(repo, repo_dir, branch, path) elseif view == "blob" then -- /repo/blob/branch/[FILE PATH] elseif view == "raw" then -- /repo/raw/branch/[FILE PATH] elseif view == "log" then -- /repo/log/branch?n=[COMMITS PER PAGE]&skip=[COMMITS TO SKIP] content = html.log(repo, repo_dir, branch, 40, 0) elseif view == "refs" then content = html.refs(repo, repo_dir, branch) elseif view == "download" then content = html.download(repo, repo_dir, branch) elseif view == "commit" then -- /repo/commit/[COMMIT HASH] end end end end if content ~= nil then ngx.say([[]]) local arrow_left_circle = [[]] ngx.say(""..arrow_left_circle.."Index") ngx.say(content.body) ngx.exit(ngx.HTTP_OK) return else ngx.exit(ngx.HTTP_NOT_FOUND) -- default behavior return end