Skip to content

Commit b99ef38

Browse files
committed
separate function to create Project instance
1 parent 85acf7b commit b99ef38

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

project.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@ func absPath(path string) string {
2424
func findProject(path string) (*Project, error) {
2525
d := absPath(path)
2626
for {
27-
w := filepath.Join(d, ".github", "workflows")
28-
if s, err := os.Stat(w); err == nil && s.IsDir() {
29-
g := filepath.Join(d, ".git")
30-
if _, err := os.Stat(g); err == nil { // Note: .git may be a file
31-
c, err := loadRepoConfig(d)
32-
if err != nil {
33-
return nil, err
34-
}
35-
return &Project{root: d, config: c}, nil
27+
if s, err := os.Stat(filepath.Join(d, ".github", "workflows")); err == nil && s.IsDir() {
28+
if _, err := os.Stat(filepath.Join(d, ".git")); err == nil { // Note: .git may be a file
29+
return NewProject(d)
3630
}
3731
}
3832

@@ -44,6 +38,16 @@ func findProject(path string) (*Project, error) {
4438
}
4539
}
4640

41+
// NewProject creates a new instance with a file path to the root directory of the repository.
42+
// This function returns an error when failing to parse an actionlint config file in the repository.
43+
func NewProject(root string) (*Project, error) {
44+
c, err := loadRepoConfig(root)
45+
if err != nil {
46+
return nil, err
47+
}
48+
return &Project{root, c}, nil
49+
}
50+
4751
// RootDir returns a root directory path of the GitHub project repository.
4852
func (p *Project) RootDir() string {
4953
return p.root

0 commit comments

Comments
 (0)