Last active
May 24, 2016 12:52
-
-
Save suknark/1d26013014e9116f6c20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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