Skip to content

Commit

Permalink
separate function to create Project instance
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Aug 6, 2023
1 parent 85acf7b commit b99ef38
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@ func absPath(path string) string {
func findProject(path string) (*Project, error) {
d := absPath(path)
for {
w := filepath.Join(d, ".github", "workflows")
if s, err := os.Stat(w); err == nil && s.IsDir() {
g := filepath.Join(d, ".git")
if _, err := os.Stat(g); err == nil { // Note: .git may be a file
c, err := loadRepoConfig(d)
if err != nil {
return nil, err
}
return &Project{root: d, config: c}, nil
if s, err := os.Stat(filepath.Join(d, ".github", "workflows")); err == nil && s.IsDir() {
if _, err := os.Stat(filepath.Join(d, ".git")); err == nil { // Note: .git may be a file
return NewProject(d)
}
}

Expand All @@ -44,6 +38,16 @@ func findProject(path string) (*Project, error) {
}
}

// NewProject creates a new instance with a file path to the root directory of the repository.
// This function returns an error when failing to parse an actionlint config file in the repository.
func NewProject(root string) (*Project, error) {
c, err := loadRepoConfig(root)
if err != nil {
return nil, err
}
return &Project{root, c}, nil
}

// RootDir returns a root directory path of the GitHub project repository.
func (p *Project) RootDir() string {
return p.root
Expand Down

0 comments on commit b99ef38

Please sign in to comment.