Skip to content

Commit db3f7c4

Browse files
committed
cmd/mr_discussion: populate PositionOptions when needed
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 <bmeneg@redhat.com>
1 parent 493268e commit db3f7c4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

cmd/mr_discussion.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ var mrCreateDiscussionCmd = &cobra.Command{
121121
return
122122
}
123123

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

152152
positionType := "text"
153-
notePos = gitlab.PositionOptions{
153+
discussionOpts.Position = &gitlab.PositionOptions{
154154
BaseSHA: &parentSHA,
155155
StartSHA: &parentSHA,
156156
HeadSHA: &commit,
@@ -165,16 +165,15 @@ var mrCreateDiscussionCmd = &cobra.Command{
165165
if body == "" {
166166
log.Fatal("aborting discussion due to empty discussion msg")
167167
}
168+
discussionOpts.Body = &body
169+
168170
var commitID *string
169171
if commit != "" {
170172
commitID = &commit
171173
}
174+
discussionOpts.CommitID = commitID
172175

173-
discussionURL, err := lab.MRCreateDiscussion(rn, int(mrNum), &gitlab.CreateMergeRequestDiscussionOptions{
174-
Body: &body,
175-
CommitID: commitID,
176-
Position: &notePos,
177-
})
176+
discussionURL, err := lab.MRCreateDiscussion(rn, int(mrNum), &discussionOpts)
178177
if err != nil {
179178
log.Fatal(err)
180179
}

0 commit comments

Comments
 (0)