2020-09-19 22:00:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-04-25 10:53:45 +00:00
|
|
|
"fmt"
|
2020-09-19 22:00:34 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
2022-05-29 12:12:16 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-09-20 20:04:09 +00:00
|
|
|
"github.com/thegeeklab/drone-github-comment/plugin"
|
2022-05-29 12:12:16 +00:00
|
|
|
"github.com/thegeeklab/drone-plugin-lib/v2/urfave"
|
2022-04-25 10:53:45 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-09-19 22:00:34 +00:00
|
|
|
)
|
|
|
|
|
2022-04-25 10:53:45 +00:00
|
|
|
var (
|
|
|
|
BuildVersion = "devel"
|
|
|
|
BuildDate = "00000000"
|
|
|
|
)
|
2020-09-19 22:00:34 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
settings := &plugin.Settings{}
|
|
|
|
|
|
|
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
2022-04-25 10:53:45 +00:00
|
|
|
_ = godotenv.Overload("/run/drone/env")
|
|
|
|
}
|
|
|
|
|
|
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
|
|
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "drone-github-comment",
|
|
|
|
Usage: "handle comments to github issues or pull requests",
|
2022-04-25 10:53:45 +00:00
|
|
|
Version: BuildVersion,
|
2022-05-29 20:04:57 +00:00
|
|
|
Flags: append(settingsFlags(settings, urfave.FlagsPluginCategory), urfave.Flags()...),
|
2020-09-19 22:00:34 +00:00
|
|
|
Action: run(settings),
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2022-05-29 12:12:16 +00:00
|
|
|
logrus.Fatal(err)
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(settings *plugin.Settings) cli.ActionFunc {
|
|
|
|
return func(ctx *cli.Context) error {
|
|
|
|
urfave.LoggingFromContext(ctx)
|
|
|
|
|
|
|
|
plugin := plugin.New(
|
|
|
|
*settings,
|
|
|
|
urfave.PipelineFromContext(ctx),
|
|
|
|
urfave.NetworkFromContext(ctx),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := plugin.Validate(); err != nil {
|
2022-05-29 12:12:16 +00:00
|
|
|
return fmt.Errorf("validation failed: %w", err)
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := plugin.Execute(); err != nil {
|
2022-05-29 12:12:16 +00:00
|
|
|
return fmt.Errorf("execution failed: %w", err)
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|