Make it work with bitbucket
Some checks failed
Tests / unit tests (push) Has been cancelled
lint with luacheck / Luacheck (push) Has been cancelled

This commit is contained in:
Maximilian Friedersdorff 2024-10-21 14:45:37 +01:00
parent 613c18967d
commit a0a5c6c360
2 changed files with 14 additions and 6 deletions

View file

@ -1,3 +1,5 @@
local remote_format = "%s/blob/%s/%s"
local bb_remote_format = "%s/src/%s/%s"
local utils = require("openingh.utils") local utils = require("openingh.utils")
local M = {} local M = {}
@ -12,14 +14,14 @@ function M.setup()
return return
end end
local gh = utils.parse_gh_remote(repo_url) local remote = utils.parse_remote(repo_url)
if gh == nil then if remote == nil then
print("Error parsing GitHub remote URL") print("Error parsing remote URL")
vim.g.openingh = false vim.g.openingh = false
return return
end end
M.repo_url = string.format("http://%s/%s/%s", gh.host, gh.user_or_org, gh.reponame) M.repo_url = string.format("http://%s/%s/%s", remote.host, remote.user_or_org, remote.reponame)
end end
M.priority = { BRANCH = 1, COMMIT = 2 } M.priority = { BRANCH = 1, COMMIT = 2 }
@ -63,7 +65,13 @@ function M.get_file_url(
rev = branch rev = branch
end end
local file_page_url = M.repo_url .. "/blob/" .. rev .. file_path 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)
else
file_page_url = string.format(remote_format, M.repo_url, rev, file_path)
end
if range_start and not range_end then if range_start and not range_end then
file_page_url = file_page_url .. "#L" .. range_start file_page_url = file_page_url .. "#L" .. range_start

View file

@ -32,7 +32,7 @@ end
-- returns a table with the host, user/org and the reponame given a github remote url -- returns a table with the host, user/org and the reponame given a github remote url
-- nil is returned when the url cannot be parsed -- nil is returned when the url cannot be parsed
function M.parse_gh_remote(url) function M.parse_remote(url)
-- 3 capture groups for host, org/user and repo. whitespace is trimmed -- 3 capture groups for host, org/user and repo. whitespace is trimmed
-- when cloning with http://, gh redirects to https://, but remote stays http -- when cloning with http://, gh redirects to https://, but remote stays http
local http = { string.find(url, "https?://([^/]*)/([^/]*)/([^%s/]*)") } local http = { string.find(url, "https?://([^/]*)/([^/]*)/([^%s/]*)") }