Skip to content

Commit

Permalink
Add -m flag for description
Browse files Browse the repository at this point in the history
  • Loading branch information
leosunmo committed Oct 29, 2023
1 parent 6ec2cb2 commit b50639e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
18 changes: 16 additions & 2 deletions cmd/jt/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"net/url"
"os"
Expand All @@ -9,6 +10,10 @@ import (
"github.com/leosunmo/jt"
)

var (
msg = flag.String("m", "", "Issue Description")
)

func main() {
if err := run(); err != nil {
fmt.Printf("%s\n", err)
Expand All @@ -17,8 +22,17 @@ func main() {
}

func run() error {
// Parse flags
flag.Parse()

var desc string
// Check if msg is set
if *msg != "" {
desc = *msg
}

// Read the issue summary from the command line arguments.
summary := strings.Join(os.Args[1:], " ")
summary := strings.Join(flag.Args(), " ")
if summary == "" {
return fmt.Errorf("please provide a summary for the issue")
}
Expand Down Expand Up @@ -49,7 +63,7 @@ func run() error {
}

c := jt.NewJiraClient(jc)
key, err := c.NewJIRATicket(summary)
key, err := c.NewJIRATicket(summary, desc)
if err != nil {
return fmt.Errorf("failed to create ticket: %s\n", err)
}
Expand Down
23 changes: 22 additions & 1 deletion jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Content struct {
Content []ContentBlock `json:"content,omitempty"`
}
type Description struct {
Version int `json:"version,omitempty"`
Type string `json:"type,omitempty"`
Content []Content `json:"content,omitempty"`
}
Expand All @@ -106,7 +107,7 @@ type CreatedIssueResponse struct {
// NewJIRATicket creates a new JIRA ticket using the JIRA REST API v3.
// The function returns the key of the created ticket and an error if the ticket could not be created.
// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post
func (jc JiraClient) NewJIRATicket(summary string) (string, error) {
func (jc JiraClient) NewJIRATicket(summary string, desc string) (string, error) {

// Build the body of the request using a CreateIssueRequest
reqBody := CreateIssueRequest{}
Expand All @@ -119,6 +120,7 @@ func (jc JiraClient) NewJIRATicket(summary string) (string, error) {
}

reqBody.Fields.Summary = summary
reqBody.Fields.Description = setDescription(desc)

jsonBody, err := json.MarshalIndent(reqBody, "", " ")
if err != nil {
Expand Down Expand Up @@ -161,3 +163,22 @@ func (jc JiraClient) NewJIRATicket(summary string) (string, error) {

return createResponse.Key, nil
}

func setDescription(msg string) *Description {
desc := Description{
Type: "doc",
Version: 1,
Content: []Content{
{
Type: "paragraph",
Content: []ContentBlock{
{
Type: "text",
Text: msg,
},
},
},
},
}
return &desc
}

0 comments on commit b50639e

Please sign in to comment.