55 "fmt"
66 "os"
77 "os/signal"
8- "strings"
98 "syscall"
109
1110 "github.com/google/go-github/v51/github"
@@ -30,13 +29,7 @@ var opts struct {
3029 ShortcutBaseURL string `long:"shortcut-url" env:"SHORTCUT_URL" description:"Shortcut URL. Example: https://app.shortcut.com/foo"`
3130}
3231
33- type prDataType struct {
34- completion string
35- jiraInfo string
36- shortcutInfo string
37- }
38-
39- var prData prDataType
32+ var descriptionInfo description.Info
4033
4134func main () {
4235 ctx , cancel := signal .NotifyContext (context .Background (), syscall .SIGINT , syscall .SIGTERM )
@@ -68,7 +61,7 @@ func run(ctx context.Context) error {
6861 return fmt .Errorf ("error getting commits: %w" , err )
6962 }
7063
71- prData . completion , err = description .GenerateCompletion (ctx , openAIClient , diff , pr )
64+ descriptionInfo . Completion , err = description .GenerateCompletion (ctx , openAIClient , diff , pr )
7265 if err != nil {
7366 return fmt .Errorf ("error generating completion: %w" , err )
7467 }
@@ -79,12 +72,12 @@ func run(ctx context.Context) error {
7972 if err != nil {
8073 fmt .Printf ("Error extracting Jira ticket ID: %v \n " , err )
8174 } else {
82- prData . jiraInfo = fmt .Sprintf ("### JIRA ticket: [%s](%s)" , id , jira .GenerateJiraTicketURL (opts .JiraURL , id ))
75+ descriptionInfo . JiraInfo = fmt .Sprintf ("### JIRA ticket: [%s](%s)" , id , jira .GenerateJiraTicketURL (opts .JiraURL , id ))
8376 }
8477 }
8578
8679 if opts .ShortcutBaseURL != "" {
87- prData . shortcutInfo = buildShortcutContent (opts .ShortcutBaseURL , pr )
80+ descriptionInfo . ShortcutInfo = buildShortcutContent (opts .ShortcutBaseURL , pr )
8881 }
8982
9083 if opts .Test {
@@ -93,8 +86,8 @@ func run(ctx context.Context) error {
9386
9487 // Update the pull request description
9588 fmt .Println ("Updating pull request" )
96- updatePr := buildUpdatedDescription (* pr .Body , prData )
97- if _ , err = githubClient .UpdatePullRequest (ctx , opts .Owner , opts .Repo , opts .PRNumber , updatePr ); err != nil {
89+ updatedPr := description . BuildUpdatedPullRequest (* pr .Body , descriptionInfo )
90+ if _ , err = githubClient .UpdatePullRequest (ctx , opts .Owner , opts .Repo , opts .PRNumber , updatedPr ); err != nil {
9891 return fmt .Errorf ("error updating pull request: %w" , err )
9992 }
10093
@@ -118,32 +111,3 @@ func buildShortcutContent(shortcutBaseURL string, pr *github.PullRequest) string
118111
119112 return fmt .Sprintf ("### Shortcut story: [%s](%s)" , id , shortcut .GenerateShortcutStoryURL (shortcutBaseURL , id ))
120113}
121-
122- func buildUpdatedDescription (existingBody string , prData prDataType ) * github.PullRequest {
123-
124- desc := ""
125-
126- if prData .jiraInfo != "" {
127- desc = prData .jiraInfo + "\n \n " + desc
128- }
129-
130- if prData .shortcutInfo != "" {
131- desc = prData .shortcutInfo + "\n \n " + desc
132- }
133-
134- if prData .completion != "" {
135- desc += prData .completion
136- }
137-
138- if existingBody != "" && strings .Contains (existingBody , description .Placeholder ) {
139- builtBody := strings .Replace (
140- existingBody ,
141- description .Placeholder ,
142- description .PlaceholderHidden + desc ,
143- 1 ,
144- )
145- return & github.PullRequest {Body : github .String (builtBody )}
146- }
147-
148- return & github.PullRequest {Body : github .String (desc )}
149- }
0 commit comments