refactor: replace explicit fields with tag-based property system
This commit is contained in:
@@ -23,40 +23,13 @@ const (
|
||||
RelAssignee RelType = "assignee"
|
||||
)
|
||||
|
||||
func ParseTag(s string) (key, value string, isProperty bool) {
|
||||
if strings.HasPrefix(s, "_") {
|
||||
if parts := strings.SplitN(s[1:], "::", 2); len(parts) == 2 {
|
||||
return parts[0], parts[1], true
|
||||
}
|
||||
}
|
||||
return "", s, false
|
||||
}
|
||||
|
||||
func PropertyTag(key, value string) string {
|
||||
return "_" + key + "::" + value
|
||||
}
|
||||
|
||||
func (n *Node) GetProperty(key string) string {
|
||||
for _, tag := range n.Tags {
|
||||
if k, v, ok := ParseTag(tag); ok && k == key {
|
||||
return v
|
||||
func (n *Node) GetProperty(k string) string {
|
||||
for _, t := range n.Tags {
|
||||
if strings.HasPrefix(t, "_") {
|
||||
if p := strings.SplitN(t[1:], "::", 2); len(p) == 2 && p[0] == k {
|
||||
return p[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (n *Node) GetType() string {
|
||||
if t := n.GetProperty("type"); t != "" {
|
||||
return t
|
||||
}
|
||||
return "issue"
|
||||
}
|
||||
|
||||
func (n *Node) HasTag(tag string) bool {
|
||||
for _, t := range n.Tags {
|
||||
if t == tag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user