controller

package
v0.0.0-...-7481685 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cmd = &cobra.Command{
		Use:     "upload-worklogs /path/to/file.yml",
		Aliases: []string{"uw"},
		Short:   "Upload daily worklogs into Jira from JSON or YAML/YML files",
		Long: "Upload daily worklogs into Jira from JSON or YAML/YML files. " +
			"Only logs with the issue_key and the tag work are uploaded.",
		Args: func(cmd *cobra.Command, args []string) error {
			argsVal := NewArgsValidator(args)
			if err := argsVal.Validate(); err != nil {
				return err
			}

			return nil
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			path := args[0]
			errPath := fmt.Errorf("\nPath: %s\n", path)
			fileProvider := supportedExtensions[filepath.Ext(path)].provider
			location, errLocation := time.LoadLocation(os.Getenv("TZ"))
			if errLocation != nil {
				return errLocation
			}

			worklogs, errLoad := fileProvider.LoadAndValidate(path, location)
			if errLoad != nil {
				return fmt.Errorf("%w %w", errLoad, errPath)
			}

			if push {
				uploader := repo2.NewJiraUploader(
					os.Getenv("ATLASSIAN_URL"),
					os.Getenv("ATLASSIAN_USERNAME"),
					os.Getenv("ATLASSIAN_TOKEN"),
				)
				errUpload := upload(uploader, worklogs, context.Background())
				if errUpload != nil {
					return fmt.Errorf("%w %w", errUpload, errPath)
				}
			} else {
				slog.Info(fmt.Sprintf("[%v] READ ONLY", worklogs.Date))
				for _, worklog := range worklogs.Worklogs {
					slog.Info(worklog.GetReport(worklogs.Date))
				}
			}

			return nil
		},
	}
)

Functions

This section is empty.

Types

type ArgsValidator

type ArgsValidator struct {
	// contains filtered or unexported fields
}

func NewArgsValidator

func NewArgsValidator(args []string) *ArgsValidator

func (*ArgsValidator) Validate

func (argsVal *ArgsValidator) Validate() error

type FileProvider

type FileProvider interface {
	LoadAndValidate(path string, location *time.Location) (*entity.DailyWorklogs, error)
}

type Uploader

type Uploader interface {
	Upload(dailyWorklogs *entity.DailyWorklogs, ctx context.Context) error
}

Jump to

Keyboard shortcuts

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