TP-48200 | updated response messages in link and unlink jira apis (#278)

This commit is contained in:
Shashank Shekhar
2023-11-08 17:29:25 +05:30
committed by GitHub
parent f199f68ae6
commit f075b0df8f
2 changed files with 16 additions and 16 deletions

View File

@@ -59,7 +59,7 @@ func (handler *IncidentHandler) HandleJiraLinking(c *gin.Context) {
return
}
if err := utils.ValidateLinkJiraRequest(linkJiraRequest); err != nil {
logger.Debug(fmt.Sprintf("%s invalid request to link Jira reveived. %s", logTag, err.Error()))
logger.Debug(fmt.Sprintf("%s invalid request to link JIRA reveived. %s", logTag, err.Error()))
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadGateway, nil))
return
}
@@ -67,13 +67,13 @@ func (handler *IncidentHandler) HandleJiraLinking(c *gin.Context) {
if err != nil {
logger.Error(
fmt.Sprintf(
"%s failed to link jira to the incident %d", logTag, linkJiraRequest.IncidentID,
"%s failed to link JIRA to the incident %d", logTag, linkJiraRequest.IncidentID,
), zap.Error(err),
)
c.JSON(http.StatusInternalServerError, common.ErrorResponse(err, http.StatusBadRequest, nil))
return
}
c.JSON(http.StatusOK, common.SuccessResponse("Jira link added successfully", http.StatusOK))
c.JSON(http.StatusOK, common.SuccessResponse("JIRA link added successfully", http.StatusOK))
}
func (handler *IncidentHandler) HandleJiraUnLinking(c *gin.Context) {
@@ -98,5 +98,5 @@ func (handler *IncidentHandler) HandleJiraUnLinking(c *gin.Context) {
c.JSON(http.StatusInternalServerError, common.ErrorResponse(err, http.StatusNotFound, nil))
return
}
c.JSON(http.StatusOK, common.SuccessResponse("Jira link removed successfully", http.StatusOK))
c.JSON(http.StatusOK, common.SuccessResponse("JIRA link removed successfully", http.StatusOK))
}

View File

@@ -153,7 +153,7 @@ func (i *IncidentServiceV2) CreateIncident(
}
func (i *IncidentServiceV2) LinkJiraToIncident(incidentId uint, linkedBy string, jiraLinks ...string) error {
logger.Info(fmt.Sprintf("%s received request to link jira to %d", logTag, incidentId))
logger.Info(fmt.Sprintf("%s received request to link JIRA to %d", logTag, incidentId))
logTag := fmt.Sprintf("%s [LinkJiraToIncident]", logTag)
entity, err := i.incidentRepository.FindIncidentById(incidentId)
if err != nil {
@@ -163,13 +163,13 @@ func (i *IncidentServiceV2) LinkJiraToIncident(incidentId uint, linkedBy string,
}
if len(jiraLinks) == 1 {
if util.Contains(entity.JiraLinks, jiraLinks[0]) {
return errors.New("The jira link already exists")
return errors.New("This JIRA link already exists")
}
}
err = i.updateJiraIDs(entity, linkedBy, logTag, LinkJira, jiraLinks...)
if err != nil {
logger.Error(fmt.Sprintf("%s failed to link jira to the incident: %s", logTag, entity.IncidentName))
_, err := i.slackService.PostMessageByChannelID("failed to link Jira", false, entity.SlackChannel)
logger.Error(fmt.Sprintf("%s failed to link JIRA to the incident: %s", logTag, entity.IncidentName))
_, err := i.slackService.PostMessageByChannelID("failed to link JIRA", false, entity.SlackChannel)
if err != nil {
logger.Info(fmt.Sprintf("%s failed to post jira linking failure message to slack channel: %s", logTag, entity.IncidentName))
}
@@ -178,7 +178,7 @@ func (i *IncidentServiceV2) LinkJiraToIncident(incidentId uint, linkedBy string,
}
func (i *IncidentServiceV2) UnLinkJiraFromIncident(incidentId uint, unLinkedBy, jiraLink string) error {
logger.Info(fmt.Sprintf("%s received request to unLink jira from %d", logTag, incidentId))
logger.Info(fmt.Sprintf("%s received request to unLink JIRA from %d", logTag, incidentId))
logTag := fmt.Sprintf("%s [UnLinkJiraFromIncident]", logTag)
entity, err := i.incidentRepository.FindIncidentById(incidentId)
if err != nil {
@@ -187,7 +187,7 @@ func (i *IncidentServiceV2) UnLinkJiraFromIncident(incidentId uint, unLinkedBy,
}
err = i.updateJiraIDs(entity, unLinkedBy, logTag, UnLinkJira, jiraLink)
if err != nil {
logger.Error(fmt.Sprintf("%s failed to unlink Jira ID(s): %s from incident %s", logTag, jiraLink, entity.IncidentName))
logger.Error(fmt.Sprintf("%s failed to unlink JIRA ID(s): %s from incident %s", logTag, jiraLink, entity.IncidentName))
return err
}
return nil
@@ -219,15 +219,15 @@ func (i *IncidentServiceV2) updateJiraIDs(entity *incident.IncidentEntity, user,
}
}
if len(newJiraLinks) == 0 {
_ = i.slackService.PostEphemeralByChannelID("`No new jira link to add`", updatedBy, false, entity.SlackChannel)
_ = i.slackService.PostEphemeralByChannelID("`No new JIRA link to add`", updatedBy, false, entity.SlackChannel)
} else if len(newJiraLinks) > 1 {
slackMessage = fmt.Sprintf(
"<@%s> `linked the following jiras to the incident: \"%s\"`",
"<@%s> `linked the following JIRAs to the incident: \"%s\"`",
updatedBy, re.ReplaceAllString(strings.Join(newJiraLinks, ", "), " "),
)
} else {
slackMessage = fmt.Sprintf(
"<@%s> `linked the following jira to the incident: \"%s\"`",
"<@%s> `linked the following JIRA to the incident: \"%s\"`",
updatedBy, re.ReplaceAllString(strings.Join(newJiraLinks, ", "), " "),
)
}
@@ -241,7 +241,7 @@ func (i *IncidentServiceV2) updateJiraIDs(entity *incident.IncidentEntity, user,
jiraToBeUpdated = util.Difference(entity.JiraLinks, validatedJiraIDsToBeRemoved)
if len(validatedJiraIDsToBeRemoved) > 0 {
slackMessage = fmt.Sprintf(
"<@%s> `unlinked the following jira from the incident: \"%s\"`",
"<@%s> `unlinked the following JIRA from the incident: \"%s\"`",
updatedBy, re.ReplaceAllString(strings.Join(validatedJiraIDsToBeRemoved, ", "), " "),
)
}
@@ -256,7 +256,7 @@ func (i *IncidentServiceV2) updateJiraIDs(entity *incident.IncidentEntity, user,
err = i.incidentRepository.UpdateIncident(entity)
if err != nil {
errorMessage := fmt.Sprintf("%s failed to update Jira IDs for incident %s", logTag, entity.IncidentName)
errorMessage := fmt.Sprintf("%s failed to update JIRA IDs for incident %s", logTag, entity.IncidentName)
logger.Error(errorMessage)
return fmt.Errorf(errorMessage, err)
}
@@ -264,7 +264,7 @@ func (i *IncidentServiceV2) updateJiraIDs(entity *incident.IncidentEntity, user,
if slackMessage != "" {
_, err = i.slackService.PostMessageByChannelID(slackMessage, false, entity.SlackChannel)
if err != nil {
logger.Error(fmt.Sprintf("%s failed to post message about update jira link to incident for %s", logTag, entity.IncidentName))
logger.Error(fmt.Sprintf("%s failed to post message about update JIRA link to incident for %s", logTag, entity.IncidentName))
}
}