Skip to content

Commit 35e205c

Browse files
committed
Add shortcut link to description
1 parent e650c55 commit 35e205c

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Replace `<GITHUB_TOKEN>`, `<OPENAI_TOKEN>`, `<OWNER>`, `<REPO>`, and `<PR_NUMBER
5454
### Description Command
5555

5656
The usage for the `description` command is similar to the `review` command. Replace `review` with `description` in the command above and execute.
57-
Only difference is that `description` command has extra option `--jira-url` which is used to generate Jira links in the description.
57+
The only difference is that the `description` command has extra options, `--jira-url` and `--shortcut-url`, which are used to generate Jira or Shortcut links in the description, accordingly.
5858

5959
## GitHub Action
6060

cmd/description/main.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"github.com/ravilushqa/gpt-pullrequest-updater/description"
7+
oAIClient "github.com/ravilushqa/gpt-pullrequest-updater/openai"
8+
"github.com/ravilushqa/gpt-pullrequest-updater/shortcut"
69
"os"
710
"os/signal"
811
"syscall"
912

1013
"github.com/google/go-github/v51/github"
1114
"github.com/jessevdk/go-flags"
1215

13-
"github.com/ravilushqa/gpt-pullrequest-updater/description"
1416
ghClient "github.com/ravilushqa/gpt-pullrequest-updater/github"
1517
"github.com/ravilushqa/gpt-pullrequest-updater/jira"
16-
oAIClient "github.com/ravilushqa/gpt-pullrequest-updater/openai"
1718
)
1819

1920
var opts struct {
@@ -25,7 +26,7 @@ var opts struct {
2526
OpenAIModel string `long:"openai-model" env:"OPENAI_MODEL" description:"OpenAI model" default:"gpt-3.5-turbo"`
2627
Test bool `long:"test" env:"TEST" description:"Test mode"`
2728
JiraURL string `long:"jira-url" env:"JIRA_URL" description:"Jira URL. Example: https://jira.atlassian.com"`
28-
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/"`
2930
}
3031

3132
func main() {
@@ -73,6 +74,13 @@ func run(ctx context.Context) error {
7374
}
7475
}
7576

77+
if opts.ShortcutBaseUrl != "" {
78+
shortcutContent := buildShortcutContent(opts.ShortcutBaseUrl, pr)
79+
if shortcutContent != "" {
80+
completion = fmt.Sprintf("%s\n\n%s", shortcutContent, completion)
81+
}
82+
}
83+
7684
if opts.Test {
7785
return nil
7886
}
@@ -86,3 +94,21 @@ func run(ctx context.Context) error {
8694

8795
return nil
8896
}
97+
98+
func buildShortcutContent(shortcutBaseUrl string, pr *github.PullRequest) string {
99+
fmt.Println("Adding Shortcut ticket")
100+
101+
id, err := shortcut.ExtractShortcutStoryId(*pr.Title)
102+
103+
if err != nil {
104+
// Extracting from the branch name
105+
id, err = shortcut.ExtractShortcutStoryId(*pr.Head.Ref)
106+
}
107+
108+
if err != nil {
109+
fmt.Printf("There is no Shortcut story ID: %v \n", err)
110+
return ""
111+
}
112+
113+
return fmt.Sprintf("### Shortcut story: [%s](%s)", id, shortcut.GenerateShortcutStoryUrl(shortcutBaseUrl, id))
114+
}

shortcut/shortcut.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package shortcut
2+
3+
import (
4+
"fmt"
5+
"regexp"
6+
)
7+
8+
const storyUrlFormat = "%s/story/%s"
9+
10+
func ExtractShortcutStoryId(title string) (string, error) {
11+
12+
// This regular expression pattern matches a Shortcut story ID (e.g. sc-12345).
13+
pattern := `sc-([\d]+)`
14+
re, err := regexp.Compile(pattern)
15+
if err != nil {
16+
return "", fmt.Errorf("error compiling regex: %w", err)
17+
}
18+
19+
matches := re.FindStringSubmatch(title)
20+
if len(matches) < 2 {
21+
return "", fmt.Errorf("no Shortcut story ID found in the input string")
22+
}
23+
24+
return matches[1], nil
25+
}
26+
27+
func GenerateShortcutStoryUrl(shortcutBaseUrl, ticketId string) string {
28+
return fmt.Sprintf(storyUrlFormat, shortcutBaseUrl, ticketId)
29+
}

0 commit comments

Comments
 (0)