MCPcopy Index your code
hub / github.com/git-bug/git-bug / Parse

Method Parse

bridge/gitlab/parser/parser.go:52–82  ·  view source on GitHub ↗

Parse is used to fetch the new title from a "changed title" event this func is a great example of something that is _extremely_ fragile; the input string is pulled from the body of a gitlab message containing html fragments, and has changed on at least [one occasion][0], breaking our test pipelines

()

Source from the content-addressed store, hash-verified

50// [0]: https://github.com/git-bug/git-bug/issues/1367
51// [1]: https://docs.gitlab.com/api/resource_iteration_events/#list-project-issue-iteration-events
52func (p titleParser) Parse() (string, error) {
53 var reHTML = regexp.MustCompile(`.* to <code\s+class="idiff"\s*>(.*?)</code>`)
54 var reMD = regexp.MustCompile(`.* to \*\*(.*)\*\*`)
55
56 matchHTML := reHTML.FindAllStringSubmatch(p.input, -1)
57 matchMD := reMD.FindAllStringSubmatch(p.input, -1)
58
59 if len(matchHTML) == 1 {
60 t, err := p.stripHTML(matchHTML[0][1])
61 if err != nil {
62 return "", fmt.Errorf("unable to strip HTML from new title: %q", t)
63 }
64 return strings.TrimSpace(t), nil
65 }
66
67 if len(matchMD) == 1 {
68 reDiff := regexp.MustCompile(`{\+(.*?)\+}`)
69
70 t := matchMD[0][1]
71 t = reDiff.ReplaceAllString(t, "$1")
72
73 return strings.TrimSpace(t), nil
74 }
75
76 return "", fmt.Errorf(
77 "failed to extract title: html=%d md=%d input=%q",
78 len(matchHTML),
79 len(matchMD),
80 p.input,
81 )
82}
83
84// stripHTML removes all html tags from a provided string
85func (p titleParser) stripHTML(s string) (string, error) {

Callers

nothing calls this directly

Calls 2

stripHTMLMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected