mirror of
https://github.com/harness/drone.git
synced 2025-05-06 19:10:34 +08:00

This change is adding git server hook components: - githook CLI implementation - githook api handlers - githook controler
37 lines
849 B
Go
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)
|
|
}
|