Skip to content

Commit

Permalink
Add the "project" option to support many projects
Browse files Browse the repository at this point in the history
  • Loading branch information
coldic3 committed Jul 3, 2024
1 parent ebc7045 commit 1d61181
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.env
.env.*
!.env.dist
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The import file supported is an export file from a [Toggl](https://toggl.com) ap

## Setup

### Basic setup for a single project

1. Create the `.env` file:
```bash
cp .env.dist .env
Expand All @@ -26,6 +28,25 @@ Env variables prefixed with `TOGGL_` are optional if you use an `--import` optio
* `TOGGL_CLIENT_ID`: The client ID in Toggl from whom you want to export your work logs.
* `TOGGL_WORKSPACE_ID`: Your workspace ID in Toggl from whom you want to export your work logs.

### Advanced setup for many project

A very common case is that you want to import your worklogs into different Jira accounts from different Toggle accounts
depending on the project. You can handle it with the `--project` option! We will consider two cases.

#### CASE 1: One Toggl account and many Jira accounts

In this case, you most likely work on many Jira projects and want to import all from your one Toggl account where you
log everything. Let's say you work on two projects `sylius` and `symfony`. In your `.env` define common env variables so
all prefixed with `TOGGL_`. In `.env.sylius` and `.env.symfony` specify env variables specific for your Jira account so
prefixed with `ATLASSIAN_`. Now, if you run the command with `--project="symfony"`, files `.env` and `.env.symfony` will
be used.

#### CASE 2: A different Toggl account and Jira account for each project

Similar to the case above but you leave `.env` empty. Instead of that file, you define all env vars right in
`.env.<your-project-name>`.


## Usage

Import from Toggl:
Expand Down
Binary file modified bin/jira-worklogs-importer
Binary file not shown.
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@ import (
)

func main() {
var project string
var records [][]string
var csvFilePathToImport string
var since string
var until string
var dryRun bool

err := godotenv.Load()
if err != nil {
fmt.Println("Error loading .env file.")
return
}

flag.StringVar(&project, "project", "", "A project name that will load .env.<project-name> file.")
flag.StringVar(&csvFilePathToImport, "import", "", "CSV file path to import.")
flag.StringVar(&since, "since", "", "Import work logs since date. Format YYYY-MM-DD.")
flag.StringVar(&until, "until", "", "Import work logs until date. Format YYYY-MM-DD.")
flag.BoolVar(&dryRun, "dry-run", false, "Dry run. Export work logs but do not import.")
flag.Parse()

err := godotenv.Load(".env")
if err != nil {
fmt.Println("Error loading .env file.")
return
}
if project != "" {
projectEnv := fmt.Sprintf(".env.%s", project)
err = godotenv.Load(projectEnv)
if err != nil {
fmt.Printf("Error loading %s file.\n", projectEnv)
return
}
}

optionsValidationFailed := false

if since == "" {
Expand Down

0 comments on commit 1d61181

Please sign in to comment.