Skip to content

Commit

Permalink
fix: correct some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
saman2000hoseini committed Jul 12, 2023
1 parent 7d1ea5d commit db21323
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/webhook-proxy/handler/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ func (p *Proxy) ProxyToElement(c echo.Context) error {
return c.NoContent(http.StatusBadRequest)
}

if p.proxyRequest(req, p.ElementURL) {
if p.proxyRequest(generateElementText(req), p.ElementURL) {
return c.NoContent(http.StatusOK)
}

return c.NoContent(http.StatusInternalServerError)
}

func (p *Proxy) proxyRequest(req *request.Jira, url string) bool {
func (p *Proxy) proxyRequest(txt string, url string) bool {
body, err := json.Marshal(ElementBody{
Text: fmt.Sprintf("Issuer: %s\nURL: %s", req.User.Name, req.Issue.Fields.CustomField11401.Links.Web),
Text: txt,
DisplayName: DisplayName,
})
if err != nil {
Expand Down Expand Up @@ -80,3 +80,10 @@ func (p *Proxy) proxyRequest(req *request.Jira, url string) bool {
logrus.Errorf("element response body read error: %s", responseBody)
return false
}

func generateElementText(req *request.Jira) string {
return fmt.Sprintf(
"Request Type: %s\nRequest Summary: %s\nIssuer: %s\nURL: %s",
req.Issue.Fields.IssueType.Name, req.Issue.Fields.Summary, req.User.Name,
req.Issue.Fields.CustomField11401.Links.Web)
}
5 changes: 5 additions & 0 deletions internal/webhook-proxy/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type Jira struct {
Web string `json:"web"`
} `json:"_links"`
} `json:"customfield_11401"`
Summary string `json:"summary"`
IssueType struct {
Description string `json:"description"`
Name string `json:"name"`
} `json:"issuetype"`
} `json:"fields"`
} `json:"issue"`
}

0 comments on commit db21323

Please sign in to comment.