Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Rework project name/alias querying. #986

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions nextgen/project-expander/src/tasks_expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,9 @@ impl<'graph, 'query> TasksExpander<'graph, 'query> {
dep_ids.sort();

let input = if dep_ids.len() == 1 {
format!("project={id} || projectAlias={id}", id = dep_ids[0])
format!("project={id}", id = dep_ids[0])
} else {
format!(
"project=[{ids}] || projectAlias=[{ids}]",
ids = dep_ids.join(",")
)
format!("project=[{ids}]", ids = dep_ids.join(","))
};

for dep_project in (self.context.query)(input)? {
Expand All @@ -158,10 +155,8 @@ impl<'graph, 'query> TasksExpander<'graph, 'query> {
check_and_push_dep(project, &dep_target.task_id, false)?;
}
} else {
let results = (self.context.query)(format!(
"project={id} || projectAlias={id}",
id = project_id
))?;
let results =
(self.context.query)(format!("project={id}", id = project_id))?;

if results.is_empty() {
return Err(TasksExpanderError::UnknownTarget {
Expand Down
11 changes: 10 additions & 1 deletion nextgen/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,23 @@ impl Queryable for Project {
Condition::Field { field, .. } => {
let result = match field {
Field::Language(langs) => condition.matches_enum(langs, &self.language),
Field::Project(ids) => condition.matches(ids, &self.id),
Field::Project(ids) => {
if condition.matches(ids, &self.id)? {
Ok(true)
} else if let Some(alias) = &self.alias {
condition.matches(ids, alias)
} else {
Ok(false)
}
}
Field::ProjectAlias(aliases) => {
if let Some(alias) = &self.alias {
condition.matches(aliases, alias)
} else {
Ok(false)
}
}
Field::ProjectName(ids) => condition.matches(ids, &self.id),
Field::ProjectSource(sources) => {
condition.matches(sources, &self.source.to_string())
}
Expand Down
1 change: 1 addition & 0 deletions nextgen/query/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum Field {
Language(Vec<LanguageType>),
Project(Vec<String>),
ProjectAlias(Vec<String>),
ProjectName(Vec<String>),
ProjectSource(Vec<String>),
ProjectType(Vec<ProjectType>),
Tag(Vec<String>),
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
- **Codegen**
- Templates can be used as-is without rendering with [Tera](https://tera.netlify.app) by appending
a `.raw` extension.
- **Query language**
- Updated `project` to query both project name AND alias.
- Added `projectName` for only querying by name

#### 🐞 Fixes

Expand Down
10 changes: 9 additions & 1 deletion website/docs/concepts/query-lang.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ language=rust

### `project`

ID/name of the project, as defined in [`.moon/workspace.yml`](../config/workspace).
Name OR alias of the project.

```
project=server
Expand All @@ -102,6 +102,14 @@ Alias of the project. For example, the `package.json` name.
projectAlias~@scope/*
```

### `projectName`

Name of the project, as defined in [`.moon/workspace.yml`](../config/workspace).

```
project=server
```

### `projectSource`

Relative file path from the workspace root to the project root, as defined in
Expand Down
Loading