-
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.
Add file granularity and CODEOWNERS support (#81)
* wip Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * add project and subproject rules; groups are skipped by default if project is subproject Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * parse codeowners Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * support directories in codeowners Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * handle wildcards Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * use project exploration and applyonsubprojects Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * add also subproject without entry in codeowner Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * do not fail when codeowners is not there Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * remove useless rules Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * cleanup Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * subprojects pattern Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * rename subproject to filepath Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * file block in the config Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * validation Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * fixed tests, removed debug lines, changed some lines from info to debug Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * lint Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * use codeowners lib, add mapping Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * fix tests Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * linter Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * lint Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * remove hardcoded mapping Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * revert config example Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * linter Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * fix test Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * tidy Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * codeowners mapping as top level config Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * linter Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * add one more validation, update readme Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * file granularity example Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * linter and readme Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * kebab case Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> * rename owner map Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> --------- Signed-off-by: Stefano Celentano <[email protected]> Signed-off-by: Stefano Celentano <[email protected]> Co-authored-by: Mathieu Corbin <[email protected]> Co-authored-by: Stefano Celentano <[email protected]>
- Loading branch information
1 parent
bb32cb3
commit 1c4c709
Showing
20 changed files
with
344 additions
and
39 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
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
Validating CODEOWNERS rules …
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,8 @@ | ||
### team-cft-bookkeeping | ||
[CFT-Bookkeeping] @team-cft-bookkeeping | ||
app/announcers/attachment_announcer.rb @team-cft-bookkeeping | ||
|
||
[cft-sepa] @team-cft-sepa | ||
app/controllers/**/external_transfers_controller.rb @team-cft-sepa | ||
app/controllers/*/mandates_controller.rb @team-cft-sepa | ||
app/services/transfers/ @team-cft-sepa |
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,56 @@ | ||
package codeowners | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/hairyhenderson/go-codeowners" | ||
"github.com/qonto/standards-insights/config" | ||
) | ||
|
||
type Codeowners struct { | ||
codeowners *codeowners.Codeowners | ||
configPath string | ||
} | ||
|
||
func NewCodeowners(path string, configPath string) (*Codeowners, error) { | ||
// open filesystem rooted at current working directory | ||
fsys := os.DirFS(path) | ||
|
||
c, err := codeowners.FromFileWithFS(fsys, "CODEOWNERS") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Codeowners{ | ||
codeowners: c, | ||
configPath: configPath, | ||
}, nil | ||
} | ||
|
||
func (c *Codeowners) GetOwners(path string) (string, bool) { | ||
if c == nil || c.codeowners == nil { | ||
return "", false | ||
} | ||
|
||
owners := c.codeowners.Owners(path) | ||
if len(owners) == 0 { | ||
return "", false | ||
} | ||
|
||
// Attempt to load the configuration | ||
config, _, err := config.New(c.configPath) | ||
var ownerMap map[string]string | ||
if err != nil { | ||
// If config cannot be found, use an empty ownerMap | ||
ownerMap = map[string]string{} | ||
} else { | ||
ownerMap = config.CodeownerOverride | ||
} | ||
|
||
owner := owners[0] | ||
if mappedOwner, found := ownerMap[owner]; found { | ||
return mappedOwner, true | ||
} | ||
|
||
return owner, true | ||
} |
Oops, something went wrong.