Skip to content

Commit

Permalink
feat(query): add filter to affectedPackages (#9201)
Browse files Browse the repository at this point in the history
### Description

Add the ability to filter in `affectedPackages`

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
NicholasLYang authored Sep 30, 2024
1 parent 2d2b573 commit 672218b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/turborepo-lib/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl RepositoryQuery {
&self,
base: Option<String>,
head: Option<String>,
filter: Option<PackagePredicate>,
) -> Result<Array<Package>, Error> {
let mut opts = self.run.opts().clone();
opts.scope_opts.affected_range = Some((base, head));
Expand All @@ -304,6 +305,7 @@ impl RepositoryQuery {
run: self.run.clone(),
name: package,
})
.filter(|package| filter.as_ref().map_or(true, |f| f.check(package)))
.sorted_by(|a, b| a.name.cmp(&b.name))
.collect())
}
Expand Down
20 changes: 19 additions & 1 deletion turborepo-tests/integration/tests/affected.t
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,22 @@ Do the same thing with the `query` command
]
}
}
}
}
Use a filter with `affectedPackages`
$ ${TURBO} query "query { affectedPackages(filter: { equal: { field: NAME, value: \"my-app\" } }) { items { name } } }"
WARNING query command is experimental and may change in the future
WARNING unable to detect git range, assuming all files have changed: git error: fatal: no merge base found
{
"data": {
"affectedPackages": {
"items": [
{
"name": "my-app"
}
]
}
}
}

0 comments on commit 672218b

Please sign in to comment.