Skip to content

Commit

Permalink
improv: openReferencedIssues on pushing commits, not committing itself
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Aug 17, 2024
1 parent 32beb3c commit efed57e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ require("tinygit").setup {
"perf", "style", "revert", "ci", "break", "improv",
},
},
openReferencedIssue = false, -- if message has issue/PR, open in browser afterwards
insertIssuesOnHash = {
-- Experimental. Typing `#` will insert the most recent open issue.
-- Requires nvim-notify.
Expand All @@ -342,6 +341,10 @@ require("tinygit").setup {
push = {
preventPushingFixupOrSquashCommits = true,
confirmationSound = true, -- currently macOS only, PRs welcome

-- Pushed commits contain references to issues, open those issues.
-- Not used when using force-push.
openReferencedIssues = false,
},
historySearch = {
diffPopup = {
Expand Down
14 changes: 0 additions & 14 deletions lua/tinygit/commands/commit-and-amend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,6 @@ local function closeNotifications()
end
end

---@param processedMsg string
local function openReferencedIssue(processedMsg)
local config = require("tinygit.config").config.commitMsg
local issueReferenced = processedMsg:match("#(%d+)")
if config.openReferencedIssue and issueReferenced then
local repo = require("tinygit.commands.github").getGithubRemote("silent")
if not repo then return end
local url = ("https://github.com/%s/issues/%s"):format(repo, issueReferenced)
vim.ui.open(url)
end
end

--------------------------------------------------------------------------------

---If there are staged changes, commit them.
Expand Down Expand Up @@ -416,7 +404,6 @@ function M.smartCommit(opts, msgNeedsFixing)
push({ pullBefore = opts.pullBeforePush }, true)
end

openReferencedIssue(processedMsg)
updateStatusline()
end)
end
Expand Down Expand Up @@ -493,7 +480,6 @@ function M.amendOnlyMsg(opts, msgNeedsFixing)
push({ forceWithLease = true }, true)
end

openReferencedIssue(processedMsg)
updateStatusline()
end
)
Expand Down
17 changes: 16 additions & 1 deletion lua/tinygit/commands/push-pull.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ local createGitHubPr = require("tinygit.commands.github").createGitHubPr
local updateStatusline = require("tinygit.statusline").updateAllComponents
--------------------------------------------------------------------------------

---@param commitRange string
local function openReferencedIssue(commitRange)
if not config.openReferencedIssues then return end

local repo = require("tinygit.commands.github").getGithubRemote("silent")
if not repo then return end

local pushedCommits = u.syncShellCmd { "git", "log", commitRange, "--format=%s" }
for issue in pushedCommits:gmatch("#(%d+)") do
local url = ("https://github.com/%s/issues/%s"):format(repo, issue)
vim.ui.open(url)
end
end

---@param opts { pullBefore?: boolean|nil, forceWithLease?: boolean, createGitHubPr?: boolean }
local function pushCmd(opts)
local gitCommand = { "git", "push" }
Expand All @@ -20,6 +34,8 @@ local function pushCmd(opts)
local severity = result.code == 0 and "info" or "error"
if severity == "info" then
local commitRange = out:match("%x+%.%.%x+")
if not opts.forceWithLease then openReferencedIssue(commitRange) end

local numOfPushedCommits = u.syncShellCmd { "git", "rev-list", "--count", commitRange }
if numOfPushedCommits ~= "" then
local plural = numOfPushedCommits ~= "1" and "s" or ""
Expand All @@ -28,7 +44,6 @@ local function pushCmd(opts)
end
u.notify(out, severity, "Push")

-- sound
if config.confirmationSound and vim.uv.os_uname().sysname == "Darwin" then
local sound = result.code == 0
and "/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/siri/jbl_confirm.caf" -- codespell-ignore
Expand Down
12 changes: 11 additions & 1 deletion lua/tinygit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ local defaultConfig = {
"perf", "style", "revert", "ci", "break", "improv",
},
},
openReferencedIssue = false, -- if message has issue/PR, open in browser afterwards
insertIssuesOnHash = {
-- Experimental. Typing `#` will insert the most recent open issue.
-- Requires nvim-notify.
Expand All @@ -39,6 +38,10 @@ local defaultConfig = {
push = {
preventPushingFixupOrSquashCommits = true,
confirmationSound = true, -- currently macOS only, PRs welcome

-- Pushed commits contain references to issues, open those issues.
-- Not used when using force-push.
openReferencedIssues = false,
},
historySearch = {
diffPopup = {
Expand Down Expand Up @@ -93,6 +96,13 @@ function M.setupPlugin(userConfig)
local msg = ('Border type "none" is not supported, falling back to %q.'):format(fallback)
require("tinygit.shared.utils").notify(msg, "warn")
end

-- DEPRECATION
if M.config.commitMsg.openReferencedIssue ~= nil or M.config.push.openReferencedIssue ~= nil then
local msg = "`config.commitMsg.openReferencedIssue` is deprecated. "
.. "Use `config.push.openReferencedIssues` instead. (Note the plural-s.)"
require("tinygit.shared.utils").notify(msg, "warn")
end
end

--------------------------------------------------------------------------------
Expand Down

0 comments on commit efed57e

Please sign in to comment.