From 23a21b867b409f87fa82d6d4cc0c0be99aa92d19 Mon Sep 17 00:00:00 2001
From: "Harrison (Harry) Cramer"
<32515581+harrisoncramer@users.noreply.github.com>
Date: Fri, 30 Jun 2023 16:35:50 -0400
Subject: [PATCH] Removed notify as a dependency (#11)
Fixes: https://www.reddit.com/r/neovim/comments/14irqwt/comment/jphw2cx/?utm_source=share&utm_medium=web2x&context=3
---
README.md | 9 +--------
lua/gitlab/comment.lua | 7 +++----
lua/gitlab/discussions.lua | 7 +++----
lua/gitlab/init.lua | 9 ++++-----
lua/gitlab/job.lua | 19 +++++++++----------
lua/gitlab/utils/init.lua | 9 ++++-----
6 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/README.md b/README.md
index 571824b..e465c86 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,6 @@ https://user-images.githubusercontent.com/32515581/233739969-216dad6e-fa77-417f-
- Go
- nui.nvim
-- nvim-notify
- plenary.nvim
## Installation
@@ -31,14 +30,11 @@ Then install the plugin. Here's what it looks like with = 200 and data.status < 300) and "success" or "error"
if status == "error" then
- notify("Could not fetch discussions!", "error")
+ vim.notify("Could not fetch discussions!", vim.log.levels.ERROR)
return
end
M.discussions = data.discussions
@@ -88,7 +87,7 @@ M.list_discussions = function()
end
end,
on_stderr = function(_, output)
- notify("Could not run approve command!", "error")
+ vim.notify("Could not run approve command!", vim.log.levels.ERROR)
error(output)
end,
}):start()
diff --git a/lua/gitlab/init.lua b/lua/gitlab/init.lua
index f4b9b7e..2f943b5 100644
--- a/lua/gitlab/init.lua
+++ b/lua/gitlab/init.lua
@@ -1,6 +1,5 @@
local curl = require("plenary.curl")
local state = require("gitlab.state")
-local notify = require("notify")
local discussions = require("gitlab.discussions")
local summary = require("gitlab.summary")
local keymaps = require("gitlab.keymaps")
@@ -24,7 +23,7 @@ local function build_binary()
local command = string.format("cd %s && make", state.BIN_PATH)
local installCode = os.execute(command .. "> /dev/null")
if installCode ~= 0 then
- notify("Could not install gitlab.nvim!", "error")
+ vim.notify("Could not install gitlab.nvim!", vim.log.levels.ERROR)
return false
end
return true
@@ -71,19 +70,19 @@ M.setup = function(args)
vim.fn.jobstart(state.BIN .. " " .. state.PROJECT_ID .. " " .. state.PORT, {
on_stdout = function(job_id)
if job_id <= 0 then
- notify("Could not start gitlab.nvim binary", "error")
+ vim.notify("Could not start gitlab.nvim binary", vim.log.levels.ERROR)
return
else
local response_ok, response = pcall(curl.get, "localhost:" .. state.PORT .. "/info",
{ timeout = 750 })
if response == nil or not response_ok then
- notify("The gitlab.nvim server did not respond", "error")
+ vim.notify("The gitlab.nvim server did not respond", vim.log.levels.ERROR)
return
end
local body = response.body
local parsed_ok, data = pcall(vim.json.decode, body)
if parsed_ok ~= true then
- notify("The gitlab.nvim server returned an invalid response to the /info endpoint", "error")
+ vim.notify("The gitlab.nvim server returned an invalid response to the /info endpoint", vim.log.levels.ERROR)
return
end
state.INFO = data
diff --git a/lua/gitlab/job.lua b/lua/gitlab/job.lua
index 59623a6..0702be1 100644
--- a/lua/gitlab/job.lua
+++ b/lua/gitlab/job.lua
@@ -1,9 +1,8 @@
-local notify = require("notify")
-local Job = require("plenary.job")
-local state = require("gitlab.state")
-local M = {}
+local Job = require("plenary.job")
+local state = require("gitlab.state")
+local M = {}
-M.run_job = function(endpoint, method, body, callback)
+M.run_job = function(endpoint, method, body, callback)
local args = { "-s", "-X", (method or "POST"), string.format("localhost:%s/", state.PORT) .. endpoint }
if body ~= nil then
@@ -20,26 +19,26 @@ M.run_job = function(endpoint, method, body, callback)
if callback ~= nil then
callback(data)
else
- notify(data.message, status)
+ vim.notify(data.message, vim.log.levels.DEBUG)
end
else
- notify("Could not parse command output!", "error")
+ vim.notify("Could not parse command output!", vim.log.levels.ERROR)
end
end,
on_stderr = function(_, output)
- notify("Could not run command!", "error")
+ vim.notify("Could not run command!", vim.log.levels.ERROR)
error(output)
end
}):start()
end
-- Approves the current merge request
-M.approve = function()
+M.approve = function()
M.run_job("approve", "POST")
end
-- Revokes approval for the current merge request
-M.revoke = function()
+M.revoke = function()
M.run_job("revoke", "POST")
end
diff --git a/lua/gitlab/utils/init.lua b/lua/gitlab/utils/init.lua
index 2536c3f..d0000c6 100644
--- a/lua/gitlab/utils/init.lua
+++ b/lua/gitlab/utils/init.lua
@@ -1,5 +1,4 @@
local state = require("gitlab.state")
-local notify = require("notify")
local function get_git_root()
local output = vim.fn.system('git rev-parse --show-toplevel 2>/dev/null')
@@ -81,14 +80,14 @@ local base_invalid = function()
local current_branch = string.gsub(current_branch_raw, "\n", "")
if current_branch == "main" or current_branch == "master" then
- notify('On ' .. current_branch .. ' branch, no MRs available', "error")
+ vim.notify('On ' .. current_branch .. ' branch, no MRs available', vim.log.levels.ERROR)
return true
end
local base = state.BASE_BRANCH
local hasBaseBranch = feature_branch_exists(base)
if not hasBaseBranch then
- notify('No base branch. If this is a Gitlab repository, please check your setup function!', "error")
+ vim.notify('No base branch. If this is a Gitlab repository, please check your setup function!', vim.log.levels.ERROR)
return true
end
end
@@ -169,13 +168,13 @@ end
local function print_success(_, line)
if line ~= nil and line ~= "" then
- notify(line, "info")
+ vim.notify(line, vim.log.levels.INFO)
end
end
local function print_error(_, line)
if line ~= nil and line ~= "" then
- notify(line, "error")
+ vim.notify(line, vim.log.levels.ERROR)
end
end