Skip to content

Commit a27fc1c

Browse files
committed
feat: Update workflow + action
1 parent 5cf1105 commit a27fc1c

File tree

2 files changed

+51
-28
lines changed

2 files changed

+51
-28
lines changed

src/action.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use anyhow::Result;
12
use ghactions::prelude::*;
3+
use ghastoolkit::Repository;
24

35
#[derive(Actions, Debug, Clone)]
46
#[action(
@@ -20,7 +22,24 @@ pub struct Action {
2022
#[input(description = "GitHub Token")]
2123
token: String,
2224

23-
/// GitHub Repository
24-
#[input(description = "GitHub Repository")]
25-
repository: String,
25+
/// GitHub Repository where the extractor is located
26+
#[input(description = "GitHub Repository where the extractor is located")]
27+
extractor_repository: String,
28+
}
29+
30+
impl Action {
31+
/// Gets the repository to use for the extractor. If the repository is not provided,
32+
/// it will use the repository that the action is running in.
33+
pub fn extractor_repository(&self) -> Result<Repository> {
34+
let repo = if self.extractor_repository.is_empty() {
35+
log::debug!("No extractor repository provided, using the current repository");
36+
self.get_repository()?
37+
} else {
38+
log::debug!("Using the provided extractor repository");
39+
self.extractor_repository.clone()
40+
};
41+
log::info!("Extractor Repository :: {}", repo);
42+
43+
Ok(Repository::parse(&repo)?)
44+
}
2645
}

src/main.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
use anyhow::Result;
2-
use ghactions::{group, groupend, ActionTrait};
3-
use log::info;
4-
use octocrab::{models::issues::Issue, params::State};
5-
use std::error::Error;
1+
use std::path::PathBuf;
2+
3+
use anyhow::{Context, Result};
4+
use ghactions::{group, groupend, ActionTrait, ToolCache};
5+
use log::{debug, info};
66

77
mod action;
8+
mod extractors;
89

910
use action::Action;
1011

1112
#[tokio::main]
12-
async fn main() -> Result<(), Box<dyn Error>> {
13+
async fn main() -> Result<()> {
1314
let action = Action::init()?;
15+
debug!("Action :: {:?}", action);
1416

15-
info!("Action :: {:?}", action);
16-
17-
group!("Main Workflow");
17+
group!("Initialise Workflow");
1818

19-
info!("Repository: `{}`", action.get_repository()?);
19+
let client = octocrab::instance();
2020

21-
let client = action.octocrab()?;
21+
let toolcache = ToolCache::new();
22+
debug!("ToolCache :: {:?}", toolcache);
2223

23-
// https://docs.rs/octocrab/latest/octocrab/index.html
24-
// Example to get all the active issues
25-
let issues_pages = client
26-
.issues(
27-
action.get_repository_owner()?,
28-
action.get_repository_name()?,
29-
)
30-
.list()
31-
.state(State::Open)
32-
.per_page(50)
33-
.send()
34-
.await?;
24+
// Extractor
25+
let extractor_repo = action.extractor_repository()?;
26+
info!("Extractor Repository :: {}", extractor_repo);
3527

36-
for issue in client.all_pages::<Issue>(issues_pages).await? {
37-
info!(" >> {} -> {}", issue.id, issue.title);
28+
let extractor_path = PathBuf::from("./extractors");
29+
if !extractor_path.exists() {
30+
std::fs::create_dir(&extractor_path)
31+
.with_context(|| format!("Failed to create directory {:?}", extractor_path))?;
32+
info!("Created Extractor Directory :: {:?}", extractor_path);
3833
}
3934

35+
let extractor = extractors::fetch_extractor(&client, &extractor_repo, &extractor_path).await?;
36+
log::info!("Extractor :: {:?}", extractor);
37+
38+
groupend!();
39+
40+
group!("Download and install extractor");
41+
42+
// TODO: Validate the extractor
43+
4044
groupend!();
4145

4246
Ok(())

0 commit comments

Comments
 (0)