From 194f180cbc2cdf8f739b83296e26ea8805d2c122 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 15:21:55 +0200 Subject: http_test.go: Skip Login() test Because it makes a network request. I originally wrote this to test the Login function while developing so it wasn't a big deal, but we really don't want to run this type of test in normal situations. --- timetask/http_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/timetask/http_test.go b/timetask/http_test.go index c54617f..604c3c3 100644 --- a/timetask/http_test.go +++ b/timetask/http_test.go @@ -17,6 +17,8 @@ func init() { } func TestLogin(t *testing.T) { + t.Skip("No requests") + response, err := Login(username, password) if err != nil { t.Fatal(err) -- cgit v1.2.3 From b9c75fc559a5d79042e419cba8a9b5a4546c9b6d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 15:26:16 +0200 Subject: Remove generator.go, templates/ directory These are not needed in the new world where we only submit a single time entry at a time and entry parameters are filled in on the command line. My guess is we'll likely have some sort of generator in the future to create the initial `config.toml` file, but that won't contain any logic-based data. My guess is we'll probably be able to just stick it in a template string right inside a *.go file. --- templates/timesheet.yml.tmpl | 11 ---------- templates/weekly_timesheet.yml.tmpl | 3 --- timetask/generator.go | 44 ------------------------------------- 3 files changed, 58 deletions(-) delete mode 100644 templates/timesheet.yml.tmpl delete mode 100644 templates/weekly_timesheet.yml.tmpl delete mode 100644 timetask/generator.go diff --git a/templates/timesheet.yml.tmpl b/templates/timesheet.yml.tmpl deleted file mode 100644 index 1930b09..0000000 --- a/templates/timesheet.yml.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -{{- define "timesheet" -}} -- client: {{.Client}} - project: {{.Project}} - module: {{.Module}} - task: {{.Task}} - work_type: {{.WorkType}} - date: {{.Date.Format "02/01/06"}} - time: {{.Time}} - billable: {{.Billable}} - description: {{.Description}} -{{ end -}} diff --git a/templates/weekly_timesheet.yml.tmpl b/templates/weekly_timesheet.yml.tmpl deleted file mode 100644 index 0ea6582..0000000 --- a/templates/weekly_timesheet.yml.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -{{- range . -}} - {{- template "timesheet" . -}} -{{- end -}} diff --git a/timetask/generator.go b/timetask/generator.go deleted file mode 100644 index 5d0fa7f..0000000 --- a/timetask/generator.go +++ /dev/null @@ -1,44 +0,0 @@ -package timetask - -import ( - "io" - "log" - "text/template" - "time" - - "github.com/olebedev/when" - "github.com/olebedev/when/rules/common" - "github.com/olebedev/when/rules/en" -) - -func GenerateWeeklyTimesheet(wr io.Writer, defaults TimeEntry) { - w := when.New(nil) - w.Add(en.All...) - w.Add(common.All...) - - monday, err := w.Parse("last monday", time.Now()) - if err != nil { - log.Panic(err) - } - - time_entries := []TimeEntry{} - day := monday.Time - for i := 1; i <= 5; i++ { - time_entries = append(time_entries, defaults) - time_entries[len(time_entries) - 1].Date = day - day = day.AddDate(0, 0, 1) // Add 1 day - } - - t, err := template.ParseFiles( - "templates/weekly_timesheet.yml.tmpl", - "templates/timesheet.yml.tmpl", - ) - if err != nil { - log.Panic(err) - } - - err = t.Execute(wr, time_entries) - if err != nil { - log.Panic(err) - } -} -- cgit v1.2.3 From 72cfd2966b0de3ae96a37005848087055c4b944a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 15:30:00 +0200 Subject: Move 'fields.go' to 'project.go' Get rid of all the old commented Fields code. It's no longer used and is no longer relevant. Furthermore, since the only thing left in this file is the `Project` struct, rename the file to 'project.go'. --- timetask/fields.go | 94 ----------------------------------------------------- timetask/project.go | 10 ++++++ 2 files changed, 10 insertions(+), 94 deletions(-) delete mode 100644 timetask/fields.go create mode 100644 timetask/project.go diff --git a/timetask/fields.go b/timetask/fields.go deleted file mode 100644 index 9f7aa99..0000000 --- a/timetask/fields.go +++ /dev/null @@ -1,94 +0,0 @@ -package timetask - -// import "fmt" - -// type Client struct { -// ID int -// Name string -// Projects []Project -// } - -// type Project struct { -// ID int -// Name string -// Modules []Module -// Tasks []Task -// WorkTypes []WorkType `yaml:"work_types"` -// } - -type Project struct { - Client int - Project int - Module int - Task int - WorkType int `toml:"work_type"` - Billable bool -} - -// type Module struct { -// ID int -// Name string -// } -// type Task struct { -// ID int -// Name string -// } -// type WorkType struct { -// ID int -// Name string -// } -// -// type Fields struct { -// PersonID int `yaml:"person_id"` -// Clients []Client -// } -// -// func (f *Fields) ClientByName(client_name string) (*Client, error) { -// for _, client := range f.Clients { -// if client.Name == client_name { -// return &client, nil -// } -// } -// -// return nil, fmt.Errorf("Client %s not found", client_name) -// } -// -// func (c *Client) ProjectByName(project_name string) (*Project, error) { -// for _, project := range c.Projects { -// if project.Name == project_name { -// return &project, nil -// } -// } -// -// return nil, fmt.Errorf("Project %s not found", project_name) -// } -// -// func (p *Project) ModuleByName(module_name string) (*Module, error) { -// for _, module := range p.Modules { -// if module.Name == module_name { -// return &module, nil -// } -// } -// -// return nil, fmt.Errorf("Module %s not found", module_name) -// } -// -// func (p *Project) TaskByName(task_name string) (*Task, error) { -// for _, task := range p.Tasks { -// if task.Name == task_name { -// return &task, nil -// } -// } -// -// return nil, fmt.Errorf("Task %s not found", task_name) -// } -// -// func (p *Project) WorkTypeByName(work_type_name string) (*WorkType, error) { -// for _, work_type := range p.WorkTypes { -// if work_type.Name == work_type_name { -// return &work_type, nil -// } -// } -// -// return nil, fmt.Errorf("Work type %s not found", work_type_name) -// } diff --git a/timetask/project.go b/timetask/project.go new file mode 100644 index 0000000..b8fe5c7 --- /dev/null +++ b/timetask/project.go @@ -0,0 +1,10 @@ +package timetask + +type Project struct { + Client int + Project int + Module int + Task int + WorkType int `toml:"work_type"` + Billable bool +} -- cgit v1.2.3 From 10b741fb0c8e9c61647ea8ff977d6242fc86656e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 15:35:15 +0200 Subject: Run gofmt on all project files --- main.go | 2 +- timetask/http.go | 1 - timetask/time_entry.go | 18 +++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 3a343b5..3111dfe 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ type Config struct { Username string PasswordCmd string `toml:"password_cmd"` } - Profile timetask.Profile + Profile timetask.Profile Projects map[string]timetask.Project } diff --git a/timetask/http.go b/timetask/http.go index 736fcfb..8e7de70 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -62,7 +62,6 @@ func SubmitTimeEntry( return resp, nil } - func buildSubmissionParams(time_entry TimeEntry) url.Values { v := url.Values{} diff --git a/timetask/time_entry.go b/timetask/time_entry.go index 161de3e..ff0ad1f 100644 --- a/timetask/time_entry.go +++ b/timetask/time_entry.go @@ -23,15 +23,15 @@ func NewTimeEntry( description string, ) TimeEntry { return TimeEntry{ - PersonID: profile.PersonID, - Client: project.Client, - Project: project.Project, - Module: project.Module, - Task: project.Task, - WorkType: project.WorkType, - Date: date, - Time: time, - Billable: project.Billable, + PersonID: profile.PersonID, + Client: project.Client, + Project: project.Project, + Module: project.Module, + Task: project.Task, + WorkType: project.WorkType, + Date: date, + Time: time, + Billable: project.Billable, Description: description, } } -- cgit v1.2.3 From e439f382fd4bfed4cb547ca59fc0d679658457d4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 15:36:27 +0200 Subject: main.go;http.go: Remove commented unused imports --- main.go | 2 -- timetask/http.go | 3 --- 2 files changed, 5 deletions(-) diff --git a/main.go b/main.go index 3111dfe..2974434 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,8 @@ package main import ( - // "fmt" "io/ioutil" "log" - // "os" "time" "github.com/teddywing/timetasker/timetask" diff --git a/timetask/http.go b/timetask/http.go index 8e7de70..6e73276 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -1,13 +1,10 @@ package timetask import ( - // "fmt" - // "log" "net/http" "net/http/cookiejar" "net/url" "strconv" - // "strings" "golang.org/x/net/publicsuffix" ) -- cgit v1.2.3 From 573df442661c9d0794688e1da98f1ef966ef6265 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 15:37:23 +0200 Subject: main.go: Remove old commented code This code was used for the old multiple time entry submission version of this program. Remove it now that the program only submits single time entries. We'll have similar argument handling code for user data, and the time entry submission code is already present here. --- main.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/main.go b/main.go index 2974434..41245db 100644 --- a/main.go +++ b/main.go @@ -53,29 +53,6 @@ func main() { defer resp.Body.Close() body, err = ioutil.ReadAll(resp.Body) log.Println(string(body)) - - // if len(os.Args) == 1 { - // fmt.Println("Not enough arguments") - // os.Exit(1) - // } - // - // file_path := os.Args[len(os.Args)-1] - // file, err := ioutil.ReadFile(file_path) - // if err != nil { - // log.Println(err) - // } - - // time_entries := []timetask.TimeEntry{} - // err = yaml.Unmarshal(file, &time_entries) - // if err != nil { - // log.Println(err) - // } - // - // log.Printf("%+v", time_entries) - - // timetask.SubmitTimeEntries(config.Fields, time_entries) - - // timetask.GenerateWeeklyTimesheet(os.Stdout, config.Defaults) } func loadConfig() { -- cgit v1.2.3