mirror of
https://github.com/harness/drone.git
synced 2025-05-05 04:30:50 +08:00

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)
53 lines
1.1 KiB
Go
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
|
|
}
|