Skip to content

Commit

Permalink
Add jenkins integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
cocatrip committed Jan 12, 2022
1 parent ddd1a6f commit 1ad1624
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 62 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/rust.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pipeline {
agent {
table 'rust'
}

stages {
stage('Build') {
steps {
sh "cargo build"
}
}
}
}
8 changes: 5 additions & 3 deletions src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ impl<'a> Cli<'a> {
.takes_value(true)
.possible_value(PossibleValue::new("0").help("Public"))
.possible_value(PossibleValue::new("1").help("Unlisted"))
.possible_value(PossibleValue::new("2").help("Private (in combination with api_user_key)"))
.possible_value(
PossibleValue::new("2").help("Private (in combination with api_user_key)"),
)
.required(false)
.default_value("0"),
)
Expand All @@ -55,8 +57,8 @@ impl<'a> Cli<'a> {
.takes_value(true)
.required(false)
.default_value("10M"),
)
;Self { app }
);
Self { app }
}

pub fn parse(self) -> ArgMatches {
Expand Down
8 changes: 3 additions & 5 deletions src/lib/cred.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::Deserialize;
use std::fs;
use std::io::Read;
use std::io::Write;
use std::fs;
use std::path::Path;
use toml;
use serde::Deserialize;

#[derive(Debug, Default, Deserialize)]
pub struct Cred {
Expand Down Expand Up @@ -49,9 +49,7 @@ impl Cred {
if cred.devkey.is_empty() {
println!("No devkey found. Please enter one.");
}
if !cred.username.is_empty() && !cred.password.is_empty() {

}
if !cred.username.is_empty() && !cred.password.is_empty() {}

cred
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod cli;
pub mod proc;
pub mod flag;
pub mod cred;
pub mod flag;
pub mod proc;
28 changes: 14 additions & 14 deletions src/lib/proc.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use std::path::Path;
use std::io::prelude::*;
use std::io::{Read,Write,Error, ErrorKind};
use std::fs;
use std::io::prelude::*;
use std::io::{Error, ErrorKind, Read, Write};
use std::path::Path;

use dirs;
use futures::stream::TryStreamExt;
use reqwest::{Body, Client};
use tokio;
use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead};
use dirs;
use tokio;

use crate::lib::flag::Flags;
use crate::lib::cred::Cred;
use crate::lib::flag::Flags;

fn type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
Expand Down Expand Up @@ -44,14 +44,15 @@ pub fn detect_proglang(path: &Path) -> Result<String, Error> {

async fn login_to_pastebin(cred: &Cred) -> Result<String, Box<dyn std::error::Error>> {
let client = Client::new();
let mut userkey = String::new();
let mut userkey = String::new();
let data = [
("api_dev_key", cred.devkey.as_str()),
("api_user_name", cred.username.as_str()),
("api_user_password", cred.password.as_str()),
];

let res = client.post("https://pastebin.com/api/api_login.php")
let res = client
.post("https://pastebin.com/api/api_login.php")
.form(&data)
.send()
.await?;
Expand All @@ -70,7 +71,10 @@ async fn login_to_pastebin(cred: &Cred) -> Result<String, Box<dyn std::error::Er
}

#[tokio::main]
pub async fn upload_to_pastebin(input: &str, args: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
pub async fn upload_to_pastebin(
input: &str,
args: &clap::ArgMatches,
) -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let flag = Flags::set_flags(args);
let cred = Cred::load();
Expand All @@ -83,7 +87,6 @@ pub async fn upload_to_pastebin(input: &str, args: &clap::ArgMatches) -> Result<
("api_dev_key", cred.devkey.as_str()),
("api_option", "paste"),
("api_paste_code", input),

// optional
("api_user_key", &userkey),
("api_paste_name", args.value_of("title").unwrap()),
Expand All @@ -92,10 +95,7 @@ pub async fn upload_to_pastebin(input: &str, args: &clap::ArgMatches) -> Result<
("api_paste_expire_date", "10M"),
];

let res = client.post(url)
.form(&data)
.send()
.await?;
let res = client.post(url).form(&data).send().await?;

match res.status() {
reqwest::StatusCode::OK => {
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![allow(unused)]

use std::fs::{create_dir_all, File};
use std::io;
use std::io::prelude::*;
use std::fs::{File, create_dir_all};
use std::path::Path;

mod lib;
use lib::cli::*;
use lib::proc::*;


fn main() {
let app = Cli::new();
let args = app.parse();
Expand Down

0 comments on commit 1ad1624

Please sign in to comment.