gh_workflow_parser/
commands.rs

1//! The `commands` module contains the subcommands for the `gh-workflow-parser` CLI.
2
3/// The maximum Levenshtein distance for issues to be considered similar.
4///
5/// Determined in tests at the bottom of this file.
6pub const LEVENSHTEIN_THRESHOLD: usize = 100;
7
8use std::path::PathBuf;
9
10use clap::*;
11use clap::{Subcommand, ValueEnum};
12use strum::{Display, EnumString};
13
14pub mod create_issue_from_run;
15pub mod locate_failure_log;
16
17#[derive(Debug, Subcommand)]
18pub enum Command {
19    /// Create a GitHub issue from a failed workflow run
20    CreateIssueFromRun {
21        /// The GitHub repository to parse
22        #[arg(long, value_hint = ValueHint::Url)]
23        repo: String,
24        /// The GitHub workflow run ID
25        #[arg(short = 'r', long)]
26        run_id: String,
27        /// The GitHub issue label
28        #[arg(short, long)]
29        label: String,
30        /// The kind of workflow (e.g. Yocto)
31        #[arg(short, long)]
32        kind: WorkflowKind,
33        /// Don't create the issue if a similar issue already exists
34        #[arg(short, long, default_value_t = true)]
35        no_duplicate: bool,
36    },
37
38    /// Locate the specific failure log in a failed build/test/other
39    LocateFailureLog {
40        /// The kind of workflow (e.g. Yocto)
41        #[arg(short, long)]
42        kind: BuildKind,
43        /// Log file to search for the failure log (e.g. log.txt or read from stdin)
44        /// File to operate on (if not provided, reads from stdin)
45        #[arg(short = 'f', long, value_hint = ValueHint::FilePath)]
46        input_file: Option<PathBuf>,
47    },
48}
49
50/// The kind of workflow (e.g. Yocto)
51#[derive(ValueEnum, Display, Copy, Clone, Debug, PartialEq, Eq)]
52pub enum WorkflowKind {
53    Yocto,
54    Other,
55}
56
57/// The kind of build (e.g. Yocto)
58///
59/// Could be extended to Python, Pytest, Vivado Synethesis, etc.
60#[derive(ValueEnum, Display, EnumString, Copy, Clone, Debug, PartialEq, Eq)]
61pub enum BuildKind {
62    Yocto,
63    Other,
64}