|
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}; |
6 | 6 |
|
7 | 7 | mod action; |
| 8 | +mod extractors; |
8 | 9 |
|
9 | 10 | use action::Action; |
10 | 11 |
|
11 | 12 | #[tokio::main] |
12 | | -async fn main() -> Result<(), Box<dyn Error>> { |
| 13 | +async fn main() -> Result<()> { |
13 | 14 | let action = Action::init()?; |
| 15 | + debug!("Action :: {:?}", action); |
14 | 16 |
|
15 | | - info!("Action :: {:?}", action); |
16 | | - |
17 | | - group!("Main Workflow"); |
| 17 | + group!("Initialise Workflow"); |
18 | 18 |
|
19 | | - info!("Repository: `{}`", action.get_repository()?); |
| 19 | + let client = octocrab::instance(); |
20 | 20 |
|
21 | | - let client = action.octocrab()?; |
| 21 | + let toolcache = ToolCache::new(); |
| 22 | + debug!("ToolCache :: {:?}", toolcache); |
22 | 23 |
|
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); |
35 | 27 |
|
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); |
38 | 33 | } |
39 | 34 |
|
| 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 | + |
40 | 44 | groupend!(); |
41 | 45 |
|
42 | 46 | Ok(()) |
|
0 commit comments