Skip to content

Commit

Permalink
chore: merge pull request #23 from websublime/fix/change-exist
Browse files Browse the repository at this point in the history
fix: change exist, should also check package is defined not only bran…
  • Loading branch information
miguelramos authored Jul 24, 2024
2 parents b18714e + ce42c77 commit b8e023f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "workspace-node-tools"
version = "1.0.11"
version = "1.0.12"
edition = "2021"
description = "Node workspace version tools"
repository = "https://github.com/websublime/workspace-node-tools"
Expand Down
18 changes: 15 additions & 3 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub fn get_change(branch: String, cwd: Option<String>) -> Vec<Change> {
}

/// Check if a change exists in the changes file in the root of the project.
pub fn change_exist(branch: String, cwd: Option<String>) -> bool {
pub fn change_exist(branch: String, packages_name: Vec<String>, cwd: Option<String>) -> bool {
let ref root = match cwd {
Some(ref dir) => get_project_root_path(Some(PathBuf::from(dir))).unwrap(),
None => get_project_root_path(None).unwrap(),
Expand All @@ -319,7 +319,15 @@ pub fn change_exist(branch: String, cwd: Option<String>) -> bool {

let changes: ChangesFileData = serde_json::from_reader(changes_reader).unwrap();

return changes.changes.contains_key(&branch);
if changes.changes.contains_key(&branch) {
let branch_changes = changes.changes.get(&branch).unwrap();

return branch_changes.iter().any(|change| {
packages_name
.iter()
.any(|package_name| change.package == *package_name)
});
}
}

false
Expand Down Expand Up @@ -484,7 +492,11 @@ mod tests {
let ref changes_path = monorepo_dir.join(String::from(".changes.json"));
add_change(&change, Some(root.to_string()));

let result = change_exist(String::from("main"), Some(root.to_string()));
let result = change_exist(
String::from("main"),
vec!["test-package".to_string()],
Some(root.to_string()),
);

assert_eq!(result, true);
assert_eq!(changes_path.is_file(), true);
Expand Down

0 comments on commit b8e023f

Please sign in to comment.