From 57b842cad5745a1edee5af186c0f0e7726fbbc6b Mon Sep 17 00:00:00 2001
From: "Harrison (Harry) Cramer"
<32515581+harrisoncramer@users.noreply.github.com>
Date: Wed, 6 Sep 2023 20:25:54 -0400
Subject: [PATCH] Feat: Windows Support (#57)
This MR adds support for Windows machines
---
README.md | 3 +--
lua/gitlab/server.lua | 12 +++++++++---
lua/gitlab/utils/init.lua | 7 +++++++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 0201356..2eb1a7a 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,6 @@ https://github.com/harrisoncramer/gitlab.nvim/assets/32515581/ab5a8597-32fa-4a28
## Requirements
- Go >= v1.19
-- make (for install)
## Quick Start
@@ -63,7 +62,7 @@ use {
}
```
-## Configuration
+## Project Configuration
This plugin requires a `.gitlab.nvim` file in the root of the project. Provide this file with values required to connect to your gitlab instance of your repository (gitlab_url is optional, use ONLY for self-hosted instances):
diff --git a/lua/gitlab/server.lua b/lua/gitlab/server.lua
index 6d10857..a6ac5ce 100644
--- a/lua/gitlab/server.lua
+++ b/lua/gitlab/server.lua
@@ -46,15 +46,21 @@ M.build = function(override)
local file_path = u.current_file_path()
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h")
state.settings.bin_path = parent_dir
- state.settings.bin = parent_dir .. "/bin"
+ state.settings.bin = parent_dir .. (u.is_windows() and "\\bin.exe" or "/bin")
if not override then
local binary_exists = vim.loop.fs_stat(state.settings.bin)
if binary_exists ~= nil then return end
end
- local command = string.format("cd %s && make", state.settings.bin_path)
- local installCode = os.execute(command .. "> /dev/null")
+ local cmd = u.is_windows() and
+ 'cd cmd && go build -o bin.exe && move bin.exe ..\\' or
+ 'cd cmd && go build -o bin && mv bin ../bin'
+
+ local command = string.format(cmd, state.settings.bin_path)
+ local null = u.is_windows() and " >NUL" or " > /dev/null"
+ print(command .. null)
+ local installCode = os.execute(command .. null)
if installCode ~= 0 then
vim.notify("Could not install gitlab.nvim!", vim.log.levels.ERROR)
return false
diff --git a/lua/gitlab/utils/init.lua b/lua/gitlab/utils/init.lua
index ff6a49b..5a47593 100644
--- a/lua/gitlab/utils/init.lua
+++ b/lua/gitlab/utils/init.lua
@@ -19,6 +19,13 @@ M.has_reviewer = function(reviewer)
return has_reviewer
end
+M.is_windows = function()
+ if vim.fn.has("win32") == 1 or vim.fn.has("win32unix") == 1 then
+ return true
+ end
+ return false
+end
+
M.P = function(...)
local objects = {}
for i = 1, select("#", ...) do