Move create-release code to it's own function
This commit is contained in:
25
src/lib.rs
25
src/lib.rs
@@ -38,25 +38,12 @@ pub struct Author {
|
|||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
pub struct CreateReleaseOption {
|
pub struct CreateReleaseOption {
|
||||||
body: String,
|
pub body: String,
|
||||||
draft: bool,
|
pub draft: bool,
|
||||||
name: String,
|
pub name: String,
|
||||||
prerelease: bool,
|
pub prerelease: bool,
|
||||||
tag_name: String,
|
pub tag_name: String,
|
||||||
target_commitish: String,
|
pub target_commitish: String,
|
||||||
}
|
|
||||||
|
|
||||||
impl CreateReleaseOption {
|
|
||||||
pub fn new(name: String) -> Self {
|
|
||||||
Self{
|
|
||||||
body: String::from("hard-coded test body"),
|
|
||||||
draft: false,
|
|
||||||
name,
|
|
||||||
prerelease: true,
|
|
||||||
tag_name: String::from("big-goof"),
|
|
||||||
target_commitish: String::from("548ceecc7528901a7b4376091b42e410d950affc")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
|||||||
48
src/main.rs
48
src/main.rs
@@ -3,6 +3,7 @@ use gt_tools::{ReleaseInfo, cli::Args};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
@@ -32,22 +33,41 @@ async fn main() -> Result<(), Error> {
|
|||||||
println!("{:?}", body_text);
|
println!("{:?}", body_text);
|
||||||
}
|
}
|
||||||
gt_tools::cli::Commands::CreateRelease { name } => {
|
gt_tools::cli::Commands::CreateRelease { name } => {
|
||||||
let token = env::var("RELEASE_KEY_GITEA")
|
let submission = CreateReleaseOption {
|
||||||
.expect("You must set the RELEASE_KEY_GITEA environment variable so the Gitea API can be used.");
|
body: String::from("hard-coded test body"),
|
||||||
let body = CreateReleaseOption::new(name);
|
draft: false,
|
||||||
let response = client
|
name,
|
||||||
.post(request_url)
|
prerelease: true,
|
||||||
.header(USER_AGENT, "gt-tools-test-agent")
|
tag_name: String::from("big-goof"),
|
||||||
.header(ACCEPT, "application/json")
|
target_commitish: String::from("548ceecc7528901a7b4376091b42e410d950affc"),
|
||||||
.header("Authorization", format!("token {}", token))
|
};
|
||||||
.json(&body)
|
do_create_release(&client, &request_url, submission).await?;
|
||||||
.send()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let result: gt_tools::CreateResult = response.json().await?;
|
|
||||||
println!("{:?}", result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
async fn do_create_release(
|
||||||
|
client: &reqwest::Client,
|
||||||
|
endpoint: &str,
|
||||||
|
submission: CreateReleaseOption,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let token = env::var("RELEASE_KEY_GITEA").expect(
|
||||||
|
"You must set the RELEASE_KEY_GITEA environment variable so the Gitea API can be used.",
|
||||||
|
);
|
||||||
|
let response = client
|
||||||
|
.post(endpoint)
|
||||||
|
.header(USER_AGENT, "gt-tools-test-agent")
|
||||||
|
.header(ACCEPT, "application/json")
|
||||||
|
.header("Authorization", format!("token {}", token))
|
||||||
|
.json(&submission)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
println!("HTTP Response: {}", response.status());
|
||||||
|
let result: gt_tools::CreateResult = response.json().await?;
|
||||||
|
println!("{:?}", result);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user