githubcmd

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GitHubSyncCmd = &cobra.Command{
	Use:   "sync [repository|developer]",
	Short: "Sync the latest repositories or developers details from GitHub",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		config.Init()

		action := args[0]
		ctx, stop := context.WithCancel(context.Background())
		db := database.GetInstance(ctx)
		tokenPool := github.NewTokenPool(config.GitHubTokens)
		gh := github.NewClient(tokenPool)

		defer func() {
			err := db.Close()

			if err != nil {
				slog.Error("failed to close db", slog.Any("error", err))
				sentry.CaptureException(err)
			}

			stop()
			sentry.Flush(2 * time.Second)
		}()

		if start != "" {
			_, err := time.Parse(time.DateTime, start)
			if err != nil {
				slog.Error("failed to parse start time", slog.Any("error", err))
				sentry.CaptureException(err)
				return
			}
		}

		endDateTime, err := parseEndDateTimeOption(end)
		if err != nil {
			slog.Error("failed to parse end date time", slog.Any("error", err))
			sentry.CaptureException(err)
			return
		}

		appSignal := make(chan os.Signal, 3)
		signal.Notify(appSignal, os.Interrupt, syscall.SIGTERM)

		go func() {
			<-appSignal
			stop()
		}()

		repositoryRepo := model.NewGhRepositoryRepo(db)
		developerRepo := model.NewDeveloperRepo(db)
		handler := github.NewSyncHandler(repositoryRepo, developerRepo, gh)
		err = handler.Handle(ctx, action, opt.Start(start), opt.End(endDateTime), opt.Limit(limit))

		if err != nil {
			slog.Error("failed to handle sync action", slog.Any("error", err))
			sentry.CaptureException(err)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL