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