Skip to content

Commit

Permalink
cmd/mr_discussion: populate PositionOptions when needed
Browse files Browse the repository at this point in the history
With commit 4d1dbfa ("cmd/mr_discussion.go: Switch from NotePosition to
PositionOptions") the PositionOptions object was being created
regardless the presence of --position in user's command, causing the
REST API to fail due to the presence of a "position" parameter in the
request without all required arguments. This commit creates the
PositionOptions object within the --position handler, ensuring it's not
passed "empty".

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Apr 18, 2024
1 parent 493268e commit 0dd35f5
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmd/mr_discussion.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var mrCreateDiscussionCmd = &cobra.Command{
return
}

var notePos gitlab.PositionOptions
var discussionOpts gitlab.CreateMergeRequestDiscussionOptions
if position != "" {
if commit == "" {
// We currently only support "--position" when commenting on individual commits within an MR.
Expand Down Expand Up @@ -150,7 +150,7 @@ var mrCreateDiscussionCmd = &cobra.Command{
oldLine := int(oldLine64)

positionType := "text"
notePos = gitlab.PositionOptions{
discussionOpts.Position = &gitlab.PositionOptions{
BaseSHA: &parentSHA,
StartSHA: &parentSHA,
HeadSHA: &commit,
Expand All @@ -165,16 +165,13 @@ var mrCreateDiscussionCmd = &cobra.Command{
if body == "" {
log.Fatal("aborting discussion due to empty discussion msg")
}
var commitID *string
discussionOpts.Body = &body

if commit != "" {
commitID = &commit
discussionOpts.CommitID = &commit
}

discussionURL, err := lab.MRCreateDiscussion(rn, int(mrNum), &gitlab.CreateMergeRequestDiscussionOptions{
Body: &body,
CommitID: commitID,
Position: &notePos,
})
discussionURL, err := lab.MRCreateDiscussion(rn, int(mrNum), &discussionOpts)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 0dd35f5

Please sign in to comment.