Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen Premaratne committed Mar 6, 2020
2 parents 377ae55 + bd0a846 commit 0f0d8a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ given the user knows the issue reference
```
This tool can be used to log time spent on a specific Jira ticket on a project.
-d string
OPTIONAL: The date on which the worklog effort was started in DD-MM-YYYY format. Default 05-03-2020
OPTIONAL: The date on which the worklog effort was started in YYYY-MM-DD format. Default 2020-03-06
-e string
HELP: Base64 encode the given credentials. Format: email:token;domain. e.g. example@example.com:abcThisIsFake;xyz.atlassian.net
-h HELP: Print usage
HELP: Base64 encode the given credentials. Format: email:token;domain. e.g. example@example.com:abcThisIsFake;xyz.atlassian.net
-h HELP: Print usage
-history
Print the timesheet of the day
HELP: Print the timesheet of the day
-m string
OPTIONAL: A comment about the worklog
OPTIONAL: A comment about the worklog
-r string
REQUIRED: Jira ticket reference. E.g. DDSP-4
REQUIRED: Jira ticket reference. E.g. DDSP-4
-remaining
Time remaining
HELP: Print how many hour can be book for the current day. -history and -d are also available
-t string
REQUIRED: The time spent as days (#d), hours (#h), or minutes (#m or #). E.g. 8h
REQUIRED: The time spent as days (#d), hours (#h), or minutes (#m or #). E.g. 8h
```

## Requirements
Expand Down
12 changes: 6 additions & 6 deletions argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"os"
"regexp"
"time"
)

/**
Expand All @@ -16,24 +15,25 @@ import (
* Created on: 29/02/2020 17:52
*/

var dateFormat, _ = regexp.Compile("[0-9]{2}-[0-9]{2}-[0-9]{4}")
var dateFormat, _ = regexp.Compile("[0-9]{4}-[0-9]{2}-[0-9]{2}")

func (app *App) Parser() {
var day = time.Now().Format("02-01-2006")
app.Started = app.getDateTime()

flag.BoolVar(&app.Help, "h", false, "HELP: Print usage")
flag.StringVar(&app.Ticket, "r", "",
"REQUIRED: Jira ticket reference. E.g. DDSP-4")
flag.StringVar(&app.TimeSpent, "t", "",
"REQUIRED: The time spent as days (#d), hours (#h), or minutes (#m or #). E.g. 8h")
flag.StringVar(&app.Started, "d", "",
fmt.Sprintf("OPTIONAL: The date on which the worklog effort was started in DD-MM-YYYY format. Default %s", day))
fmt.Sprintf("OPTIONAL: The date on which the worklog effort was started in YYYY-MM-DD format. Default %s", app.getDate()))
flag.StringVar(&app.Comment, "m", "",
"OPTIONAL: A comment about the worklog")
flag.StringVar(&app.Encode, "e", "", "HELP: Base64 encode the given credentials."+
" Format: email:token;domain. e.g. example@example.com:abcThisIsFake;xyz.atlassian.net")
flag.BoolVar(&app.TimeRemaining, "remaining", false, "Print how many hour can be book for the current day.")
flag.BoolVar(&app.History, "history", false, "Print the timesheet of the day")
flag.BoolVar(&app.TimeRemaining, "remaining", false, "HELP: Print how many hour can be book for the current day." +
" -history and -d are also available")
flag.BoolVar(&app.History, "history", false, "HELP: Print the timesheet of the day")
flag.Parse()
app.validate()
}
Expand Down
8 changes: 4 additions & 4 deletions atlassian.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (app *App) GetTimeRemaining(domain string, auth string) {
var totalTimeSpent int
var timeRemaining float64
userEmail, _ := basicAuth(auth)
issuesOfTheDay, iErr := getIssuesUpdatedToday(domain, auth)
issuesOfTheDay, iErr := getIssuesUpdatedToday(domain, auth, app.getDate())
if iErr != nil {
panic(iErr)
}
Expand All @@ -119,7 +119,7 @@ func (app *App) GetTimeRemaining(domain string, auth string) {
if app.isDateMatch(log.Started) {
if log.Author.EmailAddress == userEmail {
if app.History {
fmt.Println("Timesheet history:")
fmt.Printf("Timesheet history: (%s)\n", app.getDate())
fmt.Printf("\t%s: %s\n\t%s: %s\n\t%s: %s\n\t%s: %.2fh\n\n",
"Key", wLog.Key,
"Summary", wLog.Summary,
Expand All @@ -142,9 +142,9 @@ func (app *App) GetTimeRemaining(domain string, auth string) {

}

func getIssuesUpdatedToday(domain string, auth string) (*JiraSearchResult, error) {
func getIssuesUpdatedToday(domain string, auth string, date string) (*JiraSearchResult, error) {
var client = &http.Client{}
var query = "jql=worklogDate%20>%3D%20startOfDay()%20AND%20worklogDate%20<%3D%20endOfDay()"
var query = fmt.Sprintf("jql=worklogDate%%20>%%3D%%20\"%s\"%%20AND%%20worklogDate%%20<%%3D%%20\"%s\"", date, date)
var url = fmt.Sprintf("https://%s/rest/api/3/search?%s", strings.TrimSuffix(domain, "\n"), query)
req, reqErr := http.NewRequest("GET", url, nil)
if reqErr != nil {
Expand Down
7 changes: 6 additions & 1 deletion datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"regexp"
"strings"
"time"
)

Expand All @@ -23,6 +24,10 @@ func (app *App) getTime() string {
return fmt.Sprintf("%s.000+0000", now.Format("15:04:05"))
}

func (app *App) getDate() string {
return strings.Split(app.Started, "T")[0]
}

func (app *App) getTimeFixed() string {
return "09:00:00.000+0000"
}
Expand All @@ -34,7 +39,7 @@ func (app *App) isDateMatch(datetime string) bool {
panic(err)
}

if date.Format("2006-01-02") == time.Now().Format("2006-01-02") {
if date.Format("2006-01-02") == app.getDate() {
return true
}
return false
Expand Down

0 comments on commit 0f0d8a9

Please sign in to comment.