-
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.
- Loading branch information
1 parent
2bf7163
commit f82413e
Showing
17 changed files
with
708 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/bullshitsoftware/youtimetrack/internal/app" | ||
yt "github.com/bullshitsoftware/youtimetrack/internal/pkg/youtrack" | ||
) | ||
|
||
type App interface { | ||
Load() | ||
NewYoutrack() app.Youtrack | ||
} | ||
|
||
var a App = &app.App{} | ||
|
||
func main() { | ||
if len(os.Args) != 4 { | ||
app.ExitOnError(errors.New("invalid arguments number")) | ||
flag.Usage = func() { | ||
fmt.Printf("Usage of %s type issue duration comment:\n", os.Args[0]) | ||
fmt.Println(" - type, work type prefix (e.g., develop)") | ||
fmt.Println(" - issue, issue number (e.g., XY-123)") | ||
fmt.Println(" - duration, spent time in YouTrack format (e.g., 1h 30m)") | ||
fmt.Println(" - comment, work item description (e.g., did something cool)") | ||
} | ||
flag.Parse() | ||
if flag.NArg() != 4 { | ||
flag.Usage() | ||
return | ||
} | ||
|
||
a := app.Default() | ||
err := a.ReadConfig() | ||
app.ExitOnError(err) | ||
typeName := strings.ToLower(os.Args[0]) | ||
types, err := a.Youtrack.WorkItemTypes() | ||
a.Load() | ||
yt := a.NewYoutrack() | ||
|
||
typeName := strings.ToLower(os.Args[1]) | ||
issue := os.Args[2] | ||
duration := os.Args[3] | ||
text := os.Args[4] | ||
|
||
types, err := yt.WorkItemTypes() | ||
app.ExitOnError(err) | ||
var t yt.Type | ||
aTypes := []string{} | ||
for _, i := range types { | ||
s := strings.ToLower(i.Name) | ||
if strings.HasPrefix(s, typeName) { | ||
t = i | ||
break | ||
err = yt.Add(i, issue, duration, text) | ||
app.ExitOnError(err) | ||
fmt.Println("Time tracked") | ||
return | ||
} | ||
aTypes = append(aTypes, i.Name) | ||
} | ||
issue := os.Args[1] | ||
duration := os.Args[2] | ||
text := os.Args[3] | ||
|
||
a.Youtrack.Add(t, issue, duration, text) | ||
fmt.Println("No work type found, available:", strings.Join(aTypes, ", ")) | ||
} |
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,80 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/bullshitsoftware/youtimetrack/internal/app" | ||
"github.com/bullshitsoftware/youtimetrack/internal/pkg/youtrack" | ||
) | ||
|
||
type AppStub struct{} | ||
|
||
func (s *AppStub) Load() {} | ||
|
||
func (s *AppStub) NewYoutrack() app.Youtrack { | ||
return &YoutrackStub{} | ||
} | ||
|
||
type YoutrackStub struct{} | ||
|
||
func (yt *YoutrackStub) WorkItems(start, end time.Time) ([]youtrack.WorkItem, error) { | ||
panic("unexpected call") | ||
} | ||
|
||
func (yt *YoutrackStub) WorkItemTypes() ([]youtrack.Type, error) { | ||
types := []youtrack.Type{ | ||
{ | ||
Id: "123", | ||
Name: "Development", | ||
}, | ||
{ | ||
Id: "456", | ||
Name: "DevOps", | ||
}, | ||
} | ||
|
||
return types, nil | ||
} | ||
|
||
func (yt *YoutrackStub) Add(itemType youtrack.Type, issueId, duration, text string) error { | ||
if itemType.Id != "123" { | ||
panic("unexpected type") | ||
} | ||
|
||
if issueId != "XY-123" { | ||
panic("unexpected issue") | ||
} | ||
|
||
if duration != "1h" { | ||
panic("unexpected dureation") | ||
} | ||
|
||
if text != "did something" { | ||
panic("unexpected text") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Example() { | ||
a = &AppStub{} | ||
|
||
os.Args = []string{"yttadd"} | ||
main() | ||
|
||
os.Args = []string{"yttadd", "deve", "XY-123", "1h", "did something"} | ||
main() | ||
|
||
os.Args = []string{"yttadd", "strange", "XY-123", "1h", "did something"} | ||
main() | ||
|
||
// Output: | ||
// Usage of yttadd type issue duration comment: | ||
// - type, work type prefix (e.g., develop) | ||
// - issue, issue number (e.g., XY-123) | ||
// - duration, spent time in YouTrack format (e.g., 1h 30m) | ||
// - comment, work item description (e.g., did something cool) | ||
// Time tracked | ||
// No work type found, available: Development, DevOps | ||
} |
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,14 @@ | ||
package main | ||
|
||
type AppStub struct{} | ||
|
||
func (s *AppStub) Save() string { | ||
return "/home/john/.config/ytt/config.json" | ||
} | ||
|
||
func Example() { | ||
a = &AppStub{} | ||
main() | ||
|
||
// Output: Created /home/john/.config/ytt/config.json edit it with your favorite text editor | ||
} |
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,82 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/bullshitsoftware/youtimetrack/internal/app" | ||
"github.com/bullshitsoftware/youtimetrack/internal/pkg/calendar" | ||
"github.com/bullshitsoftware/youtimetrack/internal/pkg/youtrack" | ||
) | ||
|
||
type AppStub struct{} | ||
|
||
func (s *AppStub) Load() {} | ||
|
||
func (s *AppStub) NewCalendar() app.Calendar { | ||
return &CalendarStub{} | ||
} | ||
|
||
func (s *AppStub) NewYoutrack() app.Youtrack { | ||
return &YoutrackStub{} | ||
} | ||
|
||
type CalendarStub struct{} | ||
|
||
func (s *CalendarStub) Period(now time.Time) *calendar.Period { | ||
if !now.Equal(time.Date(2007, 1, 2, 3, 4, 5, 0, time.UTC)) { | ||
panic("enexpected now") | ||
} | ||
|
||
return &calendar.Period{ | ||
Start: time.Date(2007, 1, 1, 0, 0, 0, 0, time.UTC), | ||
End: time.Date(2007, 1, 31, 23, 59, 59, 0, time.UTC), | ||
} | ||
} | ||
|
||
func (s *CalendarStub) Calc(start, end time.Time) int { | ||
panic("unexpected call") | ||
} | ||
|
||
type YoutrackStub struct{} | ||
|
||
func (yt *YoutrackStub) WorkItems(start, end time.Time) ([]youtrack.WorkItem, error) { | ||
issue := &youtrack.Issue{IdReadable: "XY-123", Summary: "Do something cool"} | ||
items := []youtrack.WorkItem{ | ||
{ | ||
Issue: issue, | ||
Date: time.Date(2007, 1, 10, 3, 4, 5, 0, time.UTC).UnixMilli(), | ||
Duration: youtrack.Duration{Minutes: 30}, | ||
Type: youtrack.Type{Id: "123", Name: "Development"}, | ||
Text: "did something cool", | ||
}, | ||
{ | ||
Issue: issue, | ||
Date: time.Date(2007, 1, 15, 3, 4, 5, 0, time.UTC).UnixMilli(), | ||
Duration: youtrack.Duration{Minutes: 30}, | ||
Type: youtrack.Type{Id: "321", Name: "DevOps"}, | ||
Text: "opsed something cool", | ||
}, | ||
} | ||
|
||
return items, nil | ||
} | ||
|
||
func (yt *YoutrackStub) WorkItemTypes() ([]youtrack.Type, error) { | ||
panic("unexpected call") | ||
} | ||
|
||
func (yt *YoutrackStub) Add(itemType youtrack.Type, issueId, duration, text string) error { | ||
panic("unexpected call") | ||
} | ||
|
||
func Example() { | ||
a = &AppStub{} | ||
now = time.Date(2007, 1, 2, 3, 4, 5, 0, time.UTC) | ||
main() | ||
|
||
// Output: | ||
// 2007-01-10 0h30m XY-123 Do something cool | ||
// did something cool | ||
// 2007-01-15 0h30m XY-123 Do something cool | ||
// opsed something cool | ||
} |
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
Oops, something went wrong.