From 6c5bd0476787a53244cc6c0d06bf3cec7e8e2d8f Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Mon, 21 Oct 2024 15:18:22 +0100 Subject: [PATCH] Try making it all work --- lua/openingh/init.lua | 51 +++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/lua/openingh/init.lua b/lua/openingh/init.lua index 0a19c36..9532e79 100644 --- a/lua/openingh/init.lua +++ b/lua/openingh/init.lua @@ -1,6 +1,13 @@ -local remote_format = "%s/blob/%s%s" -local bb_remote_format = "%s/src/%s%s" -local forgejo_remote_format = "%s/src/%s%s" +local remote_format_file = "%s/blob/%s%s" +local bb_remote_format_file = "%s/src/%s%s" +local forgejo_remote_format_file = "%s/src/%s%s" + +local remote_format_branch = "%s/tree/%s" +local bb_remote_format_branch = "%s/branch/%s" +local bb_remote_format_commit = "%s/commits/%s" +local forgejo_remote_format_branch = "%s/src/branch/%s" +local forgejo_remote_format_commit = "%s/commit/%s" + local utils = require("openingh.utils") local M = {} @@ -23,9 +30,27 @@ function M.setup() end M.repo_url = string.format("http://%s/%s/%s", remote.host, remote.user_or_org, remote.reponame) + + if string.find(M.repo_url, "bitbucket") then + M.remote = M.remotes.BB + M.format_file = bb_remote_format_file + M.format_branch = bb_remote_format_branch + M.format_commit = bb_remote_format_commit + elseif string.find(M.repo_url, "forgejo") or string.find(M.repo_url, "gitea") then + M.remote = M.remotes.FORGEJO + M.format_file = forgejo_remote_format_file + M.format_branch = forgejo_remote_format_branch + M.format_commit = forgejo_remote_format_commit + else + M.remote = M.remotes.GH + M.format_file = remote_format_file + M.format_branch = remote_format_branch + M.format_commit = remote_format_branch + end end M.priority = { BRANCH = 1, COMMIT = 2 } +M.remotes = { GH = 1, BB = 2, FORGEJO = 3 } local function get_current_branch_or_commit_with_priority(priority) if priority == M.priority.BRANCH then @@ -66,18 +91,7 @@ function M.get_file_url( rev = branch end - local file_page_url = "" - - if string.find(M.repo_url, "bitbucket") then - file_page_url = string.format(bb_remote_format, M.repo_url, rev, file_path) - elseif string.find(M.repo_url, "forgejo") or string.find(M.repo_url, "gitea") then - print(M.repo_url) - print(rev) - print(file_path) - file_page_url = string.format(forgejo_remote_format, M.repo_url, rev, file_path) - else - file_page_url = string.format(remote_format, M.repo_url, rev, file_path) - end + local file_page_url = string.format(M.format_file, M.repo_url, rev, file_path) if range_start and not range_end then file_page_url = file_page_url .. "#L" .. range_start @@ -99,7 +113,12 @@ function M.get_repo_url(priority) return end - local url = M.repo_url .. "/tree/" .. get_current_branch_or_commit_with_priority(priority) + local url = "" + if priority == M.priority.BRANCH then + url = string.format(M.format_branch, M.repo_url, get_current_branch_or_commit_with_priority(priority)) + else + url = string.format(M.format_commit, M.repo_url, get_current_branch_or_commit_with_priority(priority)) + end return url end