-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sumner Evans <me@sumnerevans.com>
- Loading branch information
1 parent
7bf3a4e
commit ee889ab
Showing
7 changed files
with
195 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sumnerevans/tracktime/lib" | ||
"github.com/sumnerevans/tracktime/synchroniser" | ||
) | ||
|
||
type Sync struct { | ||
Month *lib.Month `arg:"positional" help:"the month to synchronize time entries for (accepted formats: 01, 1, Jan, January, 2019-01)" default:"this month"` | ||
} | ||
|
||
func (s *Sync) Run(config *lib.Config) error { | ||
for _, synchroniser := range synchroniser.Synchronisers { | ||
go synchroniser.Sync(context.Background(), nil, nil, *s.Month) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package lib | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type Month struct { | ||
year int | ||
month time.Month | ||
} | ||
|
||
func ThisMonth() Month { | ||
now := time.Now().Local() | ||
return Month{year: now.Year(), month: now.Month()} | ||
} | ||
|
||
func (d *Month) UnmarshalText(text []byte) error { | ||
now := time.Now().Local() | ||
switch string(text) { | ||
case "this month", "thismonth": | ||
d.year = now.Year() | ||
d.month = now.Month() | ||
default: | ||
// TODO | ||
return fmt.Errorf("Invalid date '%s'.", string(text)) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package synchroniser | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/sumnerevans/tracktime/lib" | ||
) | ||
|
||
type GitHubSynchroniser struct { | ||
Config lib.GitHubSyncConfig | ||
} | ||
|
||
func (gh *GitHubSynchroniser) Name() string { return "GitHub" } | ||
|
||
func (gh *GitHubSynchroniser) Init(config lib.SyncConfig) { | ||
gh.Config = config.GitHub | ||
} | ||
|
||
func (gh *GitHubSynchroniser) Sync(ctx context.Context, aggregatedTime, syncedTime AggregatedTime, month lib.Month) (AggregatedTime, error) { | ||
return aggregatedTime, nil | ||
} | ||
|
||
func (gh *GitHubSynchroniser) cleanTaskID(taskID string) string { | ||
return strings.TrimPrefix(taskID, "#") | ||
} | ||
|
||
func (gh *GitHubSynchroniser) GetFormattedTaskID(entry *lib.TimeEntry) string { | ||
if (entry.Type != "github" && entry.Type != "gh") || entry.TaskID == "" { | ||
return "" | ||
} | ||
|
||
return fmt.Sprintf("#%s", gh.cleanTaskID(entry.TaskID)) | ||
} | ||
|
||
func (gh *GitHubSynchroniser) GetTaskLink(entry *lib.TimeEntry) string { | ||
var owner, project string | ||
projectParts := strings.Split(entry.Project, "/") | ||
if len(projectParts) == 1 { | ||
if gh.Config.Username == "" { | ||
return "" | ||
} | ||
owner = gh.Config.Username | ||
project = projectParts[0] | ||
} else if len(projectParts) == 2 { | ||
owner = projectParts[0] | ||
project = projectParts[1] | ||
} else { | ||
return "" | ||
} | ||
// Always link to /issues/ because it will redirect to /pull/ if necessary. | ||
return fmt.Sprintf("%s/%s/%s/issues/%s", gh.Config.RootURI, owner, project, gh.cleanTaskID(entry.TaskID)) | ||
} | ||
|
||
func (gh *GitHubSynchroniser) GetTaskDescription(ctx context.Context, entry *lib.TimeEntry) string { | ||
return "" | ||
} | ||
|
||
func init() { | ||
Synchronisers = append(Synchronisers, &GitHubSynchroniser{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package synchroniser | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/sumnerevans/tracktime/lib" | ||
) | ||
|
||
type AggregatedTimeKey struct { | ||
Type lib.TimeEntryType | ||
Project string | ||
TaskID string | ||
} | ||
|
||
type AggregatedTime map[AggregatedTimeKey]time.Duration | ||
|
||
type Synchroniser interface { | ||
Init(config lib.SyncConfig) | ||
Name() string | ||
Sync(ctx context.Context, aggregatedTime, syncedTime AggregatedTime, month lib.Month) (AggregatedTime, error) | ||
GetFormattedTaskID(entry *lib.TimeEntry) string | ||
GetTaskLink(entry *lib.TimeEntry) string | ||
GetTaskDescription(ctx context.Context, entry *lib.TimeEntry) string | ||
} | ||
|
||
var Synchronisers []Synchroniser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters