Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen Premaratne committed Mar 7, 2020
2 parents eaa6c0d + a6a0a89 commit 19e070a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ TEST_REPORT = tests.xml
GOARCH = amd64

VERSION?=?
COMMIT=\$(shell git rev-parse HEAD)
BRANCH=\$(shell git rev-parse --abbrev-ref HEAD)

# Symlink into GOPATH
GITHUB_USERNAME=praveenprem
Expand All @@ -15,7 +13,7 @@ CURRENT_DIR=\$(shell pwd)
BUILD_DIR_LINK=\$(shell readlink ${BUILD_DIR})

# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT} -X main.BRANCH=${BRANCH}"
LDFLAGS = -ldflags "-X main.VERSION=${VERSION}"

# Build the project
all: link clean test vet linux darwin windows
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Timesheet

This tool is written to help developer with logging work time to Atlassian Jira based projects.
A commandline tool written to help developer with logging work time to Atlassian Jira based projects.

This tool allows developers to add worklog to a specific ticket without having to browse and find issues
given the user knows the issue reference
Expand Down
9 changes: 8 additions & 1 deletion argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (app *App) Parser() {
" -history and -d are also available")
flag.BoolVar(&app.History, "history", false, "HELP: Print the timesheet of the day")
flag.BoolVar(&app.PrintWeek, "week", false, "HELP: Print timesheet of the current week")
flag.BoolVar(&app.Version, "v", false, "Print application version")
flag.Parse()
app.validate()
}
Expand All @@ -44,6 +45,7 @@ func (app *App) validate() {
if len(os.Args[1:]) < 1 {
fmt.Printf("no arguments are given\n\n")
app.usage()
os.Exit(1)
}

if app.Started != "" {
Expand All @@ -58,6 +60,12 @@ func (app *App) validate() {

if app.Help {
app.usage()
os.Exit(0)
}

if app.Version {
fmt.Println(VERSION)
os.Exit(0)
}

if app.TimeRemaining || app.PrintWeek {
Expand Down Expand Up @@ -88,5 +96,4 @@ func (app *App) usage() {
"\ttimesheet -remaining -d 2020-03-05\n" +
"\ttimesheet -remaining -history\n" +
"\ttimesheet -remaining -history -d 2020-03-05\n")
os.Exit(1)
}
33 changes: 33 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"encoding/json"
"fmt"
"net/http"
"os"
)

Expand Down Expand Up @@ -36,6 +38,7 @@ type App struct {
TimeRemaining bool
History bool
PrintWeek bool
Version bool
Configuration struct {
Auth string
Domain string
Expand All @@ -45,6 +48,35 @@ type App struct {
type Application interface {
Parser()
CredentialEncode()
GetTimeRemaining(domain string, auth string)
GetWeekTimesheet(domain string, auth string)
}

var VERSION string

func (app *App) upgrade() {
var client = &http.Client{}
req, rErr := http.NewRequest("GET", "https://api.github.com/repos/praveenprem/timesheet/releases/latest", nil)
if rErr != nil {
panic(rErr)
}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var response struct {
Name string `json:"name"`
URL string `json:"html_url"`
}
decodeErr := json.NewDecoder(resp.Body).Decode(&response)
if decodeErr != nil {
panic(decodeErr)
}

if fmt.Sprintf("v%s", VERSION) != response.Name {
fmt.Println("New version available! Please download the latest release from", response.URL)
}
}

func main() {
Expand All @@ -59,6 +91,7 @@ func main() {

app.Parser()
app.loadConf()
app.upgrade()

if app.TimeRemaining {
app.GetTimeRemaining(app.Configuration.Domain, app.Configuration.Auth)
Expand Down

0 comments on commit 19e070a

Please sign in to comment.