| 317 | } |
| 318 | |
| 319 | func changedFilesNames(w io.Writer, r io.Reader) error { |
| 320 | diff, err := io.ReadAll(r) |
| 321 | if err != nil { |
| 322 | return err |
| 323 | } |
| 324 | |
| 325 | // This is kind of a gnarly regex. We're looking lines of the format: |
| 326 | // diff --git a/9114-triage b/9114-triage |
| 327 | // diff --git "a/hello-\360\237\230\200-world" "b/hello-\360\237\230\200-world" |
| 328 | // |
| 329 | // From these lines we would look to extract: |
| 330 | // 9114-triage |
| 331 | // "hello-\360\237\230\200-world" |
| 332 | // |
| 333 | // Note that the b/ is removed but in the second case the preceding quote remains. |
| 334 | // This is important for how git handles filenames that would be quoted with core.quotePath. |
| 335 | // https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath |
| 336 | // |
| 337 | // Thus we capture the quote if it exists, and everything that follows the b/ |
| 338 | // We then concatenate those two capture groups together which for the examples above would be: |
| 339 | // `` + 9114-triage |
| 340 | // `"`` + hello-\360\237\230\200-world" |
| 341 | // |
| 342 | // Where I'm using the `` to indicate a string to avoid confusion with the " character. |
| 343 | matches := diffHeaderRegexp.FindAllStringSubmatch(string(diff), -1) |
| 344 | |
| 345 | for _, val := range matches { |
| 346 | name := strings.TrimSpace(val[1] + val[2]) |
| 347 | if _, err := w.Write([]byte(name + "\n")); err != nil { |
| 348 | return err |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | return nil |
| 353 | } |
| 354 | |
| 355 | func sanitizedReader(r io.Reader) io.Reader { |
| 356 | return transform.NewReader(r, &asciisanitizer.Sanitizer{}) |