Skip to content
Merged
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
15 changes: 15 additions & 0 deletions githubtasksutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"

"golang.org/x/net/context"

pb "github.com/brotherlogic/githubtasks/proto"
)

func (s *Server) validateIntegrity(ctx context.Context) error {
Expand All @@ -13,6 +15,19 @@ func (s *Server) validateIntegrity(ctx context.Context) error {
if len(s.config.GetProjects()) == 0 {
s.RaiseIssue(ctx, "Task Issue", fmt.Sprintf("There are no projects listed"), false)
}

for _, project := range s.config.GetProjects() {
activeMilestone := false
for _, milestone := range project.GetMilestones() {
if milestone.GetState() == pb.Milestone_ACTIVE {
activeMilestone = true
}
}

if !activeMilestone {
s.RaiseIssue(ctx, "Task Issue", fmt.Sprintf("%v has no active milestones", project.GetName()), false)
}
}
}

return err
Expand Down
30 changes: 30 additions & 0 deletions githubtasksutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,33 @@ func TestEmptyConfig(t *testing.T) {
t.Errorf("Error in validation: %v", err)
}
}

func TestEmptyMilestones(t *testing.T) {
s := InitTestServer()

_, err := s.AddProject(context.Background(), &pb.AddProjectRequest{Add: &pb.Project{Name: "Hello", Milestones: []*pb.Milestone{&pb.Milestone{Name: "teting"}}}})
if err != nil {
t.Errorf("Error adding project: %v", err)
}

err = s.validateIntegrity(context.Background())

if err != nil {
t.Errorf("Error in validation: %v", err)
}
}

func TestActiveMilestone(t *testing.T) {
s := InitTestServer()

_, err := s.AddProject(context.Background(), &pb.AddProjectRequest{Add: &pb.Project{Name: "Hello", Milestones: []*pb.Milestone{&pb.Milestone{Name: "teting", State: pb.Milestone_ACTIVE}}}})
if err != nil {
t.Errorf("Error adding project: %v", err)
}

err = s.validateIntegrity(context.Background())

if err != nil {
t.Errorf("Error in validation: %v", err)
}
}