Skip to content

Commit

Permalink
Fixed append project to view
Browse files Browse the repository at this point in the history
  • Loading branch information
colton22 authored and coryb committed Dec 2, 2019
1 parent 9cbd993 commit 8a46215
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

type IssueQueryProvider interface {
ProvideIssueQueryString() string
ProvideDefaultProject() string
}

type IssueOptions struct {
Expand All @@ -24,6 +25,11 @@ type IssueOptions struct {
Properties []string `json:"properties,omitempty" yaml:"properties,omitempty"`
FieldsByKeys bool `json:"fieldsByKeys,omitempty" yaml:"fieldsByKeys,omitempty"`
UpdateHistory bool `json:"updateHistory,omitempty" yaml:"updateHistory,omitempty"`
Project string `json:"project,omitempty" yaml:"project,omitempty"`
}

func (o *IssueOptions) ProvideDefaultProject() string {
return o.Project
}

func (o *IssueOptions) ProvideIssueQueryString() string {
Expand All @@ -49,13 +55,19 @@ func (o *IssueOptions) ProvideIssueQueryString() string {
return ""
}

func CaseInsensitiveContains(s, substr string) bool {
s, substr = strings.ToUpper(s), strings.ToUpper(substr)
return strings.Contains(s, substr)
}

// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getIssue
func (j *Jira) GetIssue(issue string, iqg IssueQueryProvider) (*jiradata.Issue, error) {
return GetIssue(j.UA, j.Endpoint, issue, iqg)
}

func GetIssue(ua HttpClient, endpoint string, issue string, iqg IssueQueryProvider) (*jiradata.Issue, error) {
query := ""
pro := iqg.ProvideDefaultProject()
if iqg != nil {
query = iqg.ProvideIssueQueryString()
}
Expand All @@ -71,6 +83,11 @@ func GetIssue(ua HttpClient, endpoint string, issue string, iqg IssueQueryProvid
results := &jiradata.Issue{}
return results, json.NewDecoder(resp.Body).Decode(results)
}
// Ticket not found, maybe try prepend Project value?
if ! CaseInsensitiveContains(issue,pro) {
issue = pro+"-"+issue
return GetIssue(ua, endpoint, issue, iqg)
}
return nil, responseError(resp)
}

Expand Down

0 comments on commit 8a46215

Please sign in to comment.