forked from goliac-project/goliac
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request goliac-project#12 from AlayaCare/repo_visibility
Repo visibility
- Loading branch information
Showing
26 changed files
with
357 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package engine | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/goliac-project/goliac/internal/config" | ||
) | ||
|
||
type ReconciliatorFilter interface { | ||
RepositoryFilter(reponame string, repo *GithubRepoComparable) *GithubRepoComparable | ||
} | ||
|
||
type ReconciliatorFilterImpl struct { | ||
isEnterprise bool | ||
ForbidPublicRepositories bool | ||
ForbidPulicRepostitoriesExcept []*regexp.Regexp | ||
} | ||
|
||
func NewReconciliatorFilter(isEnterprise bool, config *config.RepositoryConfig) *ReconciliatorFilterImpl { | ||
exclude := []*regexp.Regexp{} | ||
if config != nil { | ||
for _, pattern := range config.VisibilityRules.ForbidPublicRepositoriesExclusions { | ||
exclude = append(exclude, regexp.MustCompile("^"+pattern+"$")) | ||
} | ||
} | ||
|
||
return &ReconciliatorFilterImpl{ | ||
isEnterprise: isEnterprise, | ||
ForbidPublicRepositories: config.VisibilityRules.ForbidPublicRepositories, | ||
ForbidPulicRepostitoriesExcept: exclude, | ||
} | ||
} | ||
|
||
func (r *ReconciliatorFilterImpl) RepositoryFilter(reponame string, repo *GithubRepoComparable) *GithubRepoComparable { | ||
if !r.isEnterprise { | ||
if repo.Visibility == "internal" { | ||
repo.Visibility = "private" | ||
} | ||
} | ||
|
||
if r.ForbidPublicRepositories { | ||
for _, exclude := range r.ForbidPulicRepostitoriesExcept { | ||
if exclude.MatchString(reponame) { | ||
return repo | ||
} | ||
} | ||
if repo.Visibility == "public" { | ||
repo.Visibility = "private" | ||
} | ||
} | ||
return repo | ||
} |
Oops, something went wrong.