-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathutils.lua
More file actions
35 lines (26 loc) · 896 Bytes
/
utils.lua
File metadata and controls
35 lines (26 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local M = {}
function M.safe_path(path)
return string.gsub(path, "/", "_")
end
function M.repo_path(repo, ref)
local x = M.safe_path(string.format("%s-%s", repo, ref or "HEAD"))
return x
end
function M.root_dir(fname)
if not fname or fname == "" then
fname = vim.fn.getcwd()
end
local matches = vim.fs.find({ "mix.exs" }, { upward = true, limit = 2, path = fname })
local child_or_root_path, maybe_umbrella_path = unpack(matches)
return vim.fs.dirname(maybe_umbrella_path or child_or_root_path)
end
function M.latest_release(owner, repo)
local curl = string.format(
[[curl --silent -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/%s/%s/releases/latest]],
owner,
repo
)
local resp = vim.json.decode(vim.fn.system(curl))
return resp and resp.tag_name:gsub("^v", "") or nil
end
return M