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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GITHUB_TOKEN=token
27 changes: 27 additions & 0 deletions Dockerfile.buf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use an official Golang image
FROM golang:1.24 AS buf-builder

# Install dependencies and clean up unnecessary package
# lists after running apt-get update and installing packages.
RUN apt-get update && apt-get install -y curl unzip && rm -rf /var/lib/apt/lists/*

# Set Protobuf version
ENV PROTOC_VERSION=30.2

# Install buf
RUN curl -sSL https://github.com/bufbuild/buf/releases/latest/download/buf-Linux-x86_64 \
-o /usr/local/bin/buf && chmod +x /usr/local/bin/buf

# Set environment variables for Go modules
ENV GOPROXY=https://proxy.golang.org,direct
ENV GO111MODULE=on
ENV PATH="/go/bin:$PATH"

# Install protoc-gen-go and protoc-gen-go-grpc
RUN go install google.golang.org/protobuf/cmd/[email protected] && \
go install google.golang.org/grpc/cmd/[email protected]

WORKDIR /app

# Copy protobuf files
COPY buf.gen.yaml buf.gen.yaml
35 changes: 35 additions & 0 deletions Dockerfile.server
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Use an official Golang image for building
FROM golang:1.24 AS builder

# Set working directory
WORKDIR /app

# Copy Go modules and dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy the entire source code
COPY . .

# Build the Go application statically
RUN go build -o server ./server/server.go

# Use a minimal runtime image
FROM debian:bookworm-slim
# Install CA certificates
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy the compiled binary from the builder stage
COPY --from=builder /app/server .

# Ensure binary is executable
RUN chmod +x ./server

# Expose required ports
EXPOSE 8080

# Run the server
CMD ["./server"]
75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,73 @@
# weaveGitHubSearchService
Build a service using gRPC that builds on top of the GitHub API to perform queries for the provided search phrase and allows for optional filtering down to the user level. You’ll return the file URL and the repo it was found in.
### Github Search Service
Build a service using gRPC that builds on top of the GitHub API to perform queries for the
provided search phrase and allows for optional filtering down to the user level. You’ll return the
file URL and the repo it was found in.
This is the API you’ll use to perform the GitHub search:
```https://docs.github.com/en/rest/reference/search```

This is the API spec that should be implemented:

service GithubSearchService {
rpc Search(SearchRequest) returns (SearchResponse);
}

message SearchRequest {
string search_term = 1;
string user = 2;
}

message SearchResponse {
repeated Result results = 1;
}

message Result {
string file_url = 1;
string repo = 2;
}
Instructions
1. Create a new, public GitHub repository with only a README
2. Create a new branch and do all your work in that branch
3. Create a PR back into the main branch and send in the URL to the Pull Request

## Prerequisites
### Mac:
1. Make and Git: `brew install git make`
2. Docker: `brew install docker`
3. Ensure Docker is running:
```sh
open -a Docker
docker info
```
If Docker is not running, start the Docker daemon manually.

### Linux:
1. Make and Git: `sudo apt-get install git make`
2. Docker: `sudo apt-get install docker`
3. Ensure Docker is running:
```sh
sudo systemctl start docker
sudo systemctl enable docker # Optional: Start Docker on boot
sudo docker info

## Setup Instructions:
1. Clone the repository: `git clone [email protected]:Thesohan/weaveGitHubSearchService.git`
3. Generate Protobuf code (if modified): `make generate`
4. Update environement variables file `.env`: `GITHUB_API_TOKEN=<your_github_token>`

## Running the Service
1. To start the gRPC server and client: `make run`
2. It will ask you to `Enter username`: Enter the username for user level search result (optional)
3. It will ask you to `Enter search term`: Enter the search term to search in the GitHub repository (required)

## Running the Tests
1. To execute a test request, run: `make test`

## Troubleshooting
1. Authentication Errors: Ensure you have set `GITHUB_API_TOKEN` with a valid GitHub token in your env variable.
2. Ensure docker is up and running

### Future Improvements
1. Support for configurable logging
2. Support for pagination
3. Secret management for API tokens
18 changes: 18 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Specify the version of the configuration file
version: v1

# Enable or disable managed mode
managed:
enabled: true

# List of plugins to use for code generation
plugins:
# Go plugin for generating Go code
- name: go
out: gen/go # Output directory for generated Go code
opt: paths=source_relative # The generated .pb.go files are placed relative to the .proto file’s directory instead of following the full import path

# Go gRPC plugin for generating gRPC code in Go
- name: go-grpc
out: gen/go
opt: paths=source_relative
Loading