Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -120,7 +120,8 @@ impl Command {
|
||||
current_dir: Option<&Path>,
|
||||
) -> anyhow::Result<(PleaseConfig, VcsClient, DynRemoteGitClient)> {
|
||||
let config = self.build_config(current_dir)?;
|
||||
let git_client = self.get_git(&config)?;
|
||||
let git_client =
|
||||
self.get_git(&config, self.global.token.clone().expect("token to be set"))?;
|
||||
let gitea_client = self.get_gitea_client(&config);
|
||||
|
||||
let filter = match self.global.log_level {
|
||||
@@ -160,7 +161,7 @@ impl Command {
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn get_git(&self, config: &PleaseConfig) -> anyhow::Result<VcsClient> {
|
||||
fn get_git(&self, config: &PleaseConfig, token: String) -> anyhow::Result<VcsClient> {
|
||||
if self.global.no_vcs {
|
||||
Ok(VcsClient::new_noop())
|
||||
} else {
|
||||
@@ -168,6 +169,7 @@ impl Command {
|
||||
config.get_source(),
|
||||
config.settings.git_username.clone(),
|
||||
config.settings.git_email.clone(),
|
||||
token,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ pub enum VcsClient {
|
||||
source: PathBuf,
|
||||
username: String,
|
||||
email: String,
|
||||
token: String,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -19,6 +20,7 @@ impl VcsClient {
|
||||
path: &Path,
|
||||
git_username: Option<impl Into<String>>,
|
||||
git_email: Option<impl Into<String>>,
|
||||
git_token: String,
|
||||
) -> anyhow::Result<VcsClient> {
|
||||
if !path.to_path_buf().join(".git").exists() {
|
||||
anyhow::bail!("git directory not found in: {}", path.display().to_string())
|
||||
@@ -32,6 +34,7 @@ impl VcsClient {
|
||||
email: git_email
|
||||
.map(|e| e.into())
|
||||
.unwrap_or("bot@cuddle.sh".to_string()),
|
||||
token: git_token,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -56,10 +59,15 @@ impl VcsClient {
|
||||
source,
|
||||
username,
|
||||
email,
|
||||
token,
|
||||
} => {
|
||||
let checkout_branch = std::process::Command::new("git")
|
||||
.current_dir(source.as_path())
|
||||
.args([
|
||||
"-c",
|
||||
&format!("http.extraHeader='Authorization: token {}'", token),
|
||||
"-c",
|
||||
&format!("http.extraHeader='Sudo: kjuulh'"),
|
||||
"-c",
|
||||
&format!("user.name={}", username),
|
||||
"-c",
|
||||
|
@@ -13,6 +13,7 @@ fn get_base_args<'a>() -> Vec<&'a str> {
|
||||
"list",
|
||||
"--no-vcs",
|
||||
"--engine=local",
|
||||
"--token=something",
|
||||
]
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,8 @@ fn exec_git_into_branch() {
|
||||
add_commit(tempdir.path(), "second").unwrap();
|
||||
add_tag(tempdir.path(), "1.0.1").unwrap();
|
||||
|
||||
let vcs = VcsClient::new_git(tempdir.path(), None::<String>, None::<String>).unwrap();
|
||||
let vcs =
|
||||
VcsClient::new_git(tempdir.path(), None::<String>, None::<String>, "".into()).unwrap();
|
||||
vcs.checkout_branch().unwrap();
|
||||
|
||||
let output = std::process::Command::new("git")
|
||||
@@ -48,7 +49,8 @@ fn add_files_to_commit() {
|
||||
add_commit(tempdir.path(), "first").unwrap();
|
||||
add_tag(tempdir.path(), "1.0.0").unwrap();
|
||||
|
||||
let vcs = VcsClient::new_git(tempdir.path(), None::<String>, None::<String>).unwrap();
|
||||
let vcs =
|
||||
VcsClient::new_git(tempdir.path(), None::<String>, None::<String>, "".into()).unwrap();
|
||||
vcs.checkout_branch().unwrap();
|
||||
|
||||
std::fs::File::create(tempdir.path().join("changelog")).unwrap();
|
||||
@@ -76,7 +78,8 @@ fn reset_branch() {
|
||||
add_commit(tempdir.path(), "first").unwrap();
|
||||
add_tag(tempdir.path(), "1.0.0").unwrap();
|
||||
|
||||
let vcs = VcsClient::new_git(tempdir.path(), None::<String>, None::<String>).unwrap();
|
||||
let vcs =
|
||||
VcsClient::new_git(tempdir.path(), None::<String>, None::<String>, "".into()).unwrap();
|
||||
vcs.checkout_branch().unwrap();
|
||||
|
||||
std::fs::File::create(tempdir.path().join("changelog-first")).unwrap();
|
||||
|
@@ -16,13 +16,14 @@ fn test_vcs_get_noop() {
|
||||
#[traced_test]
|
||||
fn test_vcs_get_git_found() {
|
||||
let testdata = get_test_data_path("git-found");
|
||||
let git = VcsClient::new_git(&testdata, None::<String>, None::<String>).unwrap();
|
||||
let git = VcsClient::new_git(&testdata, None::<String>, None::<String>, "".into()).unwrap();
|
||||
assert_eq!(
|
||||
git,
|
||||
VcsClient::Git {
|
||||
source: testdata,
|
||||
username: "cuddle-please".into(),
|
||||
email: "bot@cuddle.sh".into()
|
||||
email: "bot@cuddle.sh".into(),
|
||||
token: "".into(),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user