Skip to content

feat: Github code search api integration using GO GRPC #1

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

Merged
merged 6 commits into from
Apr 10, 2025

Conversation

Thesohan
Copy link
Owner

@Thesohan Thesohan commented Mar 21, 2025

What?

  1. Github search code api integration using GRPC.
  2. Added test cases for GitHub search.
  3. Created a client and server to run the code.
  4. Used Makefile for saving all the used commands
  5. Retry mechanism in case of external API failure
  6. Docker setup to run it locally
    Local Test Result:
Screenshot 2025-03-21 at 11 11 13 AM

@Thesohan Thesohan added the enhancement New feature or request label Mar 21, 2025
README.md Outdated
Comment on lines 36 to 45
1. Ensure you have the following installed on your system:
Go (1.23.3) - Download & Install (https://go.dev/dl/)

2. Protocol Buffers Compiler (protoc) - `brew install protobuf`

3. Buf (for Protobuf management) - Install using Homebrew: `brew install bufbuild/buf/buf`

4. Git - Install using Homebrew: `brew install git`

5. Make - Install using Homebrew: `brew install make`

Choose a reason for hiding this comment

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

This assumes the user is on OSX. You should include instructions for Linux users.

Choose a reason for hiding this comment

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

Also, why are there extra newlines between list items for only this list?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'll use docker to avoid the local setup challenges and make local setup consistent regardless of the OS.
Also, I'll remove the newlines if not required.

README.md Outdated
3. To execute a test request, run: `make test`

## Troubleshooting
1. Missing Dependencies: Run go mod tidy to install missing Go dependencies.

Choose a reason for hiding this comment

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

Suggested change
1. Missing Dependencies: Run go mod tidy to install missing Go dependencies.
1. Missing Dependencies: Run `go mod tidy` to install missing Go dependencies.

README.md Outdated

## Troubleshooting
1. Missing Dependencies: Run go mod tidy to install missing Go dependencies.
2. Protobuf Compilation Issues: Ensure protoc and buf are correctly installed.

Choose a reason for hiding this comment

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

Suggested change
2. Protobuf Compilation Issues: Ensure protoc and buf are correctly installed.
2. Protobuf Compilation Issues: Ensure `protoc` and `buf` are correctly installed.

README.md Outdated
## Troubleshooting
1. Missing Dependencies: Run go mod tidy to install missing Go dependencies.
2. Protobuf Compilation Issues: Ensure protoc and buf are correctly installed.
3. Authentication Errors: Ensure you have set GITHUB_API_TOKEN with a valid GitHub token in your env variable.

Choose a reason for hiding this comment

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

Suggested change
3. Authentication Errors: Ensure you have set GITHUB_API_TOKEN with a valid GitHub token in your env variable.
3. Authentication Errors: Ensure you have set `GITHUB_API_TOKEN` with a valid GitHub token in your env variable.

makefile Outdated
go mod vendor

test:
go test ./...

Choose a reason for hiding this comment

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

Missing trailing newline

Comment on lines 39 to 46
"items": [
{
"html_url": "https://github.com/test/repo/blob/main/file.go",
"repository": {
"full_name": "test/repo"
}
}
]

Choose a reason for hiding this comment

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

This seems to be the same content as in the mock client. You might consider pulling it out into a package const.

Comment on lines 51 to 53
// Set up test environment
os.Setenv("GITHUB_TOKEN", "test-token")
client := NewGitHubClient(mockServer.URL)

Choose a reason for hiding this comment

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

Using an env variable in tests make them brittle and hard/impossible to run concurrently. You may wan to refactor your client to take the token as a parameter instead.

Copy link
Owner Author

Choose a reason for hiding this comment

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

used option pattern to pass token and fetched the default token from environment

Comment on lines 60 to 63
assert.NotNil(t, data)
assert.Len(t, data.Items, 1)
assert.Equal(t, "https://github.com/test/repo/blob/main/file.go", data.Items[0].HTMLURL)
assert.Equal(t, "test/repo", data.Items[0].Repository.FullName)

Choose a reason for hiding this comment

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

assert.DeepEqual is likely a better choice here. It is more readable and comprehensive.

Copy link
Owner Author

Choose a reason for hiding this comment

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

assert doesn't have DeepEqual, i've used assert.EqualValues instead

return fmt.Errorf("API error: %s", resp.Status)
}

return json.NewDecoder(resp.Body).Decode(response)

Choose a reason for hiding this comment

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

This is a really common bug and miss-use with the json package: golang/go#36225

You should rewrite this to not be susceptible to that bug.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I've used json.Unmarshal

Comment on lines 31 to 35
func setHeaders(req *http.Request, headers map[string]string) {
for key, value := range headers {
req.Header.Set(key, value)
}
}

Choose a reason for hiding this comment

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

This function only appears to be used once. You are probably better off just doing this in the once place it is needed instead of factoring it out to a function.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I've removed it

@Thesohan Thesohan merged commit d8a2815 into main Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants