Jira link table (#331)

* TP-51013 | incident_jira entity, repo and service

* TP-51013 | get jira status api

* TP-51013 | added db migration file

* TP-51013 | added migration query to migrate existing jira links into new table

* TP-51013 | removing linked_jira_issues column from incident table

* TP-51013 | removing empty jira fields if no response found for a jira key in jira api response

* TP-51013 | handled jira api failure cases, will return empty jira fields

* TP-51013 | removed linked_jira_issues field from incident entity

* TP-51013 | handled jira link addition and removal in slack action

* TP-51013 | resolving PR comments

* TP-51013 | adding jira link max length check
This commit is contained in:
Shashank Shekhar
2023-12-21 16:52:35 +05:30
committed by GitHub
parent f31c75a1fb
commit 5758e603e8
20 changed files with 614 additions and 19 deletions

View File

@@ -24,7 +24,7 @@ type IncidentHandler struct {
gin *gin.Engine
db *gorm.DB
authService *service.AuthService
service *incident.IncidentServiceV2
service *incident.IncidentServiceV2
}
func NewIncidentHandler(gin *gin.Engine, db *gorm.DB, authService *service.AuthService, incidentService *incident.IncidentServiceV2) *IncidentHandler {
@@ -32,7 +32,7 @@ func NewIncidentHandler(gin *gin.Engine, db *gorm.DB, authService *service.AuthS
gin: gin,
db: db,
authService: authService,
service: incidentService,
service: incidentService,
}
}
@@ -57,10 +57,10 @@ func (handler *IncidentHandler) HandleCreateIncident(c *gin.Context) {
c.JSON(http.StatusOK, common.SuccessResponse(incidentResponse, http.StatusOK))
}
func (h *IncidentHandler) HandleUpdateIncident(c *gin.Context) {
func (handler *IncidentHandler) HandleUpdateIncident(c *gin.Context) {
userEmail := c.GetHeader(util.UserEmailHeader)
sessionToken := c.GetHeader(util.SessionTokenHeader)
isValidUser, err := h.authService.CheckValidUser(sessionToken, userEmail)
isValidUser, err := handler.authService.CheckValidUser(sessionToken, userEmail)
if err != nil || !isValidUser {
c.JSON(http.StatusUnauthorized, common.ErrorResponse(errors.New("Unauthorized user"), http.StatusUnauthorized, nil))
return
@@ -77,7 +77,7 @@ func (h *IncidentHandler) HandleUpdateIncident(c *gin.Context) {
return
}
incidentServiceV2 := incident.NewIncidentServiceV2(h.db)
incidentServiceV2 := incident.NewIncidentServiceV2(handler.db)
result, err := incidentServiceV2.UpdateIncident(updateIncidentRequest, userEmail)
if err != nil {
@@ -136,3 +136,20 @@ func (handler *IncidentHandler) HandleJiraUnLinking(c *gin.Context) {
}
c.JSON(http.StatusOK, common.SuccessResponse("JIRA link removed successfully", http.StatusOK))
}
func (handler *IncidentHandler) HandleGetJiraStatuses(c *gin.Context) {
IncidentName := c.Query("incident_name")
pageSize, pageNumber, err :=
utils.ValidatePage(c.Query("page_size"), c.Query("page_number"))
if err != nil {
logger.Error("error in query parameters", zap.Int64("page_size", pageSize),
zap.Int64("page_number", pageNumber), zap.Error(err))
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
return
}
statuses, err := handler.service.GetJiraStatuses(IncidentName, pageNumber, pageSize)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
}
c.JSON(http.StatusOK, statuses)
}

View File

@@ -160,6 +160,7 @@ func (s *Server) incidentClientHandlerV2(houstonGroup *gin.RouterGroup) {
}
houstonGroup.POST("/link-jira-to-incident", incidentHandler.HandleJiraLinking)
houstonGroup.POST("/unlink-jira-from-incident", incidentHandler.HandleJiraUnLinking)
houstonGroup.GET("/get-jira-statuses", incidentHandler.HandleGetJiraStatuses)
}
func (s *Server) incidentHandler(houstonGroup *gin.RouterGroup) {