github.com/blend/go-sdk@v1.20220411.3/codeowners/read.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package codeowners 9 10 import ( 11 "bufio" 12 "io" 13 "strings" 14 ) 15 16 // Read reads a codeowners file. 17 func Read(r io.Reader) (output File, err error) { 18 scanner := bufio.NewScanner(r) 19 var line string 20 var codeownersEntry Source 21 for scanner.Scan() { 22 line = scanner.Text() 23 line = strings.TrimSpace(line) 24 if line == "" { 25 continue 26 } else if strings.HasPrefix(line, OwnersFileSourceComment) { 27 codeownersEntry.Source = strings.TrimPrefix(line, OwnersFileSourceComment) 28 continue 29 } else if strings.HasPrefix(line, OwnersFileSourceEndComment) { 30 output = append(output, codeownersEntry) 31 codeownersEntry = Source{} 32 continue 33 } else if strings.HasPrefix(line, "#") { 34 continue 35 } 36 37 var codeownersEntryPath Path 38 codeownersEntryPath, err = ParsePath(line) 39 if err != nil { 40 return 41 } 42 codeownersEntry.Paths = append(codeownersEntry.Paths, codeownersEntryPath) 43 } 44 return 45 }