-
Notifications
You must be signed in to change notification settings - Fork 2
added complete once if possible, added jira integration #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package jira | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
const ticketUrlFormat = "%s/browse/%s" | ||
|
||
// ExtractJiraTicketID returns the first JIRA ticket ID found in the input string. | ||
func ExtractJiraTicketID(s string) (string, error) { | ||
// This regular expression pattern matches a JIRA ticket ID (e.g. PROJ-123). | ||
pattern := `([aA-zZ]+-\d+)` | ||
re, err := regexp.Compile(pattern) | ||
if err != nil { | ||
return "", fmt.Errorf("error compiling regex: %w", err) | ||
} | ||
|
||
matches := re.FindStringSubmatch(s) | ||
if len(matches) == 0 { | ||
return "", fmt.Errorf("no JIRA ticket ID found in the input string") | ||
} | ||
|
||
return matches[0], nil | ||
} | ||
|
||
func GenerateJiraTicketURL(jiraURL, ticketID string) string { | ||
return fmt.Sprintf(ticketUrlFormat, jiraURL, ticketID) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code patch adds functionality for extracting JIRA ticket IDs from a string and generating a JIRA URL for a given ticket ID. Overall, the code seems simple and straightforward. One potential improvement could be to add more robust error handling for the Overall, the code seems low-risk for introducing bugs. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package jira | ||
|
||
import "testing" | ||
|
||
func TestExtractJiraTicketID(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
input string | ||
expected string | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Valid ticket ID", | ||
input: "This is a sample text with a JIRA ticket ID: PROJ-123, let's extract it.", | ||
expected: "PROJ-123", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "No ticket ID", | ||
input: "This is a sample text without a JIRA ticket ID.", | ||
expectError: true, | ||
}, | ||
{ | ||
name: "Multiple ticket IDs", | ||
input: "This text has multiple JIRA ticket IDs: PROJ-123, TASK-456, and BUG-789.", | ||
expected: "PROJ-123", | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Valid ticket ID. Lowercase.", | ||
input: "This is an invalid JIRA ticket ID: Proj-123.", | ||
expected: "Proj-123", | ||
expectError: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result, err := ExtractJiraTicketID(tc.input) | ||
if tc.expectError { | ||
if err == nil { | ||
t.Errorf("expected an error, but got none") | ||
} | ||
} else { | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
if result != tc.expected { | ||
t.Errorf("expected result '%s', but got '%s'", tc.expected, result) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code patch adds a test function for a Overall, the code patch looks good, and the testing strategy is quite comprehensive. However, one suggestion for improvement could be to include some edge cases, such as very long input strings or non-alphanumeric characters in the input string. Additionally, it might be a good idea to check for the error message in the test cases that expect an error to ensure that the correct type of error is being thrown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code patch adds a new flag
JiraURL
to the CLI and a new import packagejira
. ThegenCompletionOnce
andgenCompletionPerFile
functions are refactored to accept an OpenAI client as an argument. Therun
function now checks for theTest
flag and prints the completion output if it is set to true. A newgenCompletionPerFile
function is introduced to generate completion for files with diffs greater than 4000 bytes. Themain
function reads theJiraURL
flag, checks for theTest
flag, and calls therun
function to update the pull request description.The code looks easy to read, and the changes made seem reasonable. However, it is hard to tell if there are any bugs or risks without understanding the full context of the code and its usage. As for improvement suggestions, it would be helpful to add comments to explain the purpose and functionality of the added code. Additionally, error handling could be improved by providing more detailed error messages when returning errors.