Compare commits

..

1 Commits

Author SHA1 Message Date
888fd3a8bd add flakes and direnv files
All checks were successful
Rust / build (push) Successful in 8m21s
2024-08-25 10:04:32 -05:00
7 changed files with 158 additions and 77 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

61
flake.lock Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-schemas": {
"locked": {
"lastModified": 1721999734,
"narHash": "sha256-G5CxYeJVm4lcEtaO87LKzOsVnWeTcHGKbKxNamNWgOw=",
"rev": "0a5c42297d870156d9c57d8f99e476b738dcd982",
"revCount": 75,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.5/0190ef2f-61e0-794b-ba14-e82f225e55e6/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1722372011,
"narHash": "sha256-B2xRiC3NEJy/82ugtareBkRqEkPGpMyjaLxaR8LBxNs=",
"rev": "cf05eeada35e122770c5c14add958790fcfcbef5",
"revCount": 633614,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2405.633614%2Brev-cf05eeada35e122770c5c14add958790fcfcbef5/01910e77-e048-77f4-b2d4-a69cacb697db/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/NixOS/nixpkgs/%2A.tar.gz"
}
},
"root": {
"inputs": {
"flake-schemas": "flake-schemas",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1722548948,
"narHash": "sha256-ddR/6wbOzRXijcOAEgeaIlbskky51eJdZhYPwoErs3s=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "0b973d3e54e497e518515c05a6e99ec6c03be2ce",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

61
flake.nix Normal file
View File

@ -0,0 +1,61 @@
# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.10)
{
# A helpful description of your flake
description = "A Gitea command line application";
# Flake inputs
inputs = {
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz";
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
# Flake outputs that other flakes can use
outputs = { self, flake-schemas, nixpkgs, rust-overlay }:
let
# Nixpkgs overlays
overlays = [
rust-overlay.overlays.default
(final: prev: {
rustToolchain = final.rust-bin.stable.latest.default.override { extensions = [ "rust-src"]; };
})
];
# Helpers for producing system-specific outputs
supportedSystems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs { inherit overlays system; };
});
in {
# Schemas tell Nix about the structure of your flake's outputs
schemas = flake-schemas.schemas;
# Development environments
devShells = forEachSupportedSystem ({ pkgs }: {
default = pkgs.mkShell {
# Pinned packages available in the environment
packages = with pkgs; [
rustToolchain
rust-analyzer
curl
git
jq
wget
nixpkgs-fmt
openssl
];
# Environment variables
env = {
RUST_BACKTRACE = "1";
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
};
};
});
};
}

7
rust-analyzer.json Normal file
View File

@ -0,0 +1,7 @@
{
"rust-analyzer": {
"files": {
"excludeDirs": [".direnv"]
}
}
}

View File

@ -7,7 +7,6 @@ pub fn get_args() -> ArgMatches<'static> {
.version("0.0.2")
.author("Wyatt J. Miller <wjmiller2016@gmail.com>")
.about("It's a Gitea CLI client!")
.arg(Arg::with_name("--json").help("Print out results in JSON"))
.subcommand(SubCommand::with_name("repo")
.about("Create, delete, list, search, or fork a repository")
.arg(Arg::with_name("create")

View File

@ -1,18 +1,11 @@
use std::{
collections::HashMap,
file,
path::{self, Path},
};
use std::{collections::HashMap, path::{Path, self}, file};
use colored::*;
use git2::{
build::RepoBuilder, Cred, CredentialType, Credentials, FetchOptions, RemoteCallbacks,
Repository as Repo,
};
use git2::{Repository as Repo, build::RepoBuilder, Credentials, Cred, CredentialType, RemoteCallbacks, FetchOptions};
use reqwest::StatusCode;
use serde_derive::{Deserialize, Serialize};
use crate::{config::Configuration, request::Request};
use crate::{request::Request, config::Configuration};
pub struct Repository;
@ -124,7 +117,6 @@ impl Repository {
request = request.url.as_ref().unwrap(),
api_token = request.authentication.credentials.1.as_ref().unwrap()
);
let is_json = request.is_json;
map.insert("name", arg_value);
map.insert("readme", arg_value);
@ -135,9 +127,6 @@ impl Repository {
match response {
Ok(repo) => match repo.status() {
StatusCode::CREATED => {
if is_json {
println!("{}", repo)
}
let deserialized: RepositoryResponse = repo.json().unwrap();
println!("{}", "Repository successfully created!".green());
println!("\tRepository name: {:0}\n\tRepository owner: {:1}\n\tRepository description: {:2}", deserialized.name, deserialized.owner.unwrap().full_name, deserialized.description);
@ -156,9 +145,6 @@ impl Repository {
}
pub fn delete_repo(&self, request: &Request) {
if (request.is_json) {
println!("uh oh json"); // TODO: fix me, replace line with util::bad_response_message
}
let client = &request.client;
let arg_value: Vec<&str> = request
.arg_value
@ -180,9 +166,7 @@ impl Repository {
match response {
Ok(repo) => match repo.status() {
StatusCode::NO_CONTENT => {
println!("{}", "Respository successfully deleted!".green())
}
StatusCode::NO_CONTENT => println!("{}", "Respository successfully deleted!".green()),
StatusCode::FORBIDDEN => println!("{}", "Repository deletion forbidden!".red()),
_ => println!(
"Repository deletion failed! Does the repository exist? HTTP status code: {}",
@ -222,25 +206,15 @@ impl Repository {
match response {
Ok(repo) => match repo.status() {
StatusCode::ACCEPTED => {
if (request.is_json) {
println!("{}", repo)
}
let deserialized: RepositoryResponse = repo.json().unwrap();
println!("{}", "Repository forked successfully".green());
println!("\tOriginal repository name: {:0?}\n\tOriginal repository owner: {:1?}\n\tForked repository name: {:2?}\n\tForked repository owner: {:3?}", deserialized.name, arg_item[0], deserialized.name, deserialized.owner.unwrap().full_name);
}
StatusCode::INTERNAL_SERVER_ERROR => {
println!("{}", "Repository already forked!".red())
}
StatusCode::INTERNAL_SERVER_ERROR => println!("{}", "Repository already forked!".red()),
StatusCode::FORBIDDEN => println!("{}", "Repository fork forbidden!".red()),
StatusCode::UNPROCESSABLE_ENTITY => {
println!("{}", "Repository fork input validation failed!".red())
}
StatusCode::UNPROCESSABLE_ENTITY => println!("{}", "Repository fork input validation failed!".red()),
StatusCode::NOT_FOUND => println!("{}", "Repository not found!"),
_ => println!(
"Repository creation failed! HTTP status code: {}",
repo.status().as_str()
),
_ => println!("Repository creation failed! HTTP status code: {}", repo.status().as_str()),
},
Err(e) => panic!("{}", e),
}
@ -267,9 +241,6 @@ impl Repository {
match response {
Ok(repo) => match repo.status() {
StatusCode::OK => {
if (request.is_json) {
println!("{}", repo)
}
let deserialized: MultipleRepositories = repo.json().unwrap();
match deserialized.data.len() != 0 {
@ -280,22 +251,14 @@ 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.iter().count())
}
false => println!("{}", "Repository searched doesn't exist!".red()),
}
}
StatusCode::NOT_FOUND => println!("{}", "Repository searched doesn't exist!".red()),
StatusCode::UNPROCESSABLE_ENTITY => {
println!("{}", "Repository input validation failed!".red())
}
_ => println!(
"Repository search failed! HTTP status code: {}",
repo.status().as_str()
),
StatusCode::UNPROCESSABLE_ENTITY => println!("{}", "Repository input validation failed!".red()),
_ => println!("Repository search failed! HTTP status code: {}", repo.status().as_str()),
},
Err(e) => panic!("{}", e),
}
@ -314,9 +277,6 @@ impl Repository {
match response {
Ok(repo) => match repo.status() {
StatusCode::OK => {
if (request.is_json) {
println!("{}", repo)
}
let deserialized: MultipleRepositories = repo.json().unwrap();
match deserialized.data.len() != 0 {
@ -332,13 +292,8 @@ impl Repository {
false => println!("{}", "The authenticated user doesn't have any repositories. Why not create one?".yellow())
}
}
StatusCode::UNPROCESSABLE_ENTITY => {
println!("{}", "Repository input validation failed!".red())
}
_ => println!(
"Repository search failed! HTTP status code: {}",
repo.status().as_str()
),
StatusCode::UNPROCESSABLE_ENTITY => println!("{}", "Repository input validation failed!".red()),
_ => println!("Repository search failed! HTTP status code: {}",repo.status().as_str()),
},
Err(e) => panic!("{}", e),
}
@ -347,6 +302,7 @@ impl Repository {
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, config: &Configuration) {
@ -374,15 +330,15 @@ impl Repository {
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 _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())),
// 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
// )
@ -393,25 +349,24 @@ impl Repository {
// )
// }
Cred::userpass_plaintext(
request
.authentication
.credentials
.0
.as_ref()
.unwrap()
.as_str(),
config.password.as_ref().unwrap().as_str(),
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"),
_ => panic!("agh")
};
}
pub fn add_to_staging(&self, request: &Request, config: Configuration) {}
pub fn add_to_staging(&self, request: &Request, config: Configuration) {
pub fn create_commit(&self, request: &Request, config: Configuration) {}
}
pub fn create_commit(&self, request: &Request, config: Configuration) {
}
}

View File

@ -17,7 +17,6 @@ pub struct Request<'a> {
pub map: HashMap<String, String>,
pub url: Option<String>,
pub authentication: Authentication,
pub is_json: bool,
}
pub struct Authentication {
@ -40,7 +39,6 @@ impl<'a> Request<'a> {
map: HashMap::new(),
url: Some(format!("{}{}", config.base_url, config.base_api)),
authentication: auth,
is_json: arg.is_present("--json"),
}
}
@ -56,7 +54,6 @@ impl<'a> Request<'a> {
map: HashMap::new(),
url: Some(format!("{}{}", config.base_url, config.base_api)),
authentication: auth,
is_json: arg.is_present("--json"),
}
}
}