Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/pkg/utils/parseGitpodConfig.go
2500 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package utils
6
7
import (
8
"errors"
9
"os"
10
"path/filepath"
11
12
gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
13
yaml "gopkg.in/yaml.v2"
14
)
15
16
func ParseGitpodConfig(repoRoot string) (*gitpod.GitpodConfig, error) {
17
if repoRoot == "" {
18
return nil, errors.New("repoRoot is empty")
19
}
20
data, err := os.ReadFile(filepath.Join(repoRoot, ".gitpod.yml"))
21
if err != nil {
22
// .gitpod.yml not exist is ok
23
if errors.Is(err, os.ErrNotExist) {
24
return nil, nil
25
}
26
return nil, errors.New("read .gitpod.yml file failed: " + err.Error())
27
}
28
var config *gitpod.GitpodConfig
29
if err = yaml.Unmarshal(data, &config); err != nil {
30
return nil, errors.New("unmarshal .gitpod.yml file failed" + err.Error())
31
}
32
return config, nil
33
}
34
35