Skip to content

Commit 6d87d5b

Browse files
committed
improve health check, add default_branch option
1 parent de87ffc commit 6d87d5b

4 files changed

Lines changed: 96 additions & 18 deletions

File tree

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Create GitHub Release
18+
uses: softprops/action-gh-release@v2
19+
with:
20+
generate_release_notes: true
21+
22+
- name: Update stable tag
23+
uses: rickstaa/action-create-tag@v1
24+
with:
25+
tag: stable
26+
message: "Latest stable release: ${{ github.ref_name }}"
27+
force_push_tag: true

lua/browsher/git.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ function M.get_current_branch_or_commit()
9898
return nil
9999
end
100100

101+
if config.options.default_branch then
102+
return config.options.default_branch, "branch"
103+
end
104+
101105
local output = run_git_command("symbolic-ref --short HEAD", git_root)
102106
if output and output[1] ~= "" then
103107
return output[1], "branch"

lua/browsher/health.lua

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,83 @@ function M.check()
66
local ok = health.ok or health.report_ok
77
local warn = health.warn or health.report_warn
88
local error = health.error or health.report_error
9+
local info = health.info or health.report_info
910

1011
start("browsher.nvim")
1112

13+
local version = require("browsher.version")
14+
info("{browsher.nvim} version `" .. version .. "`")
15+
1216
if vim.fn.executable("git") ~= 1 then
13-
error("Git is not installed or not in PATH.")
17+
error("{git} is not installed or not in PATH")
1418
else
15-
ok("Git is installed.")
19+
local git_version = vim.fn.system("git --version"):match("git version ([%d%.]+)")
20+
ok("{git} version `" .. (git_version or "unknown") .. "`")
21+
end
22+
23+
local git_root = vim.fn.systemlist("git rev-parse --show-toplevel 2>/dev/null")[1]
24+
if vim.v.shell_error ~= 0 or not git_root then
25+
info("not inside a Git repository")
26+
else
27+
ok("inside Git repository `" .. git_root .. "`")
28+
29+
local remotes = vim.fn.systemlist("git remote")
30+
if #remotes == 0 then
31+
warn("no remotes configured in this repository")
32+
else
33+
ok("remote(s) available: `" .. table.concat(remotes, "`, `") .. "`")
34+
35+
local config = require("browsher.config")
36+
local url_builder = require("browsher.url")
37+
local default_remote = config.options.default_remote or remotes[1]
38+
local remote_url = vim.fn.systemlist("git config --get remote." .. default_remote .. ".url")[1]
39+
40+
if remote_url then
41+
local sanitized = url_builder.sanitize_remote_url(remote_url)
42+
local provider_found = false
43+
for provider, _ in pairs(config.options.providers) do
44+
if sanitized:match(provider) then
45+
ok("provider matched: {" .. provider .. "}")
46+
provider_found = true
47+
break
48+
end
49+
end
50+
if not provider_found then
51+
warn("no provider configured for `" .. sanitized .. "`")
52+
info("add a custom provider in your config for this remote")
53+
end
54+
end
55+
end
1656
end
1757

1858
local open_cmd = require("browsher.config").options.open_cmd
1959
if open_cmd then
2060
local cmd = type(open_cmd) == "string" and open_cmd or open_cmd[1]
21-
if vim.fn.executable(cmd) ~= 1 then
22-
error(string.format("Configured open_cmd '%s' is not executable.", cmd))
61+
if string.len(cmd) == 1 then
62+
ok("configured to copy URL to `" .. cmd .. "` register")
63+
elseif vim.fn.executable(cmd) ~= 1 then
64+
error("{" .. cmd .. "} is not executable")
2365
else
24-
ok(string.format("Configured open_cmd '%s' is executable.", cmd))
66+
ok("{" .. cmd .. "} is executable")
2567
end
2668
else
27-
local has_open_cmd = false
28-
if vim.fn.has("unix") == 1 and vim.fn.executable("xdg-open") == 1 then
29-
ok("xdg-open is available.")
30-
has_open_cmd = true
31-
elseif vim.fn.has("macunix") == 1 and vim.fn.executable("open") == 1 then
32-
ok("'open' command is available.")
33-
has_open_cmd = true
34-
elseif vim.fn.has("win32") == 1 then
35-
ok("Windows detected. 'explorer.exe' will be used.")
36-
has_open_cmd = true
37-
end
38-
if not has_open_cmd then
39-
warn("No suitable command found to open URLs. Set 'open_cmd' in configuration.")
69+
local os_name = vim.loop.os_uname().sysname
70+
if os_name == "Linux" then
71+
if vim.fn.executable("xdg-open") == 1 then
72+
ok("{xdg-open} is available")
73+
else
74+
warn("{xdg-open} is not available, set `open_cmd` in configuration")
75+
end
76+
elseif os_name == "Darwin" then
77+
if vim.fn.executable("open") == 1 then
78+
ok("{open} is available")
79+
else
80+
warn("{open} is not available, set `open_cmd` in configuration")
81+
end
82+
elseif os_name == "Windows_NT" then
83+
ok("Windows detected, {explorer.exe} will be used")
84+
else
85+
warn("unknown OS, set `open_cmd` in configuration")
4086
end
4187
end
4288
end

lua/browsher/version.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
return "0.1.3"

0 commit comments

Comments
 (0)