feat: generate config, load shell env vars
This commit is contained in:
+53
-9
@@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, path::{Path, self}, file};
|
||||
|
||||
use colored::*;
|
||||
use git2::Repository as Repo;
|
||||
use git2::{Repository as Repo, build::RepoBuilder, Credentials, Cred, CredentialType, RemoteCallbacks, FetchOptions};
|
||||
use reqwest::StatusCode;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
@@ -287,7 +287,7 @@ impl Repository {
|
||||
println!("{}.\tRepository name: {:1}\n\tRepository owner: {:2}\n\tRepository description: {:3}\n", i + 1, data.name, data.owner.as_ref().unwrap().full_name, data.description)
|
||||
}
|
||||
|
||||
println!("Total number of repositories indexed: {}", deserialized.data.iter().count())
|
||||
println!("Total number of repositories indexed: {}", deserialized.data.len())
|
||||
},
|
||||
false => println!("{}", "The authenticated user doesn't have any repositories. Why not create one?".yellow())
|
||||
}
|
||||
@@ -299,12 +299,15 @@ impl Repository {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_to_remote(&self, request: &Request) {
|
||||
|
||||
pub fn push_to_remote(&self, request: &Request, config: &Configuration) {
|
||||
// code to push to the remote server goes here
|
||||
// this is based on the user, the remote, and the branch
|
||||
|
||||
}
|
||||
|
||||
pub fn pull_from_remote(&self, request: &Request) {
|
||||
|
||||
pub fn pull_from_remote(&self, request: &Request, config: &Configuration) {
|
||||
// code to pull from the remote server goes here
|
||||
// this is based on the user, the remote, and the branch
|
||||
}
|
||||
|
||||
pub fn clone_from_remote(&self, request: &Request, config: &Configuration) {
|
||||
@@ -322,7 +325,48 @@ impl Repository {
|
||||
owner = arg_value[0],
|
||||
repo = arg_value[1]
|
||||
);
|
||||
Repo::clone(url.as_str(), ".").unwrap();
|
||||
println!("Repository successfully cloned!");
|
||||
|
||||
let mut builder = RepoBuilder::new();
|
||||
let mut callbacks = RemoteCallbacks::new();
|
||||
callbacks.credentials(|_url, _user_from_url, _allowed_types| {
|
||||
let user = _user_from_url.unwrap_or("git");
|
||||
|
||||
if _allowed_types.contains(CredentialType::USERNAME) {
|
||||
return Cred::username(user)
|
||||
}
|
||||
|
||||
// if request.url_request() {
|
||||
// Cred::ssh_key(
|
||||
// user,
|
||||
// Some(Path::new(&format!("{}/.ssh/id_ed25519.pub", std::env::var("HOME").unwrap()).as_str())),
|
||||
// Path::new(&format!("{}/.ssh/id_ed25519", std::env::var("HOME").unwrap()).as_str()),
|
||||
// None
|
||||
// )
|
||||
// } else {
|
||||
// Cred::userpass_plaintext(
|
||||
// request.authentication.credentials.0.as_ref().unwrap().as_str(),
|
||||
// request.authentication.credentials.1.as_ref().unwrap().as_str()
|
||||
// )
|
||||
// }
|
||||
Cred::userpass_plaintext(
|
||||
request.authentication.credentials.0.as_ref().unwrap().as_str(),
|
||||
config.password.as_ref().unwrap().as_str()
|
||||
)
|
||||
});
|
||||
builder.branch("master");
|
||||
match builder.clone(url.as_str(), Path::new(arg_value[1])) {
|
||||
Ok(_r) => Ok(println!("Repository cloned successfully!")),
|
||||
Err(_e) => Err(println!("Repository clone failed!")),
|
||||
_ => panic!("agh")
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
pub fn add_to_staging(&self, request: &Request, config: Configuration) {
|
||||
|
||||
}
|
||||
|
||||
pub fn create_commit(&self, request: &Request, config: Configuration) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user