drone/internal/gitrpc/server.go
Johannes Batzill 91a75ed601 Add GetContent and ListCommits APIs, Fix DefaultBranch support (#32)
Adds the following:
- Add GetContent API (with gitrpc, proto, gitadapter changes)
- Add ListCommits API (with gitrpc, proto, gitadapter changes)
- DefaultBranch (to repo table in DB, update branch in git-repo, have default value in config)
2022-10-17 00:14:31 -07:00

53 lines
1.1 KiB
Go

// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
package gitrpc
import (
"net"
"code.gitea.io/gitea/modules/setting"
"github.com/harness/gitness/internal/gitrpc/rpc"
"google.golang.org/grpc"
)
type Server struct {
*grpc.Server
Bind string
}
// TODO: this wiring should be done by wire.
func NewServer(bind string, gitRoot string) (*Server, error) {
// TODO: should be subdir of gitRoot? What is it being used for?
setting.Git.HomePath = "home"
adapter, err := newGiteaAdapter()
if err != nil {
return nil, err
}
s := grpc.NewServer()
store := newLocalStore()
repoService, err := newRepositoryService(adapter, store, gitRoot)
if err != nil {
return nil, err
}
rpc.RegisterRepositoryServiceServer(s, repoService)
return &Server{
Server: s,
Bind: bind,
}, nil
}
func (s *Server) Start() error {
lis, err := net.Listen("tcp", s.Bind)
if err != nil {
return err
}
return s.Server.Serve(lis)
}
func (s *Server) Stop() error {
s.Server.GracefulStop()
return nil
}