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 enhances the job management capabilities of the API client by introducing new endpoints and data structures for retrieving job progress and filtering jobs by name. It involves a refactoring of existing job entity definitions into a dedicated file and an upgrade of the API version used for job-related operations, providing more comprehensive and organized access to job information. 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 introduces new functionality for retrieving job progress and listing jobs by name, along with some code reorganization. The changes look good overall, but I've identified a few critical issues that should be addressed. These include a potential panic due to an index-out-of-range error, and resource leaks combined with incorrect response body handling in new HTTP client methods. I've also provided a suggestion to improve the signature of a new helper function for better idiomatic Go code. Please see the detailed comments for suggestions on how to resolve these issues.
api/job/job.go
Outdated
|
|
||
| // GetAllByName gets all jobs of a project by name | ||
| func (h httpJob) GetAllByName(projectID, name string) ([]GetJobResponse, error) { | ||
| reqURL := jobBasePath + projectID + "/jobs" |
There was a problem hiding this comment.
Security training reminded me of our bad habits. It would be ideal if you could find a special library that can generate a valid URL path rather than concatenating strings. Let's do it once, and it will make future development easier because we can easily copy and paste best practices.
There was a problem hiding this comment.
Changed to "path.Join"
| } | ||
|
|
||
| // GetAllByName gets all jobs of a project by name | ||
| func (h httpJob) GetAllByName(projectID, name string) ([]GetJobResponse, error) { |
There was a problem hiding this comment.
Could you please research how to add validation for input parameters? An example for this specific case: we must check that parameters are not empty and projectID follows specific patterns.
P.S. Well, I do not want to broaden the scope of this ticket/PR. Let's make a Jira ticket for research on how to use a declarative approach for validation (rather than imerative).
There was a problem hiding this comment.
We can do simple checks. If var is not empty etc. More complex checks could bring errors when in SDK var is invalid when in API the var is valid.
api/job/job.go
Outdated
| func (h httpJob) GetJob(projectID string, translationJobUID string) (GetJobResponse, error) { | ||
| // Get gets a job related info | ||
| func (h httpJob) Get(projectID string, translationJobUID string) (GetJobResponse, error) { | ||
| url := jobBasePath + projectID + "/jobs/" + translationJobUID |
There was a problem hiding this comment.
nit: I already proposed to avoid unsafe string concatenation. It would be great to use path.Join() and url.PathEscape(). Thanks
api/job/ent_job_progress.go
Outdated
| } | ||
| return GetJobProgressResponse{ | ||
| TranslationJobUID: translationJobUID, | ||
| TotalWordCount: uint32(r.Response.Data.Progress.TotalWordCount), |
There was a problem hiding this comment.
Why do we use a mix of int and uint32. Can we use int everywhere (in type definitions)?
There was a problem hiding this comment.
Can we use uint32? Most likely TotalWordCount cannot be less zero.
|
|
||
| // GetAllByName gets all jobs of a project by name | ||
| func (h httpJob) GetAllByName(projectID, name string) ([]GetJobResponse, error) { | ||
| reqURL := path.Join(jobBasePath, url.PathEscape(projectID), "jobs") |
There was a problem hiding this comment.
nit: In the method above you call variable url. Could you pls use the same variable name in the file (just for consitency).
Smartling/smartling-cli#95