diff options
author | Chris <ccbrown112@gmail.com> | 2017-09-28 15:31:23 -0500 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-09-28 16:31:23 -0400 |
commit | cb33179998c682bf1e48795d449d85f92cec97f7 (patch) | |
tree | 081dffdc262924c3afc4b62c39efef760c4d9f55 /app | |
parent | 6c73c1459316a0d4c50a5a8bd17b8aee91cdc841 (diff) | |
download | chat-cb33179998c682bf1e48795d449d85f92cec97f7.tar.gz chat-cb33179998c682bf1e48795d449d85f92cec97f7.tar.bz2 chat-cb33179998c682bf1e48795d449d85f92cec97f7.zip |
PLT-7758: jira url fix (#7536)
* jira url fix
* whoops, forgot a file (the test file)
Diffstat (limited to 'app')
-rw-r--r-- | app/plugin/jira/webhook.go | 16 | ||||
-rw-r--r-- | app/plugin/jira/webhook_test.go | 16 |
2 files changed, 25 insertions, 7 deletions
diff --git a/app/plugin/jira/webhook.go b/app/plugin/jira/webhook.go index 748362571..9798bcd9f 100644 --- a/app/plugin/jira/webhook.go +++ b/app/plugin/jira/webhook.go @@ -5,7 +5,6 @@ package jira import ( "bytes" - "net/url" "strings" "text/template" @@ -130,12 +129,15 @@ func (w *Webhook) SlackAttachment() (*model.SlackAttachment, error) { }, nil } -func (w *Webhook) renderText(tplBody string) (string, error) { - issueSelf, err := url.Parse(w.Issue.Self) - if err != nil { - return "", err +func (w *Webhook) JIRAURL() string { + pos := strings.LastIndex(w.Issue.Self, "/rest/api") + if pos < 0 { + return "" } - jiraURL := strings.TrimRight(issueSelf.ResolveReference(&url.URL{Path: "/"}).String(), "/") + return w.Issue.Self[:pos] +} + +func (w *Webhook) renderText(tplBody string) (string, error) { verb := strings.TrimPrefix(w.WebhookEvent, "jira:issue_") if w.WebhookEvent == "jira:issue_updated" { @@ -163,7 +165,7 @@ func (w *Webhook) renderText(tplBody string) (string, error) { Verb string }{ Webhook: w, - JIRAURL: jiraURL, + JIRAURL: w.JIRAURL(), Verb: verb, }); err != nil { return "", err diff --git a/app/plugin/jira/webhook_test.go b/app/plugin/jira/webhook_test.go new file mode 100644 index 000000000..25918657e --- /dev/null +++ b/app/plugin/jira/webhook_test.go @@ -0,0 +1,16 @@ +package jira + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestWebhookJIRAURL(t *testing.T) { + var w Webhook + w.Issue.Self = "http://localhost:8080/rest/api/2/issue/10006" + assert.Equal(t, "http://localhost:8080", w.JIRAURL()) + + w.Issue.Self = "http://localhost:8080/foo/bar/rest/api/2/issue/10006" + assert.Equal(t, "http://localhost:8080/foo/bar", w.JIRAURL()) +} |