ResolveComment search for a Bug/Comment combination matching the merged bug/comment Id prefix. Returns the Bug containing the Comment and the Comment's Id.
(prefix string)
| 66 | // bug/comment Id prefix. Returns the Bug containing the Comment and the Comment's |
| 67 | // Id. |
| 68 | func (c *RepoCacheBug) ResolveComment(prefix string) (*BugCache, entity.CombinedId, error) { |
| 69 | bugPrefix, _ := entity.SeparateIds(prefix) |
| 70 | bugCandidate := make([]entity.Id, 0, 5) |
| 71 | |
| 72 | // build a list of possible matching bugs |
| 73 | c.mu.RLock() |
| 74 | for _, excerpt := range c.excerpts { |
| 75 | if excerpt.Id().HasPrefix(bugPrefix) { |
| 76 | bugCandidate = append(bugCandidate, excerpt.Id()) |
| 77 | } |
| 78 | } |
| 79 | c.mu.RUnlock() |
| 80 | |
| 81 | matchingBugIds := make([]entity.Id, 0, 5) |
| 82 | matchingCommentId := entity.UnsetCombinedId |
| 83 | var matchingBug *BugCache |
| 84 | |
| 85 | // search for matching comments |
| 86 | // searching every bug candidate allow for some collision with the bug prefix only, |
| 87 | // before being refined with the full comment prefix |
| 88 | for _, bugId := range bugCandidate { |
| 89 | b, err := c.Resolve(bugId) |
| 90 | if err != nil { |
| 91 | return nil, entity.UnsetCombinedId, err |
| 92 | } |
| 93 | |
| 94 | for _, comment := range b.Snapshot().Comments { |
| 95 | if comment.CombinedId().HasPrefix(prefix) { |
| 96 | matchingBugIds = append(matchingBugIds, bugId) |
| 97 | matchingBug = b |
| 98 | matchingCommentId = comment.CombinedId() |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if len(matchingBugIds) > 1 { |
| 104 | return nil, entity.UnsetCombinedId, entity.NewErrMultipleMatch("bug/comment", matchingBugIds) |
| 105 | } else if len(matchingBugIds) == 0 { |
| 106 | return nil, entity.UnsetCombinedId, errors.New("comment doesn't exist") |
| 107 | } |
| 108 | |
| 109 | return matchingBug, matchingCommentId, nil |
| 110 | } |
| 111 | |
| 112 | // Query return the id of all Bug matching the given Query |
| 113 | func (c *RepoCacheBug) Query(q *query.Query) ([]entity.Id, error) { |
no test coverage detected