Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add default merge method #489

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ require"octo".setup({
use_local_fs = false, -- use local files on right side of reviews
enable_builtin = false, -- shows a list of builtin actions when no action is provided
default_remote = {"upstream", "origin"}; -- order to try remotes
default_merge_method = "commit", -- default merge method which should be used when calling `Octo pr merge`, could be `commit`, `rebase` or `squash`
ssh_aliases = {}, -- SSH aliases. e.g. `ssh_aliases = {["github.com-work"] = "github.com"}`
picker = "telescope", -- or "fzf-lua"
picker_config = {
Expand Down
11 changes: 10 additions & 1 deletion lua/octo/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,9 @@ function M.pr_checks()
end

function M.merge_pr(...)
local conf = config.values
local defaultMergeMethod = conf.default_merge_method

local bufnr = vim.api.nvim_get_current_buf()
local buffer = octo_buffers[bufnr]
if not buffer or not buffer:isPullRequest() then
Expand All @@ -1121,7 +1124,13 @@ function M.merge_pr(...)
end
end
if not has_flag then
table.insert(args, "--merge")
if defaultMergeMethod == "squash" then
table.insert(args, "--squash")
elseif defaultMergeMethod == "rebase" then
table.insert(args, "--rebase")
else
table.insert(args, "--merge")
end
end
gh.run {
args = args,
Expand Down
3 changes: 3 additions & 0 deletions lua/octo/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ local M = {}
---@field picker OctoPickers
---@field picker_config OctoPickerConfig
---@field default_remote table
---@field default_merge_method string
---@field ssh_aliases {[string]:string}
---@field reaction_viewer_hint_icon string
---@field user_icon string
Expand Down Expand Up @@ -87,6 +88,7 @@ function M.get_default_values()
},
},
default_remote = { "upstream", "origin" },
default_merge_method = "commit",
ssh_aliases = {},
reaction_viewer_hint_icon = " ",
user_icon = " ",
Expand Down Expand Up @@ -390,6 +392,7 @@ function M.validate_config()
validate_type(v, "remote", "string")
end
end
validate_type(config.default_merge_method, "default_merge_method", "string")
if validate_type(config.ui, "ui", "table") then
validate_type(config.ui.use_signcolumn, "ui.use_signcolumn", "boolean")
end
Expand Down
2 changes: 2 additions & 0 deletions lua/tests/plenary/config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local eq = assert.are.same

local user_config = {
default_remote = { "remote1", "remote2" },
default_merge_method = "rebase",
file_panel = { use_icons = false },
ssh_aliases = {
["remote"] = "host",
Expand All @@ -28,6 +29,7 @@ describe("Config module:", function()
it("user configuration overrides defaults.", function()
eq(merged_config.default_remote[1], "remote1")
eq(merged_config.default_remote[2], "remote2")
eq(merged_config.default_merge_method, "rebase")
eq(merged_config.file_panel.size, 10, "file_panel.size should be 10")
eq(merged_config.file_panel.use_icons, false, "file_panel.use_icons should be false")
eq(merged_config.ssh_aliases["remote"], "host")
Expand Down
Loading