github.com/blend/go-sdk@v1.20240719.1/codeowners/parse_path.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - 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  	"fmt"
    12  	"strings"
    13  )
    14  
    15  // ParsePath parses a path line into a path and owners.
    16  func ParsePath(pathLine string) (output Path, err error) {
    17  	parts := strings.Split(pathLine, " ")
    18  	if len(parts) < 2 {
    19  		err = fmt.Errorf("invalid codeowners path line: %q", pathLine)
    20  		return
    21  	}
    22  	output.PathGlob = parts[0]
    23  	for _, owner := range parts[1:] {
    24  		owner = strings.TrimSpace(owner)
    25  		if owner != "" {
    26  			output.Owners = append(output.Owners, owner)
    27  		}
    28  	}
    29  	return
    30  }