Skip to content

Commit 79d039d

Browse files
committed
Fixing issues with the jira client
1 parent 549df80 commit 79d039d

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Create(client Client) (string, error) {
3030
func PrepareCommitMessage(client Client, branchName, commitMessage string) string {
3131
return client.PrepareCommitMessage(branchName, commitMessage)
3232
}
33-
33+
3434
// Comment : Comment on an issue
3535
func Comment(client Client, branchName, comment string) error {
3636
return client.Comment(branchName, comment)
@@ -58,7 +58,7 @@ func NewClient(clientName string) (Client, error) {
5858

5959
return nil, fmt.Errorf("Could not find client: %v", clientName)
6060
}
61-
61+
6262
// NewAuthenticatedClient : Return a new client authenticated
6363
func NewAuthenticatedClient() (Client, error) {
6464
fields, err := Load()

jira.go

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type JiraClient struct {
1515
config map[string]string
1616
}
1717

18+
// Create will create a new client
1819
func (j *JiraClient) Create() (string, error) {
1920
domain, err := j.GetDomain()
2021

@@ -63,9 +64,7 @@ func GetIssueID(branchName string) string {
6364

6465
// Comment : Post a comment on a jira issue
6566
func (j *JiraClient) Comment(branchName, comment string) error {
66-
fmt.Println(branchName)
6767
issueID := GetIssueID(branchName)
68-
fmt.Println(issueID)
6968

7069
jiraComment := &jira.Comment{
7170
Body: comment,
@@ -75,6 +74,7 @@ func (j *JiraClient) Comment(branchName, comment string) error {
7574
return err
7675
}
7776

77+
// GetDomain : Get the domain from the config
7878
func (j *JiraClient) GetDomain() (string, error) {
7979

8080
domain, ok := j.config["domain"]
@@ -130,27 +130,18 @@ func indexOf(status string, data []string) int {
130130
func (j *JiraClient) Start(issueType string, issueID string) (string, error) {
131131
allowed := strings.Split(j.config["transitions"], ",")
132132

133-
fmt.Println(issueID)
134-
135133
transitions, response, err := j.client.Issue.GetTransitions(issueID)
136-
fmt.Println(transitions)
137-
138-
if err != nil {
139-
fmt.Println(err)
140-
fmt.Println(response.Body)
141-
return "", err
142-
}
143-
144-
nextTransition := transitions[0]
145134

146-
if indexOf(nextTransition.Name, allowed) > -1 {
147-
_, err := j.client.Issue.DoTransition(issueID, nextTransition.ID)
135+
for _, transition := range transitions {
136+
if indexOf(transition.Name, allowed) > -1 {
137+
_, err := j.client.Issue.DoTransition(issueID, transition.ID)
148138

149-
if err != nil {
150-
return "", err
139+
if err != nil {
140+
fmt.Println(err)
141+
fmt.Println(response.Body)
142+
return "", err
143+
}
151144
}
152-
153-
_, _ = j.Start(issueType, issueID)
154145
}
155146

156147
branchName, err := j.GetBranchName(issueType, issueID)
@@ -167,7 +158,6 @@ func (j *JiraClient) FormatField(fieldName string, value string) string {
167158
if fieldName == "domain" {
168159
return fmt.Sprintf("https://%s", value)
169160
}
170-
171161
return value
172162
}
173163

@@ -184,15 +174,14 @@ func (j *JiraClient) GetAuthFields() map[string]bool {
184174

185175
// Authenticate : Authenticates using the fields passed in
186176
func (j *JiraClient) Authenticate(fields map[string]string) bool {
187-
jiraClient, err := jira.NewClient(nil, fields["domain"])
188-
189-
if err != nil {
190-
return false
177+
tp := jira.BasicAuthTransport{
178+
Username: fields["username"],
179+
Password: fields["password"],
191180
}
192181

193-
res, err := jiraClient.Authentication.AcquireSessionCookie(fields["username"], fields["password"])
182+
jiraClient, err := jira.NewClient(tp.Client(), fields["domain"])
194183

195-
if err != nil || res == false {
184+
if err != nil {
196185
return false
197186
}
198187

pivotal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package gong
33
import (
44
"fmt"
55
"gopkg.in/salsita/go-pivotaltracker.v1/v5/pivotal"
6-
"strconv"
76
"regexp"
7+
"strconv"
88
)
99

1010
// PivotalClient : Struct implementing the generic Client interface
@@ -20,7 +20,7 @@ func NewPivotalClient() *PivotalClient {
2020

2121
func (p *PivotalClient) Create() (string, error) {
2222
fields, err := Load()
23-
23+
2424
if err != nil {
2525
fmt.Println(err)
2626
}

pivotal_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,29 @@ type PivotalClientSuit struct{}
1111

1212
var _ = Suite(&PivotalClientSuit{})
1313

14-
func (p *PivotalClientSuit) TestBrowseWithCorrectBranchName(c * C) {
14+
func (p *PivotalClientSuit) TestBrowseWithCorrectBranchName(c *C) {
1515
pivotalClient := &PivotalClient{}
1616

1717
url, err := pivotalClient.Browse("feature/124352-test-only")
1818
c.Assert(err, Equals, nil)
1919
c.Assert(url, Equals, "https://www.pivotaltracker.com/story/show/124352")
2020
}
2121

22-
func (p *PivotalClientSuit) TestBrowseWithIncorrectBranchName(c * C) {
22+
func (p *PivotalClientSuit) TestBrowseWithIncorrectBranchName(c *C) {
2323
pivotalClient := &PivotalClient{}
2424

2525
url, err := pivotalClient.Browse("feature/test-only")
2626
c.Assert(err, Equals, nil)
2727
c.Assert(url, Equals, "https://www.pivotaltracker.com/story/show/")
2828
}
2929

30-
func (p *PivotalClientSuit) TestGetPivotalIssueIDWithCorrectBranchName(c * C) {
30+
func (p *PivotalClientSuit) TestGetPivotalIssueIDWithCorrectBranchName(c *C) {
3131
branchName := "feature/1234-test-only"
3232
issueId := GetPivotalIssueID(branchName)
3333
c.Assert(issueId, Equals, "1234")
3434
}
3535

36-
37-
func (p *PivotalClientSuit) TestGetPivotalIssueIDWithInCorrectBranchName(c * C) {
36+
func (p *PivotalClientSuit) TestGetPivotalIssueIDWithInCorrectBranchName(c *C) {
3837
branchName := "feature/test-only"
3938
issueId := GetPivotalIssueID(branchName)
4039
c.Assert(issueId, Equals, "")

0 commit comments

Comments
 (0)