gitpod/components/gitpod-cli/pkg/utils/parseGitpodConfig.go
Andrea Falzetti 1e24370e8e gitpod-cli: add gp rebuild cmd
Co-authored-by: Victor Nogueira <victor@gitpod.io>
2023-01-13 14:48:21 +01:00

34 lines
913 B
Go

// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package utils
import (
"errors"
"os"
"path/filepath"
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
yaml "gopkg.in/yaml.v2"
)
func ParseGitpodConfig(repoRoot string) (*gitpod.GitpodConfig, error) {
if repoRoot == "" {
return nil, errors.New("repoRoot is empty")
}
data, err := os.ReadFile(filepath.Join(repoRoot, ".gitpod.yml"))
if err != nil {
// .gitpod.yml not exist is ok
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
return nil, errors.New("read .gitpod.yml file failed: " + err.Error())
}
var config *gitpod.GitpodConfig
if err = yaml.Unmarshal(data, &config); err != nil {
return nil, errors.New("unmarshal .gitpod.yml file failed" + err.Error())
}
return config, nil
}