5
5
"fmt"
6
6
"os"
7
7
"os/signal"
8
- "strings"
9
8
"syscall"
10
9
11
10
"github.com/google/go-github/v51/github"
@@ -30,13 +29,7 @@ var opts struct {
30
29
ShortcutBaseURL string `long:"shortcut-url" env:"SHORTCUT_URL" description:"Shortcut URL. Example: https://app.shortcut.com/foo"`
31
30
}
32
31
33
- type prDataType struct {
34
- completion string
35
- jiraInfo string
36
- shortcutInfo string
37
- }
38
-
39
- var prData prDataType
32
+ var descriptionInfo description.Info
40
33
41
34
func main () {
42
35
ctx , cancel := signal .NotifyContext (context .Background (), syscall .SIGINT , syscall .SIGTERM )
@@ -68,7 +61,7 @@ func run(ctx context.Context) error {
68
61
return fmt .Errorf ("error getting commits: %w" , err )
69
62
}
70
63
71
- prData . completion , err = description .GenerateCompletion (ctx , openAIClient , diff , pr )
64
+ descriptionInfo . Completion , err = description .GenerateCompletion (ctx , openAIClient , diff , pr )
72
65
if err != nil {
73
66
return fmt .Errorf ("error generating completion: %w" , err )
74
67
}
@@ -79,12 +72,12 @@ func run(ctx context.Context) error {
79
72
if err != nil {
80
73
fmt .Printf ("Error extracting Jira ticket ID: %v \n " , err )
81
74
} 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 ))
83
76
}
84
77
}
85
78
86
79
if opts .ShortcutBaseURL != "" {
87
- prData . shortcutInfo = buildShortcutContent (opts .ShortcutBaseURL , pr )
80
+ descriptionInfo . ShortcutInfo = buildShortcutContent (opts .ShortcutBaseURL , pr )
88
81
}
89
82
90
83
if opts .Test {
@@ -93,8 +86,8 @@ func run(ctx context.Context) error {
93
86
94
87
// Update the pull request description
95
88
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 {
98
91
return fmt .Errorf ("error updating pull request: %w" , err )
99
92
}
100
93
@@ -118,32 +111,3 @@ func buildShortcutContent(shortcutBaseURL string, pr *github.PullRequest) string
118
111
119
112
return fmt .Sprintf ("### Shortcut story: [%s](%s)" , id , shortcut .GenerateShortcutStoryURL (shortcutBaseURL , id ))
120
113
}
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