-
Notifications
You must be signed in to change notification settings - Fork 41
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 squash and removesourcebranch to createmrrequest #230
Feat add squash and removesourcebranch to createmrrequest #230
Conversation
Thank you for writing this MR! It looks very nice, I'll take a look this weekend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lua/gitlab/actions/create_mr.lua
Outdated
local delete_branch | ||
if mr.delete_branch ~= nil then | ||
delete_branch = mr.delete_branch | ||
else | ||
delete_branch = state.settings.create_mr.delete_branch | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types of statements can be converted into ternary style values in Lua which is a bit easier to read, in my opinion:
local delete_branch = mr.delete_branch ~= nil and mr.delete_branch or state.settings.create_mr.delete_branch
I'd change a variety of if/else statements in this MR to this style, it makes clear that this is just an assignment, eliminates variable shadowing, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually tried the way you suggest before, but the problem is that it does not work for Boolean values. If mr.delete_branch
is false
it's not able to override the default value state.settings.create_mr.delete_branch
if that is true
.
How about extracting the logic to a utils function like this:
---Get the first non-nil value in the input table or nil
---@param values table The list of input values
---@return any
M.get_first_non_nil_value = function(values)
for _, val in pairs(values) do
if val ~= nil then
return val
end
end
end
Then I'll be able to simplify my code to:
local delete_branch = u.get_first_non_nil_value({mr.delete_branch, state.settings.create_mr.delete_branch})
Which is quite explicit about what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, I wanted to add tests for this function in tests/spec/util_spec.lua
, but when running busted tests/spec/util_spec.lua
I get the following error, followed by all the errors resulting from gitlab.utils
not being loaded properly:
Failure → tests/spec/util_spec.lua @ 2
utils/init.lua Loads package
tests/spec/util_spec.lua:4: Expected objects to be the same.
Passed in:
(boolean) false
Expected:
(boolean) true
Could you please add information in .github/CONTRIBUTING.md
about how to run the tests?
I don't think this is correct. The diff --git a/README.md b/README.md
index 5801d69..b41ac71 100644
--- a/README.md
+++ b/README.md
@@ -201,10 +201,6 @@ require("gitlab").setup({
success = "✓",
failed = "<U+F467>",
},
- merge = { -- The default behaviors when merging an MR, see "Merging an MR"
- squash = false,
- delete_branch = false,
- },
create_mr = {
target = nil, -- Default branch to target when creating an MR
template_file = nil, -- Default MR template in .gitlab/merge_request_templates
diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt
index 2d7442f..b37b34f 100644
--- a/doc/gitlab.nvim.txt
+++ b/doc/gitlab.nvim.txt
@@ -230,10 +230,6 @@ you call this function with no values the defaults will be used:
success = "✓",
failed = "<U+F467>",
},
- merge = { -- The default behaviors when merging an MR, see "Merging an MR"
- squash = false,
- delete_branch = false,
- },
create_mr = {
target = nil, -- Default branch to target when creating an MR
template_file = nil, -- Default MR template in .gitlab/merge_request_templates
diff --git a/lua/gitlab/actions/merge.lua b/lua/gitlab/actions/merge.lua
index 324dc1e..b610c8e 100644
--- a/lua/gitlab/actions/merge.lua
+++ b/lua/gitlab/actions/merge.lua
@@ -17,7 +17,7 @@ end
---@param opts MergeOpts
M.merge = function(opts)
- local merge_body = { squash = state.settings.merge.squash, delete_branch = state.settings.merge.delete_branch }
+ local merge_body = { squash = state.INFO.squash, delete_branch = state.INFO.delete_branch }
if opts then
merge_body.squash = opts.squash ~= nil and opts.squash
merge_body.delete_branch = opts.delete_branch ~= nil and opts.delete_branch
diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua
index 61e0684..594dd72 100644
--- a/lua/gitlab/state.lua
+++ b/lua/gitlab/state.lua
@@ -87,10 +87,6 @@ M.settings = {
return " " .. discussions_content .. " %#Comment#| " .. notes_content .. help
end,
},
- merge = {
- squash = false,
- delete_branch = false,
- },
create_mr = {
target = nil,
template_file = nil, Then, I think, during a |
@jakubbortlik All of your proposals look good to me, if you push up I'll approve. I'll take a look at adding some documentation for the Lua test suite soon |
The simplification will make it easier to add the new arguments, delete_branch and squash.
- Use a uniform spacing before section headings. - Use highlighting for functions in API reference. - Unify description of parameters in API reference. - Change options for a consistent indentation (expandtab, shiftwidth=4 and tabstop=4)
c73c79d
to
0cfacbe
Compare
Hi Harrison, I've applied the three changes as agreed (got rid of |
This MR addresses issue #222 by:
delete_branch
andsquash
information in the MR Summary.settings.create_mr
cmd/create_mr.go
It also makes some minor additional changes:
gitlab.create_mr
parameters)..pick_template
andpick_target
functions to make adding new options easier.I think some other changes should be implemented in order to improve the user experience but they are not part of this MR:
gitlab.merge()
should be adjusted. Now the equally named options ofgitlab.merge()
simply override the options set bygitlab.create_mr()
or selected in the browser (possibly by another user). I believe, by default,merge()
should respect the settings that can be seen in the "Summary" (either set bygitlab.create_mr()
or in the browser). I can imagine a situation where I wanted to override these, so maybegitlab.merge()
could still be passed arguments when called from the command line or through a mapping, but I would suggest to remove the defaultsettings.merge.squash
andsettings.merge.delete_branch
options, however, this would be a breaking change.<ctrl-w><ctrl-w>
and<ctrl-w>W
is now more cumbersome than before, so I think it would be nice to implement some cycling mappings requested in the rejected issue Mappings to change focus #219. Then it would be easy to also use these mappings for the Summary popup.linewise_actions
that would enable changing the target branch anddelete_branch
andsquash
options in the confirmation popup, and also some select values in the Details window in the MR Summary. For the confirmation popup this is not that crucial -- a user can start over again if they make a mistake, but as soon as a MR is created, changes can only be made to it in the Browser, so making it possible to adjust some values in the Summary popup would be very practical.create_mr.pick_target()
- this could be done globally by adding a parameter to the following function, something like:utils.get_all_git_branches(remote, include_current_branch)
function. Otherwise an error is thrown only after all the MR creation work has been done.Details
change (e.g., reviewers, assignees, status, etc.)@harrisoncramer, if you think any of these additions make sense I can open feature requests for them, or separate MRs directly.