Skip to content

Commit b21ad69

Browse files
decyjphravelizmu
andauthored
Testing and merging pr 622 (#714)
* Add glob matching to include/exclude in diffable * Update the README --------- Co-authored-by: Adrian Veliz <avelizmurrieta@rccl.com>
1 parent e7043c2 commit b21ad69

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,21 @@ The following can be configured:
290290
- `Rulesets`
291291
- `Environments` - wait timer, required reviewers, prevent self review, protected branches deployment branch policy, custom deployment branch policy, variables, deployment protection rules
292292

293-
It is possible to provide an `include` or `exclude` settings to restrict the `collaborators`, `teams`, `labels` to a list of repos or exclude a set of repos for a collaborator.
293+
> [!important]
294+
> It is possible to provide an `include` or `exclude` settings to restrict the `collaborators`, `teams`, `labels` to a list of repos or exclude a set of repos for a collaborator.
295+
> The include/exclude pattern can also be for glob. For e.g.:
296+
```
297+
teams:
298+
- name: Myteam-admins
299+
permission: admin
300+
- name: Myteam-developers
301+
permission: push
302+
- name: Other-team
303+
permission: push
304+
include:
305+
- '*-config'
306+
```
307+
> Will only add `Other-team` to only `*-config` repos
294308
295309
See [`docs/sample-settings/settings.yml`](docs/sample-settings/settings.yml) for a sample settings file.
296310

lib/plugins/diffable.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
const ErrorStash = require('./errorStash')
2323
const MergeDeep = require('../mergeDeep')
2424
const NopCommand = require('../nopcommand')
25+
const Glob = require('../glob')
2526
const ignorableFields = ['id', 'node_id', 'default', 'url']
2627
module.exports = class Diffable extends ErrorStash {
2728
constructor (nop, github, repo, entries, log, errors) {
@@ -39,7 +40,10 @@ module.exports = class Diffable extends ErrorStash {
3940
// this.log.debug(` entries ${JSON.stringify(filteredEntries)}`)
4041
filteredEntries = filteredEntries.filter(attrs => {
4142
if (Array.isArray(attrs.exclude)) {
42-
if (!attrs.exclude.includes(this.repo.repo)) {
43+
const excludeGlobs = attrs.exclude.map(exc => new Glob(exc));
44+
const excludeGlobsMatch = excludeGlobs.some(glob => !!this.repo.repo.match(glob));
45+
46+
if (!attrs.exclude.includes(this.repo.repo) && !excludeGlobsMatch) {
4347
// this.log.debug(`returning not excluded entry = ${JSON.stringify(attrs)} for repo ${this.repo.repo}`)
4448
return true
4549
} else {
@@ -53,7 +57,10 @@ module.exports = class Diffable extends ErrorStash {
5357
})
5458
filteredEntries = filteredEntries.filter(attrs => {
5559
if (Array.isArray(attrs.include)) {
56-
if (attrs.include.includes(this.repo.repo)) {
60+
const includeGlobs = attrs.include.map(inc => new Glob(inc));
61+
const includeGlobsMatch = includeGlobs.some(glob => !!this.repo.repo.match(glob));
62+
63+
if (attrs.include.includes(this.repo.repo) || includeGlobsMatch) {
5764
// this.log.debug(`returning included entry = ${JSON.stringify(attrs)} for repo ${this.repo.repo}`)
5865
return true
5966
} else {

0 commit comments

Comments
 (0)