drone/cli/operations/hooks/pre-receive.go
Johannes Batzill 5cb824debd [feat]: Add Git Server Hook Support (#159)
This change is adding git server hook components:
- githook CLI implementation
- githook api handlers
- githook controler
2023-01-06 12:15:11 -08:00

37 lines
849 B
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 hooks
import (
"context"
"fmt"
"time"
"github.com/harness/gitness/internal/githook"
"gopkg.in/alecthomas/kingpin.v2"
)
type preReceiveCommand struct{}
func (c *preReceiveCommand) run(*kingpin.ParseContext) error {
cli, err := githook.NewCLI()
if err != nil {
return fmt.Errorf("failed to create githook cli: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
return cli.PreReceive(ctx)
}
func registerPreReceive(app *kingpin.CmdClause) {
c := &preReceiveCommand{}
app.Command("pre-receive", "hook that is executed before any reference of the push is updated").
Action(c.run)
}