Skip to content

Commit 0320bd8

Browse files
committed
feat: support forgejo URLs
1 parent e6b0882 commit 0320bd8

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ A map of domain names to forge software, used to generate commit and file URLs.
301301
- `github`
302302
- `gitlab`
303303
- `sourcehut`
304+
- `forgejo`
304305
- `azure`
305306
- `bitbucket`
306307

Diff for: lua/gitblame/config.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ M.default_opts = {
2020
remote_domains = {
2121
["git.sr.ht"] = "sourcehut",
2222
["dev.azure.com"] = "azure",
23-
["bitbucket.org"] = "bitbucket"
23+
["bitbucket.org"] = "bitbucket",
24+
["codeberg.org"] = "forgejo"
2425
}
2526
}
2627

Diff for: lua/gitblame/git.lua

+12-7
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,31 @@ local function get_repo_url(remote_url)
101101
end
102102

103103
---@param remote_url string
104-
---@param branch string
104+
---@param ref_type "commit"|"branch"
105+
---@param ref string
105106
---@param filepath string
106107
---@param line1 number?
107108
---@param line2 number?
108109
---@return string
109-
local function get_file_url(remote_url, branch, filepath, line1, line2)
110+
local function get_file_url(remote_url, ref_type, ref, filepath, line1, line2)
110111
local repo_url = get_repo_url(remote_url)
111112
local domain = get_http_domain(repo_url)
112113

113114
local forge = vim.g.gitblame_remote_domains[domain]
114115

115-
local file_path = "/blob/" .. branch .. "/" .. filepath
116+
local file_path = "/blob/" .. ref .. "/" .. filepath
116117
if forge == "sourcehut" then
117-
file_path = "/tree/" .. branch .. "/" .. filepath
118+
file_path = "/tree/" .. ref .. "/" .. filepath
119+
end
120+
if forge == "forgejo" then
121+
file_path = "/src/" .. ref_type .. "/" .. ref .. "/" .. filepath
118122
end
119123
if forge == "bitbucket" then
120124
file_path = "/src/" .. ref .. "/" .. filepath
121125
end
122126
if forge == "azure" then
123-
-- Can't use branch here since the URL wouldn't work in cases it's a commit sha
127+
-- Can't use ref here if it's a commit sha
128+
-- FIXME: add branch names to the URL
124129
file_path = "?path=%2F" .. filepath
125130
end
126131

@@ -190,13 +195,13 @@ function M.get_file_url(filepath, sha, line1, line2, callback)
190195
if sha == nil then
191196
get_current_branch(function(branch)
192197
M.get_remote_url(function(remote_url)
193-
local url = get_file_url(remote_url, branch, relative_filepath, line1, line2)
198+
local url = get_file_url(remote_url, "branch", branch, relative_filepath, line1, line2)
194199
callback(url)
195200
end)
196201
end)
197202
else
198203
M.get_remote_url(function(remote_url)
199-
local url = get_file_url(remote_url, sha, relative_filepath, line1, line2)
204+
local url = get_file_url(remote_url, "commit", sha, relative_filepath, line1, line2)
200205
callback(url)
201206
end)
202207
end

0 commit comments

Comments
 (0)