Commit a5e65c4a authored by Simon Latapie's avatar Simon Latapie
Browse files

main: extract welcome message management from the main function

parent 5e0e4258
......@@ -103,6 +103,32 @@ func generateReport(mr MergeRequest, checks []Check) string {
return report
}
func sendWelcomeMessage(mr *MergeRequest, dryrun bool) {
// Check if we have to add a welcome message
welcome, err := mr.IsWelcomeMessagePresent()
if err != nil {
logMR(mr.IID, "ERROR! Something gone wrong when trying to check the welcome message: ", err.Error())
} else if !welcome {
logMR(mr.IID, "Cannot find a welcome message in the MR discussions, should add it!")
if dryrun {
logMR(mr.IID, "Dryrun enabled, will not post a welcome message")
} else {
welcomeMessage, err := mr.GenerateWelcomeMessage()
if err != nil {
logMR(mr.IID, "ERROR while trying to generate a Welcome message", err)
} else {
if err := mr.CreateNote(welcomeMessage); err != nil {
logMR(mr.IID, "ERROR while trying to add a Welcome Message in MR:", err)
} else {
logMR(mr.IID, "Welcome message successfully added")
}
}
}
} else {
logMR(mr.IID, "Already found a Welcome message in MR, not adding a new one")
}
}
func main() {
var projectID int64
var dryrun bool
......@@ -156,29 +182,7 @@ func main() {
}
logMR(mr.IID, "Active MR:", mr.IID)
if chatty {
// Check if we have to add a welcome message
welcome, err := mr.IsWelcomeMessagePresent()
if err != nil {
logMR(mr.IID, "ERROR! Something gone wrong when trying to check the welcome message: ", err.Error())
} else if !welcome {
logMR(mr.IID, "Cannot find a welcome message in the MR discussions, should add it!")
if dryrun {
logMR(mr.IID, "Dryrun enabled, will not post a welcome message")
} else {
welcomeMessage, err := mr.GenerateWelcomeMessage()
if err != nil {
logMR(mr.IID, "ERROR while trying to generate a Welcome message", err)
} else {
if err := mr.CreateNote(welcomeMessage); err != nil {
logMR(mr.IID, "ERROR while trying to add a Welcome Message in MR:", err)
} else {
logMR(mr.IID, "Welcome message successfully added")
}
}
}
} else {
logMR(mr.IID, "Already found a Welcome message in MR, not adding a new one")
}
sendWelcomeMessage(&mr, dryrun)
// Replay to direct request
userNotes, err := mr.GetAllNotesReferingUser(user)
if err != nil {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment