PLT-7758: jira url fix (#7536)

* jira url fix

* whoops, forgot a file (the test file)
This commit is contained in:
Chris
2017-09-28 15:31:23 -05:00
committed by Harrison Healey
parent 6c73c14593
commit cb33179998
2 changed files with 25 additions and 7 deletions

View File

@@ -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

View File

@@ -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())
}