removeProjectNode removes a project entry matching key=val from the projects sequence. Returns the removed project's ID and true, or "" and false if not found.
(doc *yaml.Node, key, val string)
| 302 | // removeProjectNode removes a project entry matching key=val from the projects sequence. |
| 303 | // Returns the removed project's ID and true, or "" and false if not found. |
| 304 | func removeProjectNode(doc *yaml.Node, key, val string) (string, bool) { |
| 305 | if len(doc.Content) == 0 { |
| 306 | return "", false |
| 307 | } |
| 308 | seq := findProjectsSequence(doc.Content[0]) |
| 309 | if seq == nil || seq.Kind != yaml.SequenceNode { |
| 310 | return "", false |
| 311 | } |
| 312 | for i, item := range seq.Content { |
| 313 | entry := nodeToProjectEntry(item) |
| 314 | if matchesEntry(entry, key, val) { |
| 315 | seq.Content = append(seq.Content[:i], seq.Content[i+1:]...) |
| 316 | return entry.ID, true |
| 317 | } |
| 318 | } |
| 319 | return "", false |
| 320 | } |
| 321 | |
| 322 | func matchesEntry(entry GlobalProjectEntry, key, val string) bool { |
| 323 | switch key { |
no test coverage detected