Skip to content

Commit a9e02fd

Browse files
committed
close #239 correct jira branch name conversion
1 parent ca0b1d5 commit a9e02fd

File tree

5 files changed

+60
-77
lines changed

5 files changed

+60
-77
lines changed

phlow/deliver.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,17 @@ func Deliver(conf *setting.ProjectSetting) {
4444
}
4545

4646
//Is branch master or is branch delivered
47-
if strings.HasPrefix(branchInfo.Current, "delivered/") || (branchInfo.Current == conf.IntegrationBranch) {
48-
fmt.Printf("Could not deliver: %s", branchInfo.Current)
47+
if strings.HasPrefix(branchInfo.Current, "delivered/") {
48+
fmt.Printf("It is not possible to deliver a branch already delivered: %s \n", branchInfo.Current)
4949
return
5050
}
51+
52+
//Delivering master
53+
if branchInfo.Current == conf.IntegrationBranch {
54+
fmt.Printf("It is not possible to deliver the integration branch: %s \n", branchInfo.Current)
55+
return
56+
}
57+
5158
//git push origin name:ready/name
5259
_, err = git.Push(conf.Remote, fmt.Sprintf("%s:%s/%s", branchInfo.Current, conf.DeliveryBranchPrefix, branchInfo.Current))
5360
if err != nil {

phlow/workon.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ func WorkOn(keyOrID string, conf *setting.ProjectSetting, update WorkOnUpdate) {
6868
branchInfo := githandler.AsList(out)
6969

7070
//Are we already on the branch we want to work on
71-
if plugins.IssueFromBranchName(branchInfo.Current) == keyOrID {
71+
if strings.HasPrefix(branchInfo.Current, keyOrID) {
7272
fmt.Fprintf(os.Stdout, "You are already on branch %s \n", ui.Format.Branch(branchInfo.Current))
7373
return
7474
}
7575
//Does another workspace already exist with the key or ID
7676
for _, branch := range branchInfo.List {
77-
if plugins.IssueFromBranchName(branch) == keyOrID {
77+
if strings.HasPrefix(branch, keyOrID) {
7878

7979
if _, err = git.CheckOut(branch); err != nil {
8080
fmt.Println(err)
@@ -88,7 +88,6 @@ func WorkOn(keyOrID string, conf *setting.ProjectSetting, update WorkOnUpdate) {
8888

8989
name, err := update(keyOrID, conf)
9090
if err != nil {
91-
9291
fmt.Println(err)
9392
os.Exit(1)
9493
}

plugins/plintf.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package plugins
2+
3+
//Authorization ...
4+
//interface for authorization with external service
5+
type Authorization func(URL, user, pass string) (token string, err error)
6+
7+
//Authentication ...
8+
//interface for authentication with external service
9+
type Authentication func(URL, user, pass string) (authenticated bool, err error)
10+
11+
//DefaultBranch ...
12+
//interface for getting the default branch of the external service
13+
type DefaultBranch func(URL, org, repo, token string) (defaultBranch string, err error)

plugins/plugin.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ import (
66
"strings"
77
)
88

9-
//Authorization ...
10-
//interface for authorization with external service
11-
type Authorization func(URL, user, pass string) (token string, err error)
12-
13-
//Authentication ...
14-
//interface for authentication with external service
15-
type Authentication func(URL, user, pass string) (authenticated bool, err error)
16-
17-
//DefaultBranch ...
18-
//interface for getting the default branch of the external service
19-
type DefaultBranch func(URL, org, repo, token string) (defaultBranch string, err error)
20-
219
//PhlowLabels ...
2210
//Map of labels in the phlow
2311
var PhlowLabels map[string]*PhlowLabel

plugins/plugin_test.go

Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,53 @@
1-
package plugins
1+
package plugins_test
22

33
import (
4-
"testing"
4+
. "github.com/praqma/git-phlow/plugins"
55

6-
. "github.com/smartystreets/goconvey/convey"
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
78
"strconv"
89
)
910

10-
type testCase struct {
11-
issue int
12-
branchName string
13-
expected string
14-
casedesc string
15-
}
11+
var _ = Describe("Plugin", func() {
1612

17-
/* Branch naming conventions
18-
* - cant begin with '.'
19-
* - cant have double dot '..'
20-
* - cant have chars '^', '~', ':'
21-
* - end with backslash /
22-
* - end with ".lock"
23-
* - contain \
24-
*/
25-
26-
func TestBranchNameFromIssue(t *testing.T) {
27-
testsToRun := [7]testCase{
28-
{issue: 12, branchName: "work on iss", expected: "12-work-on-iss", casedesc: "Test replaces whitespaces with dash '-'"},
29-
{issue: 45, branchName: "Case SENsitivity", expected: "45-case-sensitivity", casedesc: "Test converts charecters to lowercase"},
30-
{issue: 15, branchName: ".branch name", expected: "15-branch-name", casedesc: "Test removes . prefix"},
31-
{issue: 220, branchName: "^^..:~:name", expected: "220-name", casedesc: "removes ASCII control characters"},
32-
{issue: 2735, branchName: "name/", expected: "2735-name", casedesc: "test removes end / "},
33-
{issue: 234567, branchName: ".NAME.is\"dotted", expected: "234567-name-is-dotted", casedesc: "test removes backslash"},
34-
{issue: 672, branchName: "add big data blog /", expected: "672-add-big-data-blog", casedesc: "remove forward slash"},
13+
type testCase struct {
14+
issue int
15+
branchName string
16+
expected string
17+
casedesc string
3518
}
3619

37-
Convey("Running tests on 'BranchNameFromIssue'", t, func() {
38-
39-
for _, currentTest := range testsToRun {
40-
41-
Convey(currentTest.casedesc, func() {
42-
actualName := BranchNameFromIssue(strconv.Itoa(currentTest.issue), currentTest.branchName)
43-
t.Log(currentTest.branchName)
44-
So(actualName, ShouldEqual, currentTest.expected)
45-
})
20+
/* Branch naming conventions
21+
* - cant begin with '.'
22+
* - cant have double dot '..'
23+
* - cant have chars '^', '~', ':'
24+
* - end with backslash /
25+
* - end with ".lock"
26+
* - contain \
27+
*/
28+
29+
Describe("Branch name from issue", func() {
30+
testsToRun := [7]testCase{
31+
{issue: 12, branchName: "work on iss", expected: "12-work-on-iss", casedesc: "Test replaces whitespaces with dash '-'"},
32+
{issue: 45, branchName: "Case SENsitivity", expected: "45-case-sensitivity", casedesc: "Test converts charecters to lowercase"},
33+
{issue: 15, branchName: ".branch name", expected: "15-branch-name", casedesc: "Test removes . prefix"},
34+
{issue: 220, branchName: "^^..:~:name", expected: "220-name", casedesc: "removes ASCII control characters"},
35+
{issue: 2735, branchName: "name/", expected: "2735-name", casedesc: "test removes end / "},
36+
{issue: 234567, branchName: ".NAME.is\"dotted", expected: "234567-name-is-dotted", casedesc: "test removes backslash"},
37+
{issue: 672, branchName: "add big data blog /", expected: "672-add-big-data-blog", casedesc: "remove forward slash"},
4638
}
47-
})
48-
}
4939

50-
func TestStringConcat(t *testing.T) {
40+
Context("Names should follow format rules", func() {
5141

52-
Convey("Running tests on 'effecientStringConcat' function ", t, func() {
42+
for _, currentTest := range testsToRun {
5343

54-
Convey("Test variable inputs get concatenated correctly", func() {
55-
var expectedLong = "created 'something' new"
56-
var actualLong = efficientConcatString("created '", "something", "' new")
57-
So(actualLong, ShouldEqual, expectedLong)
58-
})
44+
It(currentTest.casedesc, func() {
45+
actualName := BranchNameFromIssue(strconv.Itoa(currentTest.issue), currentTest.branchName)
5946

60-
Convey("Test funny signs gets concatenated as well", func() {
61-
var expectedShort = "j$¢‰¿≈¯¯¯"
62-
var actualShort = efficientConcatString("j$¢‰¿≈", "¯¯¯")
63-
So(expectedShort, ShouldEqual, actualShort)
47+
Ω(actualName).Should(Equal(currentTest.expected))
48+
})
49+
}
6450
})
6551
})
66-
}
6752

68-
func TestGetIssueFromBranch(t *testing.T) {
69-
Convey("Running tests on 'GetIssuesFromBranch'", t, func() {
70-
71-
Convey("GetIssueSFromBranch should return 1", func() {
72-
73-
i := IssueFromBranchName("39-enable---Add-sign-in-function")
74-
So(i, ShouldEqual, "39")
75-
})
76-
})
77-
}
53+
})

0 commit comments

Comments
 (0)