Skip to content

Commit a9e75b0

Browse files
authored
Merge pull request #515 from dhiller/handle-invalid-owners-aliases-on-verify-owners
fix(verify-owners): handle invalid OWNERS_ALIASES file case
2 parents f49c615 + 081cdc6 commit a9e75b0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pkg/plugins/verify-owners/verify-owners.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,17 @@ func handle(ghc githubClient, gc git.ClientFactory, roc repoownersClient, log *l
273273
// If the file was modified, check for non trusted users in the newly added owners.
274274
nonTrustedUsers, trustedUsers, repoAliases, err := nonTrustedUsersInOwnersAliases(ghc, log, triggerConfig, org, repo, r.Directory(), modifiedOwnerAliasesFile.Patch, ownerAliasesModified, skipTrustedUserCheck, filenames)
275275
if err != nil {
276-
return err
276+
// if OWNERS_ALIASES file exists and is not parseable
277+
// attach invalid owners label and add message to PR
278+
if !hasInvalidOwnersLabel {
279+
if err := ghc.AddLabel(org, repo, number, labels.InvalidOwners); err != nil {
280+
return err
281+
}
282+
}
283+
if err := ghc.CreateComment(org, repo, number, "The content of OWNERS_ALIASES is invalid."); err != nil {
284+
return err
285+
}
286+
return nil
277287
}
278288

279289
// Check if OWNERS_ALIASES has empty aliases, then add a warning comment

pkg/plugins/verify-owners/verify-owners_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ var ownerAliasesFiles = map[string][]byte{
145145
"toBeAddedAlias": []byte(`aliases:
146146
not-yet-existing-alias:
147147
- bob
148+
`),
149+
"invalidOwnersAliases": []byte(`aliases:
150+
approvers:
151+
- alice
152+
- bob
153+
-
148154
`),
149155
}
150156

@@ -451,6 +457,12 @@ func testHandle(clients localgit.Clients, t *testing.T) {
451457
addedContent: "toBeAddedAlias",
452458
shouldLabel: false,
453459
},
460+
{
461+
name: "invalid OWNERS_ALIASES",
462+
filesChanged: []string{"OWNERS_ALIASES"},
463+
ownersFile: "invalidOwnersAliases",
464+
shouldLabel: true,
465+
},
454466
}
455467
lg, c, err := clients()
456468
if err != nil {

0 commit comments

Comments
 (0)