From e9276b033db7de95d1a8bd9c7c9c53b2e4b47f43 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Mon, 27 May 2024 10:27:04 +0200 Subject: [PATCH] updated library to version 0.0.3 This contains the `get_input` method --- Cargo.toml | 2 +- src/main.rs | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 21b43bd..8cf0428 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] actions-core = "0.0.2" -actions-github = "0.0.2" +actions-github = "0.0.3" anyhow = "1.0.86" octocrab = "0.38.0" serde = "1.0.202" diff --git a/src/main.rs b/src/main.rs index b0693f7..6771ed2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use actions_core::set_output; use actions_github::context::get_context; +use actions_github::core::get_input; use anyhow::Result; use octocrab::Octocrab; @@ -7,19 +8,13 @@ use octocrab::Octocrab; async fn main() { let ctx = match get_context() { Ok(context) => context, - Err(error) => panic!("{}", error) + Err(error) => panic!("{}", error), }; let org: String = ctx.repo.owner; - let team_name: String = actions_core::input("team") - .expect("Missing team name") - .parse() - .expect("Failed to parse team name"); + let team_name:String = get_variable("team", true); - let token: String = actions_core::input("ACCESS_TOKEN") - .expect("Missing access token") - .parse() - .expect("Failed to parse access token"); + let token:String = get_variable("ACCESS_TOKEN", true); let crab = Octocrab::builder().personal_token(token).build(); octocrab::initialise(crab.unwrap()); @@ -52,6 +47,13 @@ struct UserData { pub avatar: String, } +fn get_variable(var_name: &str, required:bool) -> String { + match get_input(var_name) { + Ok(variable) => return variable, + Err(err) => panic!("{}", err) + } +} + async fn fetch_team(org: String, team: &String) -> Result> { let team_data = octocrab::instance() .teams(org)