Skip to content

Conversation

@az-smartling
Copy link
Contributor

Return information about job

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 batch processing API by introducing the capability to retrieve detailed information about individual translation jobs. It provides a new method to query job specifics using a project ID and a translation job UID, ensuring that clients can access comprehensive job data.

Highlights

  • New API Method: A new GetJob method has been added to the Batch interface, allowing retrieval of specific job information.
  • Job Information Retrieval: The GetJob method is implemented to perform an HTTP GET request to the /job-batches-api/v2/projects/{projectID}/jobs/{translationJobUID} endpoint, fetching details about a translation job.
  • Data Structures for Job Details: New Go structs, GetJobResponse and getJobResponse, along with a conversion function toGetJobResponse, have been introduced to properly handle and parse the API response for job information.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new GetJob method to fetch job information. The implementation is straightforward, but there are a few areas for improvement. I've pointed out the missing context.Context which is a standard practice in Go for I/O operations, and suggested improvements to error handling to make debugging easier. I've also noted a minor issue with how a custom error type is populated. The changes to batch_ent.go look good.

type Batch interface {
Create(ctx context.Context, projectID string, payload CreateBatchPayload) (CreateBatchResponse, error)
CreateJob(ctx context.Context, projectID string, payload CreateJobPayload) (CreateJobResponse, error)
GetJob(projectID string, translationJobUID string) (GetJobResponse, error)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency with other methods in this interface and to follow Go best practices for I/O operations, the GetJob method should accept a context.Context as its first argument. This allows for request cancellation, deadlines, and passing request-scoped values.

Suggested change
GetJob(projectID string, translationJobUID string) (GetJobResponse, error)
GetJob(ctx context.Context, projectID string, translationJobUID string) (GetJobResponse, error)

}

// GetJob gets a job related info
func (h httpBatch) GetJob(projectID string, translationJobUID string) (GetJobResponse, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The implementation of GetJob should be updated to accept a context.Context to match the change in the Batch interface. While the context might not be used immediately by h.client.Get, adding it makes the function signature consistent with other API methods and is a good practice for functions that perform network requests.

Suggested change
func (h httpBatch) GetJob(projectID string, translationJobUID string) (GetJobResponse, error) {
func (h httpBatch) GetJob(ctx context.Context, projectID string, translationJobUID string) (GetJobResponse, error) {

Comment on lines 112 to 114
if code != 200 {
return GetJobResponse{}, fmt.Errorf("unexpected response code: %d with %s", code, rawMessage)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The error message for an unexpected status code is not very helpful because rawMessage is an io.ReadCloser and printing it with %s will not show the response body. The response body for non-200 responses often contains valuable error details from the API. You should read the body and include it in the error message. Also, it's better to use the http.StatusOK constant instead of the magic number 200 for readability and maintainability.

Suggested change
if code != 200 {
return GetJobResponse{}, fmt.Errorf("unexpected response code: %d with %s", code, rawMessage)
}
if code != http.StatusOK {
body, _ := io.ReadAll(rawMessage)
return GetJobResponse{}, fmt.Errorf("unexpected response code: %d with %s", code, body)
}

Comment on lines 117 to 121
return GetJobResponse{}, smerror.APIError{
Cause: err,
URL: url,
Payload: []byte(fmt.Sprintf("%v", rawMessage)),
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When io.ReadAll(rawMessage) fails, you are creating an smerror.APIError. However, the Payload field is being populated with []byte(fmt.Sprintf("%v", rawMessage)). At this point, rawMessage has already been read (or an attempt was made), so it's likely empty or closed. This will not provide useful information. The Payload field in APIError is meant for the request payload. For a GET request, there is no payload. You should set Payload to nil.

Suggested change
return GetJobResponse{}, smerror.APIError{
Cause: err,
URL: url,
Payload: []byte(fmt.Sprintf("%v", rawMessage)),
}
return GetJobResponse{}, smerror.APIError{
Cause: err,
URL: url,
Payload: nil,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants