jt

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 14 Imported by: 0

README

jt

Tiny command-line tool for creating JIRA tickets with a summary/title and optionally a description.

Installation

If you have go install locally, compile and install with:

go install github.com/leosunmo/jt/cmd/jt

Otherwise download a release from the releases page and put it in your path.

Usage

Create a config file under ~/.config/jt/config.yaml with some default values. Here's an example with all supported values:

url: https://example.atlassian.net
email: me@example.com
defaultProjectKey: PRJ
defaultIssueType: Task
defaultComponentNames:
  - Team A
  - Development

Then you can create a ticket with:

# Create ticket with only a summary
jt My new ticket

# Create ticket with a summary and a description
jt My new ticket -m "With a description!"

# Or create a ticket with $EDITOR
jt
# The first line is the ticket summary/title
#
# The description is everything after a blank line
# which can be multiline.
gitcommit-style vim highlighting

Add this to your .vimrc to get gitcommit-style highlighting for the summary and description:

" jt syntax highlighting
au BufReadPost *.jt set syntax=gitcommit
Setting up JIRA API access

The first time you run it, it will prompt for an access token for JIRA. You can generate one at https://id.atlassian.com/manage-profile/security/api-tokens.

It will be stored in your system's keyring, so you won't have to enter it again until you restart or lock your keychain.

Documentation

Index

Constants

View Source
const (
	DefaultConfigLocation = "~/.config/jt/config.yaml"
)
View Source
const (
	DefaultEditor = "vim"
)

Variables

View Source
var (
	ErrEmptySummary = fmt.Errorf("aborting, summary empty")
)

Functions

func GetToken

func GetToken() (string, error)

func OpenInEditor

func OpenInEditor(s string, d string) (string, string, error)

OpenInEditor opens the user's default editor and returns the contents of the file.

func SetToken

func SetToken(key string) (string, error)

Types

type Attrs

type Attrs struct {
}

type Components

type Components struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

type Content

type Content struct {
	Type    string         `json:"type,omitempty"`
	Content []ContentBlock `json:"content,omitempty"`
}

type ContentBlock

type ContentBlock struct {
	Type string `json:"type,omitempty"`
	Text string `json:"text,omitempty"`
}

type CreateIssueRequest

type CreateIssueRequest struct {
	Fields Fields `json:"fields,omitempty"`
	Update struct {
		Labels []string `json:"labels,omitempty"`
	} `json:"update"`
}

type CreatedIssueResponse

type CreatedIssueResponse struct {
	ID         string `json:"id"`
	Key        string `json:"key"`
	Self       string `json:"self"`
	Transition struct {
		Status          int `json:"status"`
		ErrorCollection struct {
			ErrorMessages []string `json:"errorMessages"`
			Errors        struct{} `json:"errors"`
		} `json:"errorCollection"`
	} `json:"transition"`
	ErrorMessages []string          `json:"errorMessages"`
	Errors        map[string]string `json:"errors"`
}

type Description

type Description struct {
	Version int       `json:"version,omitempty"`
	Type    string    `json:"type,omitempty"`
	Content []Content `json:"content,omitempty"`
}

type Fields

type Fields struct {
	Components  []Components `json:"components,omitempty"`
	Issuetype   Issuetype    `json:"issuetype,omitempty"`
	Project     Project      `json:"project,omitempty"`
	Description *Description `json:"description,omitempty"`
	Summary     string       `json:"summary,omitempty"`
}

type Issuetype

type Issuetype struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

type JTConfig

type JTConfig struct {
	// URL is the URL of the JIRA instance.
	URL string `yaml:"url"`
	// Email is the JIRA user email. Used as a username for authenticating.
	Email string `yaml:"email"`
	// Default project key is the JIRA project that will be used for issues. This is the short version of a project name, example: PRJ.
	DefaultProjectKey string `yaml:"defaultProjectKey"`
	// Default issue type is the issue type that will be used for issues.
	DefaultIssueType string `yaml:"defaultIssueType"`
	// Default component names are the default components that will be added to issues.
	DefaultComponentNames []string `yaml:"defaultComponentNames"`
}

func ReadConfig

func ReadConfig(configPath string) (JTConfig, error)

ReadConfig reads config file from the default location.

type JiraClient

type JiraClient struct {
	// contains filtered or unexported fields
}

func NewJiraClient

func NewJiraClient(conf JiraConfig) *JiraClient

func (JiraClient) NewJIRATicket

func (jc JiraClient) NewJIRATicket(summary string, desc string) (string, error)

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

type JiraConfig

type JiraConfig struct {
	URL            string
	Email          string
	Token          string
	ProjectKey     string
	IssueType      string
	ComponentNames []string
}

type Project

type Project struct {
	ID  string `json:"id,omitempty"`
	Key string `json:"key,omitempty"`
}

Directories

Path Synopsis
cmd
jt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL