CON-1842 Add a --nojob option for the upload command#20
Conversation
Summary of ChangesHello @az-smartling, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the foundational components for uploading files to the Smartling API. It extends the existing API client with a new Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds the functionality to upload files to the Smartling API by introducing an UploadFile method on the API client. The changes are well-structured, following the existing patterns in the codebase. I've identified one area for improvement in the new file_upload_request.go file concerning repetitive error handling, and I've provided a suggestion to make the code more concise and maintainable. Overall, the implementation looks correct and is a good addition.
| _, err = writer.Write(r.File) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| err = form.Writer.WriteField("fileType", string(r.FileType)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if r.Authorize { | ||
| err = form.Writer.WriteField("authorize", "true") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| for _, locale := range r.LocalesToAuthorize { | ||
| err = form.Writer.WriteField("localeIdsToAuthorize[]", locale) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| if r.Smartling.Namespace != "" { | ||
| err = form.Writer.WriteField( | ||
| "smartling.namespace", | ||
| r.Smartling.Namespace, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| if r.Smartling.FileCharset != "" { | ||
| err = form.Writer.WriteField( | ||
| "smartling.file_charset", | ||
| r.Smartling.FileCharset, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| for directive, value := range r.Smartling.Directives { | ||
| err = form.Writer.WriteField("smartling."+directive, value) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } |
There was a problem hiding this comment.
The error handling in this function is quite repetitive. While correct, it can be made more concise and maintainable by combining the assignment and check in a single if statement. This is a common Go idiom that improves readability.
if _, err = writer.Write(r.File); err != nil {
return nil, err
}
if err = form.Writer.WriteField("fileType", string(r.FileType)); err != nil {
return nil, err
}
if r.Authorize {
if err = form.Writer.WriteField("authorize", "true"); err != nil {
return nil, err
}
}
for _, locale := range r.LocalesToAuthorize {
if err = form.Writer.WriteField("localeIdsToAuthorize[]", locale); err != nil {
return nil, err
}
}
if r.Smartling.Namespace != "" {
if err = form.Writer.WriteField(
"smartling.namespace",
r.Smartling.Namespace,
); err != nil {
return nil, err
}
}
if r.Smartling.FileCharset != "" {
if err = form.Writer.WriteField(
"smartling.file_charset",
r.Smartling.FileCharset,
); err != nil {
return nil, err
}
}
for directive, value := range r.Smartling.Directives {
if err = form.Writer.WriteField("smartling."+directive, value); err != nil {
return nil, err
}
}
Smartling/smartling-cli#91