nameFromFile returns the name gh gives an artifact from a file: its base name, as typed rather than a symlink's target, cleaned up to fit the server's rule for names, since the user didn't type it. Names may contain letters, numbers, accent marks, spaces, ".", "-" and "_", and must start and end wit
(path string)
| 420 | // becomes "draft.md". The result is empty when the file name has no letters |
| 421 | // or numbers. |
| 422 | func nameFromFile(path string) string { |
| 423 | name := strings.Map(func(r rune) rune { |
| 424 | if isLetterOrNumber(r) || unicode.IsMark(r) || strings.ContainsRune(" .-_", r) { |
| 425 | return r |
| 426 | } |
| 427 | return -1 |
| 428 | }, filepath.Base(path)) |
| 429 | return strings.TrimFunc(name, func(r rune) bool { return !isLetterOrNumber(r) }) |
| 430 | } |
| 431 | |
| 432 | func isLetterOrNumber(r rune) bool { |
| 433 | return unicode.IsLetter(r) || unicode.IsNumber(r) |
no test coverage detected