-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprd.go
More file actions
81 lines (70 loc) · 1.78 KB
/
Copy pathprd.go
File metadata and controls
81 lines (70 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"encoding/json"
"os"
"sort"
)
// PRD represents the product requirements document
type PRD struct {
Project string `json:"project"`
BranchName string `json:"branchName"`
Description string `json:"description"`
UserStories []Story `json:"userStories"`
}
// Story represents a user story in the PRD
type Story struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Priority int `json:"priority"`
Passes bool `json:"passes"`
Notes string `json:"notes"`
AcceptanceCriteria []string `json:"acceptanceCriteria"`
}
// LoadPRD reads and parses the PRD JSON file
func LoadPRD(path string) (PRD, error) {
data, err := os.ReadFile(path)
if err != nil {
return PRD{}, err
}
var prd PRD
if err := json.Unmarshal(data, &prd); err != nil {
return PRD{}, err
}
sort.Slice(prd.UserStories, func(i, j int) bool {
return prd.UserStories[i].Priority < prd.UserStories[j].Priority
})
return prd, nil
}
// CountCompleted returns the number of completed stories
func CountCompleted(stories []Story) int {
count := 0
for _, s := range stories {
if s.Passes {
count++
}
}
return count
}
// CountPending returns the number of pending (incomplete) stories
func CountPending(stories []Story) int {
return len(stories) - CountCompleted(stories)
}
// GetNextStory returns the next incomplete story by priority
func GetNextStory(stories []Story) *Story {
for i := range stories {
if !stories[i].Passes {
return &stories[i]
}
}
return nil
}
// GetStoryByID returns a story by its ID
func GetStoryByID(stories []Story, id string) *Story {
for i := range stories {
if stories[i].ID == id {
return &stories[i]
}
}
return nil
}