Skip to content

Instantly share code, notes, and snippets.

@epishan
Forked from suknark/worklog.go
Created May 24, 2016 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epishan/099d643f44acf99d48c96ec0e2534b72 to your computer and use it in GitHub Desktop.
Save epishan/099d643f44acf99d48c96ec0e2534b72 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"net/http"
"strconv"
)
func Request(task string, time string, comment string) error {
t, _ := strconv.Atoi(time)
var jsonStr = []byte(`{"comment":"` + comment + `", "timeSpentSeconds":` + strconv.Itoa(t*60) + `}`)
//set your company jira domain
req, err := http.NewRequest("POST", "https://jira.your.company/rest/api/2/issue/"+task+"/worklog", bytes.NewBuffer(jsonStr))
//set your user and password
req.SetBasicAuth("user", "password")
req.Header.Set("Content-Type", "application/json")
cli := &http.Client{}
resp, err := cli.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
body, err := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
return err
}
func main() {
LogWork := flag.String("l", "60", "logwork (sec)")
JiraTask := flag.String("t", "", "task")
Comment := flag.String("c", "DevOps support", "logwork comment")
flag.Parse()
err := Request(*JiraTask, *LogWork, *Comment)
if err != nil {
panic(err)
}
}
//simple usage
//go run worklog.go -l 600 -t DEVOPS-25 -c "discussion with Andrew"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment