Skip to content

Commit

Permalink
WorkLog -> Worklog
Browse files Browse the repository at this point in the history
  • Loading branch information
jzyinq committed Mar 28, 2024
1 parent 8fd7ad2 commit cda69c7
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 74 deletions.
18 changes: 9 additions & 9 deletions gojira/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,7 +36,7 @@ var WorkLogsCommand = &cli.Command{
},
}

func NewWorkLogIssues() error {
func NewWorklogIssues() error {
// goroutine awesomeness
var err error
startDate, endDate := MonthRange(app.time)
Expand All @@ -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
Expand All @@ -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])
}
Expand Down Expand Up @@ -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...")
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions gojira/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}
14 changes: 7 additions & 7 deletions gojira/dayview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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) {
Expand All @@ -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"),
Expand Down Expand Up @@ -276,15 +276,15 @@ 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() {
timeSpent := form.GetFormItem(0).(*tview.InputField).GetText()
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
Expand All @@ -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
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions gojira/gojira.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -59,7 +59,7 @@ func Run() {
Commands: []*cli.Command{
LogWorkCommand,
IssuesCommand,
WorkLogsCommand,
WorklogsCommand,
ConfigCommand,
ViewIssueCommand,
},
Expand Down
10 changes: 5 additions & 5 deletions gojira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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",
Expand All @@ -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
}
Expand Down
22 changes: 11 additions & 11 deletions gojira/tempo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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))
Expand All @@ -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,
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions gojira/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gojira/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit cda69c7

Please sign in to comment.