mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
34 lines
913 B
Go
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
|
|
}
|