@@ -2,29 +2,12 @@ package config
2
2
3
3
import (
4
4
"bytes"
5
- "errors"
6
5
"io"
7
- "io/fs"
8
6
"os"
9
- "os/exec"
10
- "path/filepath"
11
- "strings"
12
7
13
8
"gopkg.in/yaml.v3"
14
9
)
15
10
16
- // LoadFileFromStandardLocation loads and parses a GITLAB_LABELS file at one of the
17
- // standard locations for GITLAB_LABELS files (./, .github/, docs/). If run from a
18
- // git repository, all paths are relative to the repository root.
19
- func LoadFileFromStandardLocation () (* Config , error ) {
20
- path := findFileAtStandardLocation ()
21
- if path == "" {
22
- return nil , errors .New ("could not find GITLAB_LABELS file at any of the standard locations" )
23
- }
24
-
25
- return LoadFile (path )
26
- }
27
-
28
11
// LoadFile loads and parses a GITLAB_LABELS file at the path specified.
29
12
func LoadFile (path string ) (* Config , error ) {
30
13
f , err := os .Open (path )
@@ -35,47 +18,6 @@ func LoadFile(path string) (*Config, error) {
35
18
return ParseFile (f )
36
19
}
37
20
38
- func findFileAtStandardLocation () string {
39
- pathPrefix := ""
40
-
41
- repoRoot , inRepo := findRepositoryRoot ()
42
- if inRepo {
43
- pathPrefix = repoRoot
44
- }
45
-
46
- for _ , path := range []string {".scm-engine.yml" , ".gitlab/scm-engine.yml" , ".github/scm-engine.yml" } {
47
- fullPath := filepath .Join (pathPrefix , path )
48
-
49
- if fileExists (fullPath ) {
50
- return fullPath
51
- }
52
- }
53
-
54
- return ""
55
- }
56
-
57
- // fileExist checks if a normal file exists at the path specified.
58
- func fileExists (path string ) bool {
59
- info , err := os .Stat (path )
60
- if errors .Is (err , fs .ErrNotExist ) {
61
- return false
62
- }
63
-
64
- return ! info .IsDir ()
65
- }
66
-
67
- // findRepositoryRoot returns the path to the root of the git repository, if
68
- // we're currently in one. If we're not in a git repository, the boolean return
69
- // value is false.
70
- func findRepositoryRoot () (string , bool ) {
71
- output , err := exec .Command ("git" , "rev-parse" , "--show-toplevel" ).Output ()
72
- if err != nil {
73
- return "" , false
74
- }
75
-
76
- return strings .TrimSpace (string (output )), true
77
- }
78
-
79
21
// ParseFile parses a Gitlabber file, returning a Config.
80
22
func ParseFile (f io.Reader ) (* Config , error ) {
81
23
config := & Config {}
0 commit comments