github.com/blend/go-sdk@v1.20220411.3/codeowners/source.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  	"fmt"
    12  	"io"
    13  	"strings"
    14  )
    15  
    16  // Source is a set of ownership entries.
    17  type Source struct {
    18  	Source string
    19  	Paths  []Path
    20  }
    21  
    22  // WriteTo writes the owners to a given file.
    23  func (s Source) WriteTo(wr io.Writer) (total int64, err error) {
    24  	var n int
    25  	n, err = fmt.Fprintf(wr, "%s%s\n", OwnersFileSourceComment, s.Source)
    26  	if err != nil {
    27  		return
    28  	}
    29  	total += int64(n)
    30  	for _, entry := range s.Paths {
    31  		n, err = fmt.Fprintf(wr, "%s %s\n", entry.PathGlob, strings.Join(entry.Owners, " "))
    32  		if err != nil {
    33  			return
    34  		}
    35  		total += int64(n)
    36  	}
    37  	n, err = fmt.Fprintf(wr, "%s%s\n", OwnersFileSourceEndComment, s.Source)
    38  	total += int64(n)
    39  	return
    40  }