diff --git a/gojira/cli.go b/gojira/cli.go index df22b05..c1fdb97 100644 --- a/gojira/cli.go +++ b/gojira/cli.go @@ -21,7 +21,7 @@ var AppAsciiArt = fmt.Sprintf(""+ " _/ | v%s \n"+ " |__/ \n\n", projectVersion) -var WorkLogsCommand = &cli.Command{ +var WorklogsCommand = &cli.Command{ Name: "worklogs", Usage: "Edit your today's work log", Action: func(c *cli.Context) error { @@ -36,7 +36,7 @@ var WorkLogsCommand = &cli.Command{ }, } -func NewWorkLogIssues() error { +func NewWorklogIssues() error { // goroutine awesomeness var err error startDate, endDate := MonthRange(app.time) @@ -45,7 +45,7 @@ func NewWorkLogIssues() error { } if app.workLogsIssues.startDate != startDate || app.workLogsIssues.endDate != endDate { app.ui.loaderView.Show("Fetching worklogs...") - app.workLogs, err = GetWorkLogs() + app.workLogs, err = GetWorklogs() app.ui.loaderView.Hide() if err != nil { return err @@ -55,19 +55,19 @@ func NewWorkLogIssues() error { } app.workLogsIssues.startDate = startDate app.workLogsIssues.endDate = endDate - app.workLogsIssues.issues = []WorkLogIssue{} + app.workLogsIssues.issues = []WorklogIssue{} waitGroup := sync.WaitGroup{} var errors []error errCh := make(chan error, len(app.workLogs.logs)) for i := range app.workLogs.logs { waitGroup.Add(1) - go func(workLog *WorkLog) { + go func(workLog *Worklog) { issue, err := NewJiraClient().GetIssue(workLog.Issue.Key) if err != nil { errCh <- err // Send the error to the channel. return } - app.workLogsIssues.issues = append(app.workLogsIssues.issues, WorkLogIssue{WorkLog: workLog, Issue: issue}) + app.workLogsIssues.issues = append(app.workLogsIssues.issues, WorklogIssue{Worklog: workLog, Issue: issue}) waitGroup.Done() }(app.workLogs.logs[i]) } @@ -241,7 +241,7 @@ func (issue Issue) LogWork(logTime *time.Time, timeSpent string) error { if err != nil { return err } - if Config.UpdateExistingWorkLog { + if Config.UpdateExistingWorklog { for index, workLog := range todayWorklog { if workLog.Issue.Key == issue.Key { //fmt.Println("Updating existing worklog...") @@ -257,12 +257,12 @@ func (issue Issue) LogWork(logTime *time.Time, timeSpent string) error { } } } - worklog, err := NewWorkLog(issue.Key, logTime, timeSpent) + worklog, err := NewWorklog(issue.Key, logTime, timeSpent) if err != nil { return err } // add this workload to global object app.workLogs.logs = append(app.workLogs.logs, &worklog) - app.workLogsIssues.issues = append(app.workLogsIssues.issues, WorkLogIssue{Issue: issue, WorkLog: &worklog}) + app.workLogsIssues.issues = append(app.workLogsIssues.issues, WorklogIssue{Issue: issue, Worklog: &worklog}) return nil } diff --git a/gojira/config.go b/gojira/config.go index b278cca..4ab97f7 100644 --- a/gojira/config.go +++ b/gojira/config.go @@ -16,7 +16,7 @@ func GetEnv(key string) (env string) { type Configuration struct { JiraUrl, JiraLogin, JiraToken, TempoUrl, TempoToken, JiraAccountId string - UpdateExistingWorkLog bool + UpdateExistingWorklog bool } var Config *Configuration @@ -29,6 +29,6 @@ func PrepareConfig() { JiraAccountId: GetEnv("GOJIRA_JIRA_ACCOUNT_ID"), TempoUrl: "https://api.tempo.io/core/3", TempoToken: GetEnv("GOJIRA_TEMPO_TOKEN"), - UpdateExistingWorkLog: true, + UpdateExistingWorklog: true, } } diff --git a/gojira/dayview.go b/gojira/dayview.go index 5ad6496..0fc6f9c 100644 --- a/gojira/dayview.go +++ b/gojira/dayview.go @@ -91,7 +91,7 @@ func loadWorklogs() { case loadingWorklogs <- true: go func() { defer func() { <-loadingWorklogs }() - err := NewWorkLogIssues() + err := NewWorklogIssues() if err != nil { app.ui.errorView.ShowError(err.Error()) } @@ -116,7 +116,7 @@ func (d *DayView) update() { ) d.worklogList.SetCell(r, TimeSpentColumn, tview.NewTableCell( - FormatTimeSpent((logs)[r].WorkLog.TimeSpentSeconds)).SetTextColor(color).SetAlign(tview.AlignLeft), + FormatTimeSpent((logs)[r].Worklog.TimeSpentSeconds)).SetTextColor(color).SetAlign(tview.AlignLeft), ) } d.worklogList.Select(0, IssueKeyColumn).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) { @@ -126,7 +126,7 @@ func (d *DayView) update() { }).SetSelectedFunc(func(row, column int) { NewUpdateWorklogForm(d, logs, row) }) - timeSpent := CalculateTimeSpent(getWorkLogsFromWorkLogIssues(logs)) + timeSpent := CalculateTimeSpent(getWorklogsFromWorklogIssues(logs)) d.worklogStatus.SetText( fmt.Sprintf("Worklogs - %s - [%s%s[white]]", app.time.Format("2006-01-02"), @@ -276,7 +276,7 @@ func NewAddWorklogForm(d *DayView, issues []Issue, row int) *tview.Form { return form } -func NewUpdateWorklogForm(d *DayView, workLogIssues []*WorkLogIssue, row int) *tview.Form { +func NewUpdateWorklogForm(d *DayView, workLogIssues []*WorklogIssue, row int) *tview.Form { var form *tview.Form updateWorklog := func() { @@ -284,7 +284,7 @@ func NewUpdateWorklogForm(d *DayView, workLogIssues []*WorkLogIssue, row int) *t go func() { app.ui.loaderView.Show("Updating worklog...") defer app.ui.loaderView.Hide() - err := workLogIssues[row].WorkLog.Update(timeSpent) + err := workLogIssues[row].Worklog.Update(timeSpent) if err != nil { app.ui.errorView.ShowError(err.Error()) return @@ -300,7 +300,7 @@ func NewUpdateWorklogForm(d *DayView, workLogIssues []*WorkLogIssue, row int) *t go func() { app.ui.loaderView.Show("Deleting worklog...") defer app.ui.loaderView.Hide() - err := app.workLogs.Delete(workLogIssues[row].WorkLog) + err := app.workLogs.Delete(workLogIssues[row].Worklog) if err != nil { app.ui.errorView.ShowError(err.Error()) return @@ -313,7 +313,7 @@ func NewUpdateWorklogForm(d *DayView, workLogIssues []*WorkLogIssue, row int) *t } form = tview.NewForm(). - AddInputField("Time spent", FormatTimeSpent(workLogIssues[row].WorkLog.TimeSpentSeconds), 20, nil, nil). + AddInputField("Time spent", FormatTimeSpent(workLogIssues[row].Worklog.TimeSpentSeconds), 20, nil, nil). AddButton("Update", updateWorklog). AddButton("Delete", deleteWorklog). AddButton("Cancel", func() { diff --git a/gojira/gojira.go b/gojira/gojira.go index 30ece7b..80693e4 100644 --- a/gojira/gojira.go +++ b/gojira/gojira.go @@ -12,8 +12,8 @@ type gojira struct { cli *cli.App ui *UserInteface time *time.Time - workLogs WorkLogs - workLogsIssues WorkLogsIssues + workLogs Worklogs + workLogsIssues WorklogsIssues } func Run() { @@ -59,7 +59,7 @@ func Run() { Commands: []*cli.Command{ LogWorkCommand, IssuesCommand, - WorkLogsCommand, + WorklogsCommand, ConfigCommand, ViewIssueCommand, }, diff --git a/gojira/jira.go b/gojira/jira.go index 74a8832..b8f0e64 100644 --- a/gojira/jira.go +++ b/gojira/jira.go @@ -64,7 +64,7 @@ type Issue struct { } `json:"fields"` } -type WorkLogResponse struct { +type WorklogResponse struct { Self string `json:"self"` Author struct { Self string `json:"self"` @@ -120,7 +120,7 @@ func (jc *JiraClient) GetIssue(issueKey string) (Issue, error) { return jiraIssue, nil } -func (jc *JiraClient) CreateWorklog(issueKey string, logTime *time.Time, timeSpent string) (WorkLogResponse, error) { +func (jc *JiraClient) CreateWorklog(issueKey string, logTime *time.Time, timeSpent string) (WorklogResponse, error) { payload := map[string]string{ "timeSpent": FormatTimeSpent(TimeSpentToSeconds(timeSpent)), "adjustEstimate": "leave", @@ -131,13 +131,13 @@ func (jc *JiraClient) CreateWorklog(issueKey string, logTime *time.Time, timeSpe requestUrl := fmt.Sprintf("%s/rest/api/2/issue/%s/worklog?notifyUsers=false", Config.JiraUrl, issueKey) response, err := SendHttpRequest("POST", requestUrl, requestBody, jc.getHttpHeaders(), 201) if err != nil { - return WorkLogResponse{}, err + return WorklogResponse{}, err } - var workLogRequest WorkLogResponse + var workLogRequest WorklogResponse err = json.Unmarshal(response, &workLogRequest) if err != nil { - return WorkLogResponse{}, err + return WorklogResponse{}, err } return workLogRequest, nil } diff --git a/gojira/tempo.go b/gojira/tempo.go index 6ddbc4e..5924db1 100644 --- a/gojira/tempo.go +++ b/gojira/tempo.go @@ -21,11 +21,11 @@ func NewTempoClient() *TempoClient { } } -type WorkLogsResponse struct { - WorkLogs []WorkLog `json:"results"` +type WorklogsResponse struct { + Worklogs []Worklog `json:"results"` } -type WorkLogUpdateRequest struct { +type WorklogUpdateRequest struct { IssueKey string `json:"issueKey"` StartDate string `json:"startDate"` StartTime string `json:"startTime"` @@ -34,7 +34,7 @@ type WorkLogUpdateRequest struct { TimeSpentSeconds int `json:"timeSpentSeconds"` } -func (tc *TempoClient) GetWorklogs(fromDate, toDate time.Time) (WorkLogsResponse, error) { +func (tc *TempoClient) GetWorklogs(fromDate, toDate time.Time) (WorklogsResponse, error) { // tempo is required only because of fetching worklogs by date range requestUrl := fmt.Sprintf("%s/worklogs/user/%s?from=%s&to=%s&limit=1000", tc.Url, tc.JiraAccountId, fromDate.Format(dateLayout), toDate.Format(dateLayout)) @@ -44,20 +44,20 @@ func (tc *TempoClient) GetWorklogs(fromDate, toDate time.Time) (WorkLogsResponse } response, err := SendHttpRequest("GET", requestUrl, nil, headers, 200) if err != nil { - return WorkLogsResponse{}, err + return WorklogsResponse{}, err } - var workLogsResponse WorkLogsResponse + var workLogsResponse WorklogsResponse err = json.Unmarshal(response, &workLogsResponse) if err != nil { - return WorkLogsResponse{}, err + return WorklogsResponse{}, err } return workLogsResponse, err } -func (tc *TempoClient) UpdateWorklog(worklog *WorkLog, timeSpent string) error { +func (tc *TempoClient) UpdateWorklog(worklog *Worklog, timeSpent string) error { timeSpentInSeconds := TimeSpentToSeconds(timeSpent) - payload := WorkLogUpdateRequest{ + payload := WorklogUpdateRequest{ IssueKey: worklog.Issue.Key, StartDate: worklog.StartDate, StartTime: worklog.StartTime, @@ -76,8 +76,8 @@ func (tc *TempoClient) UpdateWorklog(worklog *WorkLog, timeSpent string) error { return err } -func (tc *TempoClient) DeleteWorklog(tempoWorkLogId int) error { - requestUrl := fmt.Sprintf("%s/worklogs/%d", Config.TempoUrl, tempoWorkLogId) +func (tc *TempoClient) DeleteWorklog(tempoWorklogID int) error { + requestUrl := fmt.Sprintf("%s/worklogs/%d", Config.TempoUrl, tempoWorklogID) headers := map[string]string{ "Authorization": fmt.Sprintf("Bearer %s", Config.TempoToken), "Content-Type": "application/json", diff --git a/gojira/utils.go b/gojira/utils.go index 6aa980a..ddc0626 100644 --- a/gojira/utils.go +++ b/gojira/utils.go @@ -13,15 +13,15 @@ import ( const dateLayout = "2006-01-02" -func getWorkLogsFromWorkLogIssues(workLogIssues []*WorkLogIssue) []*WorkLog { - var workLogs []*WorkLog +func getWorklogsFromWorklogIssues(workLogIssues []*WorklogIssue) []*Worklog { + var workLogs []*Worklog for _, workLog := range workLogIssues { - workLogs = append(workLogs, workLog.WorkLog) + workLogs = append(workLogs, workLog.Worklog) } return workLogs } -func CalculateTimeSpent(workLogs []*WorkLog) int { +func CalculateTimeSpent(workLogs []*Worklog) int { timeSpentInSeconds := 0 for _, workLog := range workLogs { timeSpentInSeconds += workLog.TimeSpentSeconds diff --git a/gojira/utils_test.go b/gojira/utils_test.go index c232f82..7d6dbba 100644 --- a/gojira/utils_test.go +++ b/gojira/utils_test.go @@ -26,7 +26,7 @@ func TestFormatTimeSpent(t *testing.T) { } func TestCalculateTimeSpent(t *testing.T) { - fixture := []*WorkLog{ + fixture := []*Worklog{ {TimeSpentSeconds: 60}, // 1m {TimeSpentSeconds: 3600}, // 1h {TimeSpentSeconds: 7200}, // 2h diff --git a/gojira/worklog.go b/gojira/worklog.go index b6594c7..55853b4 100644 --- a/gojira/worklog.go +++ b/gojira/worklog.go @@ -9,19 +9,19 @@ import ( "time" ) -func NewWorkLog(issueKey string, logTime *time.Time, timeSpent string) (WorkLog, error) { +func NewWorklog(issueKey string, logTime *time.Time, timeSpent string) (Worklog, error) { workLogResponse, err := NewJiraClient().CreateWorklog(issueKey, logTime, timeSpent) if err != nil { - return WorkLog{}, err + return Worklog{}, err } - jiraWorkLogID, err := strconv.Atoi(workLogResponse.ID) + jiraWorklogID, err := strconv.Atoi(workLogResponse.ID) if err != nil { - return WorkLog{}, err + return Worklog{}, err } - workLog := WorkLog{ - JiraWorklogid: jiraWorkLogID, + workLog := Worklog{ + JiraWorklogID: jiraWorklogID, StartDate: logTime.Format(dateLayout), StartTime: logTime.Format("15:04:05"), TimeSpentSeconds: workLogResponse.Timespentseconds, @@ -32,9 +32,9 @@ func NewWorkLog(issueKey string, logTime *time.Time, timeSpent string) (WorkLog, return workLog, nil } -type WorkLog struct { +type Worklog struct { TempoWorklogid int `json:"tempoWorklogId"` - JiraWorklogid int `json:"jiraWorklogId"` + JiraWorklogID int `json:"jiraWorklogId"` Issue struct { Key string `json:"key"` } `json:"issue"` @@ -47,25 +47,25 @@ type WorkLog struct { } `json:"author"` } -type WorkLogIssue struct { - WorkLog *WorkLog +type WorklogIssue struct { + Worklog *Worklog Issue Issue } -type WorkLogsIssues struct { +type WorklogsIssues struct { startDate time.Time endDate time.Time - issues []WorkLogIssue + issues []WorklogIssue } -type WorkLogs struct { +type Worklogs struct { startDate time.Time endDate time.Time - logs []*WorkLog + logs []*Worklog } -func (wl *WorkLogs) LogsOnDate(date *time.Time) ([]*WorkLog, error) { - var logsOnDate []*WorkLog +func (wl *Worklogs) LogsOnDate(date *time.Time) ([]*Worklog, error) { + var logsOnDate []*Worklog truncatedDate := (*date).Truncate(24 * time.Hour) if truncatedDate.Before(wl.startDate) || truncatedDate.After(wl.endDate) { return nil, nil @@ -83,7 +83,7 @@ func (wl *WorkLogs) LogsOnDate(date *time.Time) ([]*WorkLog, error) { return logsOnDate, nil } -func (wl *WorkLogs) TotalTimeSpentToPresentDay() int { +func (wl *Worklogs) TotalTimeSpentToPresentDay() int { totalTime := 0 for _, log := range wl.logs { logDate, err := time.Parse(dateLayout, log.StartDate) @@ -97,14 +97,14 @@ func (wl *WorkLogs) TotalTimeSpentToPresentDay() int { return totalTime } -func (wli *WorkLogsIssues) IssuesOnDate(date *time.Time) ([]*WorkLogIssue, error) { - var issuesOnDate []*WorkLogIssue +func (wli *WorklogsIssues) IssuesOnDate(date *time.Time) ([]*WorklogIssue, error) { + var issuesOnDate []*WorklogIssue if date.Before(wli.startDate) || date.After(wli.endDate) { return nil, errors.New("Date is out of worklogs range") } truncatedDate := (*date).Truncate(24 * time.Hour) for i, issue := range wli.issues { - logDate, err := time.Parse(dateLayout, issue.WorkLog.StartDate) + logDate, err := time.Parse(dateLayout, issue.Worklog.StartDate) logDate = logDate.Truncate(24 * time.Hour) if err != nil { return nil, err @@ -117,18 +117,18 @@ func (wli *WorkLogsIssues) IssuesOnDate(date *time.Time) ([]*WorkLogIssue, error return issuesOnDate, nil } -func GetWorkLogs() (WorkLogs, error) { +func GetWorklogs() (Worklogs, error) { fromDate, toDate := MonthRange(app.time) logrus.Infof("getting worklogs from %s to %s...", fromDate, toDate) workLogsResponse, err := NewTempoClient().GetWorklogs(fromDate, toDate) if err != nil { - return WorkLogs{}, err + return Worklogs{}, err } - var worklogs []*WorkLog - for i := range workLogsResponse.WorkLogs { - worklogs = append(worklogs, &workLogsResponse.WorkLogs[i]) + var worklogs []*Worklog + for i := range workLogsResponse.Worklogs { + worklogs = append(worklogs, &workLogsResponse.Worklogs[i]) } - return WorkLogs{startDate: fromDate, endDate: toDate, logs: worklogs}, nil + return Worklogs{startDate: fromDate, endDate: toDate, logs: worklogs}, nil } func TimeSpentToSeconds(timeSpent string) int { @@ -153,7 +153,7 @@ func TimeSpentToSeconds(timeSpent string) int { return timeSpentSeconds } -func (wl *WorkLog) Update(timeSpent string) error { +func (wl *Worklog) Update(timeSpent string) error { logrus.Debugf("updating worklog ... %+v", wl) timeSpentInSeconds := TimeSpentToSeconds(timeSpent) var err error @@ -163,7 +163,7 @@ func (wl *WorkLog) Update(timeSpent string) error { err = NewTempoClient().UpdateWorklog(wl, timeSpent) } else { // make update request to jira if tempoWorklogId is not set - err = NewJiraClient().UpdateWorklog(wl.Issue.Key, wl.JiraWorklogid, timeSpentInSeconds) + err = NewJiraClient().UpdateWorklog(wl.Issue.Key, wl.JiraWorklogID, timeSpentInSeconds) } if err != nil { return err @@ -172,14 +172,14 @@ func (wl *WorkLog) Update(timeSpent string) error { return nil } -func (wl *WorkLogs) Delete(w *WorkLog) error { +func (wl *Worklogs) Delete(w *Worklog) error { logrus.Debugf("deleting w ... %+v", w) // make update request to tempo if tempoWorklogId is set var err error if w.TempoWorklogid != 0 { err = NewTempoClient().DeleteWorklog(w.TempoWorklogid) } else { - err = NewJiraClient().DeleteWorklog(w.Issue.Key, w.JiraWorklogid) + err = NewJiraClient().DeleteWorklog(w.Issue.Key, w.JiraWorklogID) } if err != nil { logrus.Debug(w) @@ -188,13 +188,13 @@ func (wl *WorkLogs) Delete(w *WorkLog) error { // FIXME delete is kinda buggy - it messes up pointers and we're getting weird results for i, issue := range app.workLogsIssues.issues { - if issue.WorkLog.JiraWorklogid == w.JiraWorklogid { + if issue.Worklog.JiraWorklogID == w.JiraWorklogID { app.workLogsIssues.issues = append(app.workLogsIssues.issues[:i], app.workLogsIssues.issues[i+1:]...) break } } for i, workLog := range wl.logs { - if workLog.JiraWorklogid == w.JiraWorklogid { + if workLog.JiraWorklogID == w.JiraWorklogID { wl.logs = append(wl.logs[:i], wl.logs[i+1:]...) break }