Skip to content

Commit

Permalink
refactor: rename tasks-as-tags to tags-as-tasks and tasks-as-tags-reg…
Browse files Browse the repository at this point in the history
…ex to tags-as-tasks-regex
  • Loading branch information
gabor-boros committed Oct 11, 2021
1 parent 3d9c7be commit 180126b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
14 changes: 7 additions & 7 deletions cmd/root.go
Expand Up @@ -119,8 +119,8 @@ func initCommonFlags() {
rootCmd.Flags().StringSliceP("table-sort-by", "", []string{printer.ColumnStart, printer.ColumnProject, printer.ColumnTask, printer.ColumnSummary}, fmt.Sprintf("sort table by column %v", printer.Columns))
rootCmd.Flags().StringSliceP("table-hide-column", "", []string{}, fmt.Sprintf("hide table column %v", printer.HideableColumns))

rootCmd.Flags().BoolP("tasks-as-tags", "", false, "treat tags matching the value of tasks-as-tags-regex as tasks")
rootCmd.Flags().StringP("tasks-as-tags-regex", "", "", "regex of the task pattern")
rootCmd.Flags().BoolP("tags-as-tasks", "", false, "treat tags matching the value of tags-as-tasks-regex as tasks")
rootCmd.Flags().StringP("tags-as-tasks-regex", "", "", "regex of the task pattern")

rootCmd.Flags().BoolP("round-to-closest-minute", "", false, "round time to closest minute")
rootCmd.Flags().BoolP("force-billed-duration", "", false, "treat every second spent as billed")
Expand Down Expand Up @@ -158,11 +158,11 @@ func validateFlags() {
cobra.CheckErr(fmt.Sprintf("\"%s\" is not part of the supported targets %v\n", target, targets))
}

if viper.GetBool("tasks-as-tags") {
tasksAsTagsRegex := viper.GetString("tasks-as-tags-regex")
if viper.GetBool("tags-as-tasks") {
tasksAsTagsRegex := viper.GetString("tags-as-tasks-regex")

if tasksAsTagsRegex == "" {
cobra.CheckErr("tasks-as-tags-regex cannot be empty if tasks-as-tags is set")
cobra.CheckErr("tags-as-tasks-regex cannot be empty if tags-as-tasks is set")
}

_, err := regexp.Compile(tasksAsTagsRegex)
Expand Down Expand Up @@ -194,8 +194,8 @@ func getClientOpts(urlFlag string, usernameFlag string, passwordFlag string, tok
HTTPClient: http.DefaultClient,
TokenHeader: tokenHeader,
},
TasksAsTags: viper.GetBool("tasks-as-tags"),
TasksAsTagsRegex: viper.GetString("tasks-as-tags-regex"),
TagsAsTasks: viper.GetBool("tags-as-tasks"),
TagsAsTasksRegex: viper.GetString("tags-as-tasks-regex"),
}

baseURL, err := url.Parse(viper.GetString(urlFlag))
Expand Down
14 changes: 7 additions & 7 deletions internal/pkg/client/client.go
Expand Up @@ -45,18 +45,18 @@ type HTTPClientOptions struct {
// using BaseClientOpts.
type BaseClientOpts struct {
HTTPClientOptions
// TasksAsTags defines to use tag names to determine the task.
// Using TasksAsTags can be useful if the user's workflow involves
// TagsAsTasks defines to use tag names to determine the task.
// Using TagsAsTasks can be useful if the user's workflow involves
// splitting activity across multiple tasks, or when the user has no option
// to set multiple tasks for a single activity.
//
// This option must be used in conjunction with TasksAsTagsRegex option.
TasksAsTags bool
// TasksAsTagsRegex sets the regular expression used for extracting tasks
// This option must be used in conjunction with TagsAsTasksRegex option.
TagsAsTasks bool
// TagsAsTasksRegex sets the regular expression used for extracting tasks
// from the list of tags.
//
// This option must be used in conjunction with TasksAsTags option.
TasksAsTagsRegex string
// This option must be used in conjunction with TagsAsTasks option.
TagsAsTasksRegex string
}

// FetchOpts specifies the only options for Fetchers.
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/client/clockify/clockify.go
Expand Up @@ -103,7 +103,7 @@ func (c *clockifyClient) getSearchURL(user string, params *WorklogSearchParams)
}

func (c *clockifyClient) splitEntry(entry FetchEntry, bd time.Duration, ubd time.Duration) (*[]worklog.Entry, error) {
r, err := regexp.Compile(c.opts.TasksAsTagsRegex)
r, err := regexp.Compile(c.opts.TagsAsTasksRegex)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *clockifyClient) FetchEntries(ctx context.Context, opts *client.FetchOpt
billableDuration = 0
}

if c.opts.TasksAsTags && len(entry.Tags) > 0 {
if c.opts.TagsAsTasks && len(entry.Tags) > 0 {
pageEntries, err := c.splitEntry(entry, billableDuration, unbillableDuration)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/client/clockify/clockify_test.go
Expand Up @@ -356,8 +356,8 @@ func TestClockifyClient_FetchEntries_TasksAsTags(t *testing.T) {
clockifyClient := clockify.NewClient(&clockify.ClientOpts{
BaseClientOpts: client.BaseClientOpts{
HTTPClientOptions: *httpClientOpts,
TasksAsTags: true,
TasksAsTagsRegex: `^TASK\-\d+$`,
TagsAsTasks: true,
TagsAsTasksRegex: `^TASK\-\d+$`,
},
Workspace: "marvel-studios",
})
Expand Down
25 changes: 25 additions & 0 deletions www/docs/sources/clockify.md
@@ -0,0 +1,25 @@
Source documentation for [Clockify](https://clockify.me/).

## CLI flags

```plaintext
Flags:
--clockify-api-key string set the API key
--clockify-url string set the base URL
--clockify-workspace string set the workspace ID
```

## Configuration options

| Config option | Kind | Description | Example |
|--------------------|--------|------------------------------------------------------------|---------------------------------------|
| clockify-url | string | URL for the Clockify installation without a trailing slash | clockify-url = "https://clockify.me" |
| clockify-api-key | string | API key gathered from Clockify[^1] | clockify-api-key = "<API KEY>" |
| clockify-workspace | string | Clockify workspace ID[^2] | clockify-workspace = "<WORKSPACE ID>" |

## Limitations

* It is not possible to filter for projects when fetching, though it is a [planned](https://github.com/gabor-boros/minutes/issues/1) feature.

[^1]: As described in the [API documentation](https://clockify.me/developers-api), visit the [settings](https://clockify.me/user/settings) page to get your API token.
[^2]: To get your workspace ID, navigate to workspace settings and copy the ID from the URL.

0 comments on commit 180126b

Please sign in to comment.