Skip to content

Commit

Permalink
Merge pull request #54 from sr-lab/github_actions
Browse files Browse the repository at this point in the history
GitHub Actions support and textual representation
  • Loading branch information
Nfsaavedra committed Apr 22, 2024
2 parents ae5aebc + 42ebce3 commit e789d58
Show file tree
Hide file tree
Showing 33 changed files with 3,133 additions and 713 deletions.
30 changes: 29 additions & 1 deletion glitch/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import click, os, sys

from pathlib import Path
Expand All @@ -14,13 +15,14 @@
from glitch.parsers.chef import ChefParser
from glitch.parsers.puppet import PuppetParser
from glitch.parsers.terraform import TerraformParser
from glitch.parsers.gha import GithubActionsParser
from pkg_resources import resource_filename
from alive_progress import alive_bar # type: ignore


# NOTE: These are necessary in order for python to load the visitors.
# Otherwise, python will not consider these types of rules.
from glitch.analysis.design import DesignVisitor # type: ignore
from glitch.analysis.design.visitor import DesignVisitor # type: ignore
from glitch.analysis.security import SecurityVisitor # type: ignore


Expand All @@ -40,6 +42,17 @@ def parse_and_check(
stats.compute(inter)


def repr_mode(
type: UnitBlockType,
path: str,
module: bool,
parser: Parser,
) -> None:
inter = parser.parse(path, type, module)
if inter != None:
print(json.dumps(inter.as_dict(), indent=2))


@click.command(
help="PATH is the file or folder to analyze. OUTPUT is an optional file to which we can redirect the smells output."
)
Expand Down Expand Up @@ -106,6 +119,14 @@ def parse_and_check(
multiple=True,
help="The type of smell_types being analyzed.",
)
# TODO: Add linter option to here
@click.option(
"--mode",
type=click.Choice(["smell_detector", "repr"]),
help="The mode the tool is running in. If the mode is 'repr', the tool will only print the intermediate representation."
"The default mode is 'smell_detector'.",
default="smell_detector",
)
@click.argument("path", type=click.Path(exists=True), required=True)
@click.argument("output", type=click.Path(), required=False)
def glitch(
Expand All @@ -121,6 +142,7 @@ def glitch(
output: Optional[str],
tableformat: str,
linter: bool,
mode: str,
):
tech = Tech(tech)
type = UnitBlockType(type)
Expand Down Expand Up @@ -148,8 +170,14 @@ def glitch(
elif tech == Tech.terraform:
parser = TerraformParser()
config = resource_filename("glitch", "configs/terraform.ini")
elif tech == Tech.gha:
parser = GithubActionsParser()
file_stats = FileStats()

if mode == "repr":
repr_mode(type, path, module, parser)
return

if smell_types == ():
smell_types = get_smell_types()

Expand Down
Loading

0 comments on commit e789d58

Please sign in to comment.