PLT-7758: jira url fix (#7536)
* jira url fix * whoops, forgot a file (the test file)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
6c73c14593
Коммит
cb33179998
@@ -5,7 +5,6 @@ package jira
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@@ -130,12 +129,15 @@ func (w *Webhook) SlackAttachment() (*model.SlackAttachment, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Webhook) renderText(tplBody string) (string, error) {
|
func (w *Webhook) JIRAURL() string {
|
||||||
issueSelf, err := url.Parse(w.Issue.Self)
|
pos := strings.LastIndex(w.Issue.Self, "/rest/api")
|
||||||
if err != nil {
|
if pos < 0 {
|
||||||
return "", err
|
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_")
|
verb := strings.TrimPrefix(w.WebhookEvent, "jira:issue_")
|
||||||
|
|
||||||
if w.WebhookEvent == "jira:issue_updated" {
|
if w.WebhookEvent == "jira:issue_updated" {
|
||||||
@@ -163,7 +165,7 @@ func (w *Webhook) renderText(tplBody string) (string, error) {
|
|||||||
Verb string
|
Verb string
|
||||||
}{
|
}{
|
||||||
Webhook: w,
|
Webhook: w,
|
||||||
JIRAURL: jiraURL,
|
JIRAURL: w.JIRAURL(),
|
||||||
Verb: verb,
|
Verb: verb,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
16
app/plugin/jira/webhook_test.go
Обычный файл
16
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())
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user