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

feat: git multiple commands #3

Merged
merged 3 commits into from
Jul 6, 2024
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Miguel Ramos <miguel.ramos@websublime.dev>"]
edition = "2021"
name = "websublime_workspace-tools"
version = "0.1.0"
version = "0.2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -12,7 +12,7 @@ crate-type = ["cdylib"]
[dependencies]
napi-derive = "2.16.8"
napi = { version = "2.16.7", default-features = false, features = ["napi9", "serde-json", "tokio_rt"] }
workspace-node-tools = "0.5.0"
workspace-node-tools = "0.6.0"

[build-dependencies]
napi-build = "2"
Expand Down
101 changes: 100 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::all)]

use workspace_node_tools::git::commands::Git;
use workspace_node_tools::git::commands::{Commit, Git, PublishTagInfo, RemoteTags};
use workspace_node_tools::git::conventional::{ConventionalPackage, ConventionalPackageOptions};
use workspace_node_tools::monorepo::packages::{Monorepo, PackageInfo};

#[macro_use]
Expand Down Expand Up @@ -30,3 +31,101 @@ pub fn git_fetch_all(cwd: Option<String>) -> bool {
pub fn git_fetch_all_tags(cwd: Option<String>) -> bool {
Git::fetch_all_tags(cwd).is_ok()
}

#[napi(js_name = "setCommit")]
pub fn commit(
message: String,
body: Option<String>,
footer: Option<String>,
cwd: Option<String>,
) -> bool {
Git::git_commit(message, body, footer, cwd).is_ok()
}

#[napi(js_name = "setTag")]
pub fn tag(tag: String, message: Option<String>, cwd: Option<String>) -> bool {
Git::git_tag(tag, message, cwd).is_ok()
}

#[napi(js_name = "gitPush")]
pub fn push(cwd: Option<String>) -> bool {
Git::git_push(cwd).is_ok()
}

#[napi(js_name = "getCurrentSha")]
pub fn current_sha(cwd: Option<String>) -> String {
Git::git_current_sha(cwd)
}

#[napi(js_name = "isWorkdirUnclean")]
pub fn workdir_unclean(cwd: Option<String>) -> bool {
Git::git_workdir_unclean(cwd)
}

#[napi(js_name = "getDivergedCommit")]
pub fn diverged_commit(refer: String, cwd: Option<String>) -> Option<String> {
Git::get_diverged_commit(refer, cwd)
}

#[napi(js_name = "getCommitsSince")]
pub fn commits_since(
cwd: Option<String>,
since: Option<String>,
relative: Option<String>,
) -> Vec<Commit> {
Git::get_commits_since(cwd, since, relative)
}

#[napi(js_name = "getAllFilesChangedSinceSha")]
pub fn all_files_changed_since_sha(sha: String, cwd: Option<String>) -> Vec<String> {
Git::git_all_files_changed_since_sha(sha, cwd)
}

#[napi(js_name = "getAllFilesChangedSinceTagInfos")]
pub fn all_files_changed_since_tag_infos(
package_info: Vec<PackageInfo>,
tag_info: Vec<PublishTagInfo>,
cwd: Option<String>,
) -> Vec<String> {
Git::get_all_files_changed_since_tag_infos(package_info, tag_info, cwd)
}

#[napi(js_name = "getAllFilesChangedSinceBranch")]
pub fn all_files_changed_since_branch(
package_info: Vec<PackageInfo>,
branch: String,
cwd: Option<String>,
) -> Vec<String> {
Git::get_all_files_changed_since_branch(package_info, branch, cwd)
}

#[napi(js_name = "getRemoteOrLocalTags")]
pub fn remote_tags(cwd: Option<String>, local: Option<bool>) -> Vec<RemoteTags> {
Git::get_remote_or_local_tags(cwd, local)
}

#[napi(js_name = "getLastKnownPublishTagInfoForPackage")]
pub fn last_known_publish_tag_info_for_package(
package_info: PackageInfo,
cwd: Option<String>,
) -> Option<PublishTagInfo> {
Git::get_last_known_publish_tag_info_for_package(package_info, cwd)
}

#[napi(js_name = "getLastKnownPublishTagInfoForAllPackages")]
pub fn last_known_publish_tag_info_for_all_packages(
package_info: Vec<PackageInfo>,
cwd: Option<String>,
) -> Vec<Option<PublishTagInfo>> {
Git::get_last_known_publish_tag_info_for_all_packages(package_info, cwd)
}

#[napi(js_name = "getConventionalForPackage")]
pub fn conventional_for_package(
package_info: PackageInfo,
no_fetch_all: Option<bool>,
cwd: Option<String>,
conventional_options: Option<ConventionalPackageOptions>,
) -> ConventionalPackage {
Git::get_conventional_for_package(package_info, no_fetch_all, cwd, conventional_options)
}