-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete branches that correspond to accepted stories [#176488902]
Co-authored-by: Charlie Nazario <cnazario@vmware.com>
1 parent
d097114
commit 0c98509
Showing
14 changed files
with
221 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/git-story-branch/git-story-branch/adapters" | ||
"github.com/git-story-branch/git-story-branch/usecases" | ||
"gopkg.in/salsita/go-pivotaltracker.v2/v5/pivotal" | ||
) | ||
|
||
func newTracker() usecases.Tracker { | ||
apiToken := os.Getenv("TRACKER_API_TOKEN") | ||
client := pivotal.NewClient(apiToken) | ||
return adapters.NewPivotalTracker(client.Stories) | ||
} | ||
|
||
func main() { | ||
tracker := newTracker() | ||
results := usecases.SweepAcceptedStories(adapters.NewRepository(), tracker) | ||
|
||
hasError := false | ||
for branchName, error := range results { | ||
if error != nil { | ||
hasError = true | ||
fmt.Printf("Could not delete '%s', %s\n", branchName, error) | ||
} else { | ||
fmt.Printf("Deleted '%s'\n", branchName) | ||
} | ||
} | ||
if hasError { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package usecases | ||
|
||
type Story struct { | ||
ID int | ||
Description string | ||
State string | ||
URL string | ||
} | ||
|
||
type Tracker interface { | ||
GetStory(storyID int) (*Story, error) | ||
} | ||
|
||
type Repository interface { | ||
GetCurrentBranchName() string | ||
DeleteBranch(branchName string) error | ||
GetAllBranchNames() []string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package usecases | ||
|
||
type ResultMap map[string]error | ||
|
||
// SweepAcceptedStories returns a map of the branches it attempted to delete and an error if that branch was unable to be deleted | ||
func SweepAcceptedStories(repo Repository, tracker Tracker) ResultMap { | ||
branchErrors := make(map[string]error) | ||
|
||
branchNames := repo.GetAllBranchNames() | ||
|
||
for _, branchName := range branchNames { | ||
story, _ := GetStoryByBranchName(branchName, tracker) | ||
|
||
if story != nil && story.State == "accepted" { | ||
branchErrors[branchName] = repo.DeleteBranch(branchName) | ||
} | ||
} | ||
|
||
return branchErrors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package usecases_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
usecases "github.com/git-story-branch/git-story-branch/usecases" | ||
) | ||
|
||
var _ = Describe("Story Sweeper use case", func() { | ||
It("should delete all branches that correspond to accepted stories", func() { | ||
mockGitRepo := &MockGitRepository{branchNames: []string{"main", "some-accepted-story-#123", "some-wip-story-#234"}} | ||
mockTrackerReader := MockPivotalTrackerReader{} | ||
result := usecases.SweepAcceptedStories(mockGitRepo, mockTrackerReader) | ||
|
||
var resultContainsStory bool | ||
_, resultContainsStory = result["some-accepted-story-#123"] | ||
|
||
Expect(resultContainsStory).To(BeTrue()) | ||
Expect(mockGitRepo.deletedBranches).To(Equal([]string{"some-accepted-story-#123"})) | ||
}) | ||
|
||
It("should return an error if the branch is unable to be deleted", func() { | ||
mockGitRepo := &MockGitRepository{ | ||
branchNames: []string{"main", "some-accepted-story-#123", "some-accepted-story-#789", "some-wip-story-#234"}, | ||
erroredBranches: []string{"some-accepted-story-#123"}, | ||
} | ||
mockTrackerReader := MockPivotalTrackerReader{} | ||
results := usecases.SweepAcceptedStories(mockGitRepo, mockTrackerReader) | ||
|
||
Expect(results["some-accepted-story-#123"]).NotTo(BeNil()) | ||
Expect(results["some-accepted-story-#789"]).To(BeNil()) | ||
}) | ||
}) |