Skip to content

Commit

Permalink
Add an ability to replace the default description pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
coldic3 committed Jun 1, 2024
1 parent 71f6726 commit ebc7045
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Import from file:

Use `--dry-run` option to see the export before being imported.

By default, it takes description from Toggl / CSV file and combines it into Jira issue key and work log description.
Therefore, your descriptions should follow the pattern [^(.*?)\s*(?:\((.*?)\))?$](https://regex101.com/r/YUvRCq/1). For
example these are valid descriptions: `XYZ-8 (resolving conflicts in the PR)`, `XYZ-8`.
If you are not going to follow this pattern, worry not! You can replace the regex with your own with `DESCRIPTION_REGEX`
env variable.

## Troubleshooting

### Where can I find these user, client and workspace IDs in Toggl?
Expand Down
Binary file modified bin/jira-worklogs-importer
Binary file not shown.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func main() {
togglUserId := os.Getenv("TOGGL_USER_ID")
togglClientId := os.Getenv("TOGGL_CLIENT_ID")
togglWorkspaceId := os.Getenv("TOGGL_WORKSPACE_ID")
descriptionRegex, exists := os.LookupEnv("DESCRIPTION_REGEX")
if !exists {
descriptionRegex = `^(.*?)\s*(?:\((.*?)\))?$`
}

if csvFilePathToImport != "" {
records, err = importer.ReadCSVFile(csvFilePathToImport)
Expand Down Expand Up @@ -93,7 +97,7 @@ func main() {
continue
}

issueIdOrKey, contentText, err := toggl.ConvertToIssueIdAndContextText(description)
issueIdOrKey, contentText, err := toggl.ConvertToIssueIdAndContextText(description, descriptionRegex)
if err != nil {
fmt.Println(fmt.Sprintln(err))
continue
Expand Down
4 changes: 2 additions & 2 deletions toggl/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func CheckDateFormat(date string) bool {
return err == nil
}

func ConvertToIssueIdAndContextText(text string) (string, string, error) {
re := regexp.MustCompile(`^(.*?)\s*(?:\((.*?)\))?$`)
func ConvertToIssueIdAndContextText(text string, regex string) (string, string, error) {
re := regexp.MustCompile(regex)
matches := re.FindStringSubmatch(text)

if len(matches) < 3 {
Expand Down

0 comments on commit ebc7045

Please sign in to comment.