go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/cmd/recipe_wrapper/manifest/manifest.go (about)

     1  // Copyright 2019 The Fuchsia Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package manifest
     6  
     7  import (
     8  	"encoding/xml"
     9  	"fmt"
    10  	"io"
    11  )
    12  
    13  type manifest struct {
    14  	XMLName     xml.Name `xml:"manifest"`
    15  	ProjectList projects `xml:"projects"`
    16  }
    17  
    18  type projects struct {
    19  	XMLName  xml.Name     `xml:"projects"`
    20  	Projects []projectDef `xml:"project"`
    21  }
    22  
    23  type projectDef struct {
    24  	XMLName  xml.Name `xml:"project"`
    25  	Remote   string   `xml:"remote,attr"`
    26  	Revision string   `xml:"revision,attr"`
    27  }
    28  
    29  // Resolve the recipes project given a manifest input.
    30  func ResolveRecipesProject(r io.Reader, remote string) (*projectDef, error) {
    31  	bytes, err := io.ReadAll(r)
    32  	if err != nil {
    33  		return nil, fmt.Errorf("could not read input")
    34  	}
    35  	var manifest manifest
    36  	err = xml.Unmarshal(bytes, &manifest)
    37  	if err != nil {
    38  		return nil, fmt.Errorf("could not parse input as manifest XML")
    39  	}
    40  	for _, proj := range manifest.ProjectList.Projects {
    41  		if proj.Remote != remote {
    42  			continue
    43  		}
    44  		return &proj, nil
    45  	}
    46  	return nil, fmt.Errorf("could not find %s project", remote)
    47  }