| package service |
| |
| import ( |
| "strconv" |
| "strings" |
| ) |
| |
| type gerritMeta struct { |
| patchSet int64 |
| changeId string |
| commit string |
| } |
| |
| // parseGerritMetadata takes a NoteDB metadata entry and extracts info from it. |
| func parseGerritMetadata(messages []string) *gerritMeta { |
| meta := &gerritMeta{} |
| |
| for _, message := range messages { |
| for _, line := range strings.Split(message, "\n") { |
| line = strings.TrimSpace(line) |
| if len(line) == 0 { |
| continue |
| } |
| |
| parts := strings.SplitN(line, ":", 2) |
| if len(parts) < 2 { |
| continue |
| } |
| k, v := parts[0], strings.TrimSpace(parts[1]) |
| |
| switch k { |
| case "Patch-set": |
| n, err := strconv.ParseInt(v, 10, 64) |
| if err != nil { |
| continue |
| } |
| meta.patchSet = n |
| case "Change-id": |
| meta.changeId = v |
| case "Commit": |
| meta.commit = v |
| } |
| } |
| } |
| |
| if meta.patchSet == 0 { |
| return nil |
| } |
| if meta.changeId == "" { |
| return nil |
| } |
| if meta.commit == "" { |
| return nil |
| } |
| return meta |
| } |