From 1f381f4140ea81d71a2ad69edd535f76db1d319c Mon Sep 17 00:00:00 2001 From: Simon Tucker Date: Sat, 11 Jan 2020 11:51:38 -0800 Subject: [PATCH] validate on active milestones. This closes #14. --- githubtasksutils.go | 15 +++++++++++++++ githubtasksutils_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/githubtasksutils.go b/githubtasksutils.go index e974f2ee..a88a2bf6 100644 --- a/githubtasksutils.go +++ b/githubtasksutils.go @@ -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 { @@ -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 diff --git a/githubtasksutils_test.go b/githubtasksutils_test.go index 102363aa..ba5329aa 100644 --- a/githubtasksutils_test.go +++ b/githubtasksutils_test.go @@ -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) + } +}