Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
var VERSION = "development"

type Jira struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
UA HttpClient `json:"-" yaml:"-"`
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
ApiVersion int `json:"api-version,omitempty" yaml:"api-version,omitempty"`
UA HttpClient `json:"-" yaml:"-"`
}

func NewJira(endpoint string) *Jira {
return &Jira{
Endpoint: endpoint,
UA: oreo.New(),
Endpoint: endpoint,
ApiVersion: 3,
UA: oreo.New(),
}
}
5 changes: 5 additions & 0 deletions jiracli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ type GlobalOptions struct {
// JiraDeploymentType can be `cloud` or `server`, if not set it will be inferred from
// the /rest/api/2/serverInfo REST API.
JiraDeploymentType figtree.StringOption `yaml:"jira-deployment-type,omitempty" json:"jira-deployment-type,omitempty"`

// ApiVersion is the Jira REST API version to use. Defaults to 3.
ApiVersion figtree.IntOption `yaml:"api-version,omitempty" json:"api-version,omitempty"`
}

type CommonOptions struct {
Expand Down Expand Up @@ -163,6 +166,7 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
globals := GlobalOptions{
User: figtree.NewStringOption(os.Getenv("USER")),
AuthenticationMethod: figtree.NewStringOption("session"),
ApiVersion: figtree.NewIntOption(3),
}
app.Flag("endpoint", "Base URI to use for Jira").Short('e').SetValue(&globals.Endpoint)
app.Flag("insecure", "Disable TLS certificate verification").Short('k').SetValue(&globals.Insecure)
Expand All @@ -171,6 +175,7 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
app.Flag("socksproxy", "Address for a socks proxy").SetValue(&globals.SocksProxy)
app.Flag("user", "user name used within the Jira service").Short('u').SetValue(&globals.User)
app.Flag("login", "login name that corresponds to the user used for authentication").SetValue(&globals.Login)
app.Flag("api-version", "Jira REST API version to use").SetValue(&globals.ApiVersion)

o = o.WithPreCallback(func(req *http.Request) (*http.Request, error) {
if globals.AuthMethod() == "api-token" {
Expand Down
2 changes: 1 addition & 1 deletion jiracmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
}
return nil
}
results, err := jira.Search(o, globals.Endpoint.Value, opts)
results, err := jira.Search(o, globals.Endpoint.Value, globals.ApiVersion.Value, opts)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion jiracmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func CmdListUsage(cmd *kingpin.CmdClause, opts *ListOptions, fig *figtree.FigTre

// List will query jira and send data to "list" template
func CmdList(o *oreo.Client, globals *jiracli.GlobalOptions, opts *ListOptions) error {
data, err := jira.Search(o, globals.Endpoint.Value, opts, jira.WithAutoPagination())
data, err := jira.Search(o, globals.Endpoint.Value, globals.ApiVersion.Value, opts, jira.WithAutoPagination())
if err != nil {
return err
}
Expand Down
11 changes: 8 additions & 3 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (o *SearchOptions) ProvideSearchRequest() *jiradata.SearchRequest {

// https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/#api-rest-api-3-search-jql-post
func (j *Jira) Search(sp SearchProvider, opts ...SearchOpt) (*jiradata.SearchResults, error) {
return Search(j.UA, j.Endpoint, sp, opts...)
return Search(j.UA, j.Endpoint, j.ApiVersion, sp, opts...)
}

type searchConfig struct {
Expand All @@ -89,7 +89,7 @@ func WithAutoPagination() SearchOpt {
}
}

func Search(ua HttpClient, endpoint string, sp SearchProvider, opts ...SearchOpt) (*jiradata.SearchResults, error) {
func Search(ua HttpClient, endpoint string, apiVersion int, sp SearchProvider, opts ...SearchOpt) (*jiradata.SearchResults, error) {
c := &searchConfig{}
for _, opt := range opts {
opt(c)
Expand All @@ -102,13 +102,18 @@ func Search(ua HttpClient, endpoint string, sp SearchProvider, opts ...SearchOpt
req.MaxResults = 100
}

searchPath := "rest/api/3/search/jql"
if apiVersion == 2 {
searchPath = "rest/api/2/search"
}

issues := jiradata.Issues{}
for {
encoded, err := json.Marshal(req)
if err != nil {
return nil, err
}
uri := URLJoin(endpoint, "rest/api/3/search/jql")
uri := URLJoin(endpoint, searchPath)
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
Expand Down