Made comment code sequential to avoid multiple comments
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xanzy/go-gitlab"
|
"github.com/xanzy/go-gitlab"
|
||||||
@@ -56,42 +55,24 @@ func (c *Client) Comment() error {
|
|||||||
|
|
||||||
/* This is necessary since we do not know whether the comment is on a line that
|
/* This is necessary since we do not know whether the comment is on a line that
|
||||||
has been changed or not. Making all three of these API calls will let us leave
|
has been changed or not. Making all three of these API calls will let us leave
|
||||||
the comment regardless. See the Gitlab documentation: https://docs.gitlab.com/ee/api/discussions.html#create-a-new-thread-in-the-merge-request-diff */
|
the comment regardless. I ran these in sequence vai a Sync.WaitGroup, but
|
||||||
wg := sync.WaitGroup{}
|
it was successfully posting a comment to a modified twice, so now I'm running
|
||||||
wg.Add(3)
|
them in sequence.
|
||||||
|
|
||||||
resultChannel := make(chan *http.Response, 3)
|
To clean this up we might try to detect more information about the change in our
|
||||||
|
Lua code and pass it to the Go code.
|
||||||
|
|
||||||
|
See the Gitlab documentation: https://docs.gitlab.com/ee/api/discussions.html#create-a-new-thread-in-the-merge-request-diff */
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
ii := i
|
ii := i
|
||||||
go func() {
|
_, err := c.CommentOnDeletion(lineNumber, fileName, comment, diffVersionInfo[0], ii)
|
||||||
defer wg.Done()
|
if err == nil {
|
||||||
response, err := c.CommentOnDeletion(lineNumber, fileName, comment, diffVersionInfo[0], ii)
|
|
||||||
if err != nil {
|
|
||||||
resultChannel <- nil
|
|
||||||
} else {
|
|
||||||
resultChannel <- response
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
|
||||||
close(resultChannel)
|
|
||||||
}()
|
|
||||||
|
|
||||||
var commentResponse *http.Response
|
|
||||||
for res := range resultChannel {
|
|
||||||
if res != nil {
|
|
||||||
commentResponse = res
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if commentResponse == nil {
|
|
||||||
return fmt.Errorf("Could not leave comment")
|
|
||||||
}
|
|
||||||
fmt.Println("Left Comment: " + comment[0:min(len(comment), 25)] + "...")
|
fmt.Println("Left Comment: " + comment[0:min(len(comment), 25)] + "...")
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Could not leave comment")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user