Skip to content

Commit 5d34b06

Browse files
committed
Fix after lint and add test
1 parent 8e5ac41 commit 5d34b06

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

cmd/description/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"fmt"
6-
"github.com/ravilushqa/gpt-pullrequest-updater/shortcut"
76
"os"
87
"os/signal"
98
"syscall"
@@ -15,6 +14,7 @@ import (
1514
ghClient "github.com/ravilushqa/gpt-pullrequest-updater/github"
1615
"github.com/ravilushqa/gpt-pullrequest-updater/jira"
1716
oAIClient "github.com/ravilushqa/gpt-pullrequest-updater/openai"
17+
"github.com/ravilushqa/gpt-pullrequest-updater/shortcut"
1818
)
1919

2020
var opts struct {
@@ -26,7 +26,7 @@ var opts struct {
2626
OpenAIModel string `long:"openai-model" env:"OPENAI_MODEL" description:"OpenAI model" default:"gpt-3.5-turbo"`
2727
Test bool `long:"test" env:"TEST" description:"Test mode"`
2828
JiraURL string `long:"jira-url" env:"JIRA_URL" description:"Jira URL. Example: https://jira.atlassian.com"`
29-
ShortcutBaseURL string `long:"shortcut-url" env:"SHORTCUT_URL" description:"Shortcut URL. Example: https://app.shortcut.com/foo/"`
29+
ShortcutBaseURL string `long:"shortcut-url" env:"SHORTCUT_URL" description:"Shortcut URL. Example: https://app.shortcut.com/foo"`
3030
}
3131

3232
func main() {
@@ -110,5 +110,5 @@ func buildShortcutContent(shortcutBaseURL string, pr *github.PullRequest) string
110110
return ""
111111
}
112112

113-
return fmt.Sprintf("### Shortcut story: [%s](%s)", id, shortcut.GenerateShortcutStoryUrl(shortcutBaseURL, id))
113+
return fmt.Sprintf("### Shortcut story: [%s](%s)", id, shortcut.GenerateShortcutStoryURL(shortcutBaseURL, id))
114114
}

shortcut/shortcut.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"regexp"
66
)
77

8-
const storyUrlFormat = "%s/story/%s"
8+
const storyURLFormat = "%s/story/%s"
99

1010
func ExtractShortcutStoryID(title string) (string, error) {
1111

@@ -24,6 +24,6 @@ func ExtractShortcutStoryID(title string) (string, error) {
2424
return matches[1], nil
2525
}
2626

27-
func GenerateShortcutStoryUrl(shortcutBaseUrl, ticketId string) string {
28-
return fmt.Sprintf(storyUrlFormat, shortcutBaseUrl, ticketId)
27+
func GenerateShortcutStoryURL(shortcutBaseUrl, ticketId string) string {
28+
return fmt.Sprintf(storyURLFormat, shortcutBaseUrl, ticketId)
2929
}

shortcut/shortcut_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package shortcut
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestExtractShortcutStoryID(t *testing.T) {
10+
testCases := []struct {
11+
title string
12+
expectedID string
13+
expectedErr bool
14+
}{
15+
{
16+
title: "This is a sample title with a valid story ID sc-12345",
17+
expectedID: "12345",
18+
expectedErr: false,
19+
},
20+
{
21+
title: "No story ID in this title",
22+
expectedID: "",
23+
expectedErr: true,
24+
},
25+
{
26+
title: "Invalid story ID format sc-abcde",
27+
expectedID: "",
28+
expectedErr: true,
29+
},
30+
}
31+
32+
for _, tc := range testCases {
33+
id, err := ExtractShortcutStoryID(tc.title)
34+
35+
if tc.expectedErr {
36+
assert.Error(t, err)
37+
} else {
38+
assert.NoError(t, err)
39+
assert.Equal(t, tc.expectedID, id)
40+
}
41+
}
42+
}
43+
44+
func TestGenerateShortcutStoryURL(t *testing.T) {
45+
baseURL := "https://app.shortcut.com/foo"
46+
ticketID := "12345"
47+
expectedURL := "https://app.shortcut.com/foo/story/12345"
48+
49+
url := GenerateShortcutStoryURL(baseURL, ticketID)
50+
assert.Equal(t, expectedURL, url)
51+
}

0 commit comments

Comments
 (0)