Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/28 list #47

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2bcb1f2
testig basic structure
ArielSixwings Oct 19, 2023
8ba1f7f
testando
AnaCarolinaRodriguesLeite Oct 19, 2023
1c2ae77
Feat: Partial configuration tree listing
AnaCarolinaRodriguesLeite Oct 22, 2023
f7a7352
fix: list initial usage
ArielSixwings Oct 22, 2023
c7c1de9
fix: list initial usage
ArielSixwings Oct 22, 2023
514bf0d
feat: Improved config presentation
ArielSixwings Oct 22, 2023
7f01344
Fix: Add indent
AnaCarolinaRodriguesLeite Oct 22, 2023
12f59e3
fix: fix identation
ArielSixwings Oct 22, 2023
efb5df0
Fix: fixing indentation
AnaCarolinaRodriguesLeite Oct 22, 2023
64c3302
refactor: Removed unused
ArielSixwings Oct 22, 2023
5510ec6
refactor: modify print of configuration to be testable
ArielSixwings Oct 22, 2023
dfd0602
test: Add test_print_config
ArielSixwings Oct 22, 2023
f6e9e79
Fix: Lopping Caracteriscts
AnaCarolinaRodriguesLeite Oct 22, 2023
e502ee7
Fix: modified expected output
ArielSixwings Oct 22, 2023
e92913e
delete src/config/msgram.json
IanPSRocha Oct 23, 2023
eeabbd7
Merge pull request #1 from fga-eps-mds/feature/28-view_configuration
IanPSRocha Oct 23, 2023
e1b4e5f
Update README.md
AnaCarolinaRodriguesLeite Oct 23, 2023
4a6328b
Update sonar-project.properties
IanPSRocha Oct 23, 2023
8add29a
Update metrics.yml
IanPSRocha Oct 23, 2023
f3d31d5
Update test.yml
IanPSRocha Oct 23, 2023
f5980e5
Update metrics.yml
IanPSRocha Oct 23, 2023
f6a8bf2
Create build.yml
IanPSRocha Oct 23, 2023
bfafe86
Update build.yml
IanPSRocha Oct 24, 2023
543de25
Update python-publish.yml
IanPSRocha Oct 26, 2023
e7d8f4c
Update pyproject.toml
IanPSRocha Oct 26, 2023
daedc68
Update python-publish.yml
IanPSRocha Oct 26, 2023
8601f8a
Update pyproject.toml
IanPSRocha Oct 26, 2023
f6b558c
Update sonar-project.properties
IanPSRocha Oct 26, 2023
7a1c058
Update sonar-project.properties
IanPSRocha Oct 26, 2023
37c5d5f
fix: Changed pipe character for asc2 179 character.
ArielSixwings Nov 2, 2023
5165c81
fix: add metrics to list
ArielSixwings Nov 2, 2023
7288f7d
Fix: Ajustes de indentacao e detalhes
AnaCarolinaRodriguesLeite Nov 3, 2023
cd1160b
test: Updated test based on metrics fix.
ArielSixwings Nov 4, 2023
ff0f351
Test: updated test
ArielSixwings Nov 4, 2023
ce8933f
feat: Add config path option to msgram list.
ArielSixwings Nov 4, 2023
20ae9bc
feat: changed character at metrics.
ArielSixwings Nov 4, 2023
8c0681e
fix: version
ArielSixwings Nov 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build
on:
push:
branches:
- develop
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [main, develop]
tags:
- "v*"
workflow_dispatch:

jobs:
release:
Expand All @@ -24,7 +25,7 @@ jobs:
run: |
git config --global user.email "${{secrets.USER_EMAIL}}"
git config --global user.name "${{secrets.USER_NAME}}"
git clone --single-branch --branch main "https://x-access-token:${{secrets.API_TOKEN_DOC}}@github.com/fga-eps-mds/2023-1-MeasureSoftGram-Doc" doc
git clone --single-branch --branch main "https://x-access-token:${{secrets.API_TOKEN_DOC}}@github.com/fga-eps-mds/2023.2-MeasureSoftGram-DOC" doc
mkdir -p doc/analytics-raw-data
cp -R analytics-raw-data/*.json doc/analytics-raw-data
cd doc/
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ develop ]
tags:
- "v*"
workflow_dispatch:

jobs:
deploy:
Expand Down Expand Up @@ -32,5 +33,5 @@ jobs:
run: python -m twine upload -u __token__ -p ${{ secrets.TEST_PYPI_API_TOKEN }} --repository testpypi dist/*

- name: Publish package on pypi
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
#if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
run: python -m twine upload -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/*
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ jobs:
fail_ci_if_error: true
files: ./coverage.xml
flags: unittests
name: 2023-1-MeasureSoftGram-CLI
verbose: true
name: 2023-2-MeasureSoftGram-CLI
verbose: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 2023-1-MeasureSoftGram-CLI
# 2023-2 MeasureSoftGram-CLI

## Badges

Expand Down
32 changes: 32 additions & 0 deletions outhelp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
──────────────────────────────────────────────────── Listing Configuration Parameters: ────────────────────────────────────────────────────


Característica:
reliability
Peso: 50%
Subcaracteristica(s):

Característica:
| testing_status
| Peso: 100%
| Medida(s):
| | passed_tests
| | Peso: 33%
| | Métrica(s):
| | | Valores de referência: Min: 0 e Max: 1
| | Fim-Metrica(s)
| Fim-Medida(s)
| | test_builds
| | Peso: 33%
| | Métrica(s):
| | | Valores de referência: Min: 0 e Max: 300000
| | Fim-Metrica(s)
| Fim-Medida(s)
| | test_coverage
| | Peso: 34%
| | Métrica(s):
| | | Valores de referência: Min: 60 e Max: 100
| | Fim-Metrica(s)
| Fim-Medida(s)
Fim-SubCaracterística
Fim-Característica
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "msgram"
version = "3.0.0"
version = "3.0.3"
description = "The msgram CLI is a command-line interface to use MeasureSoftGram software"
readme = "README.md"
authors = [
Expand Down
3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sonar.projectKey=fga-eps-mds_2023-1-MeasureSoftGram-CLI
sonar.projectKey=fga-eps-mds_2023-2-MeasureSoftGram-CLI
sonar.organization=fga-eps-mds-1

sonar.python.version=3
Expand All @@ -9,6 +9,7 @@ sonar.sources.exclusions= \
**/parsers.py \
**/cli.py
sonar.tests=./tests
sonar.test.inclusions=**/tests/

sonar.dynamicAnalysis=reuseReports
sonar.core.codeCoveragePlugin=cobertura
Expand Down
101 changes: 101 additions & 0 deletions src/cli/commands/cmd_print_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from rich.console import Console
from src.cli.utils import print_info, print_rule, print_error

from src.config.settings import FILE_CONFIG, DEFAULT_CONFIG_PATH, DEFAULT_CONFIG_FILE_PATH

from pathlib import Path

import json
import os

def print_json_tree(data):
result = []
stack = [(data, "")]
is_top = True

measure_to_metric = {}
measure_to_metric["passed_tests"] = ['test_success_density']
measure_to_metric["test_builds"] = ['tests', 'tests_execution_time']
measure_to_metric["test_coverage"] = ['coverage']
measure_to_metric["non_complex_file_density"] = ['complexity_functions', 'total_number_of_files']
measure_to_metric["commented_file_density"] = ['commented_lines_density']
measure_to_metric["duplication_absense"] = ['duplication_lines_density']

while stack:
data, indent = stack.pop()
key = data.get("key")

if is_top:
result.append(f"[#FFFFFF]\nCaracterística:")
is_top = False
result.append(f"[#FFFFFF]{indent}[#00FF00]{key}")

weight = data.get("weight", 0)
result.append(f"[#FFFFFF]{indent}Peso: [#00FF00]{weight}%")

if "subcharacteristics" in data:
for subchar in data["subcharacteristics"]:
result.append(f"[#FFFFFF]{indent}Sub-característica(s):")
stack.append((subchar, f"{indent}│ ")) # Use the ASCII character │ (code 179)

if "measures" in data:
for measure in data["measures"]:
result.append(f"[#FFFFFF]{indent}│ Medida(s):")
measure_key = measure.get("key")
result.append(f"[#FFFFFF]{indent}{indent}│ [#00FF00]{measure_key}") # Use the ASCII character │ (code 179)
result.append(f"[#FFFFFF]{indent}{indent}│ Peso: [#00FF00]{measure['weight']}%")
if "min_threshold" in measure and "max_threshold" in measure:
min_threshold = measure.get("min_threshold")
max_threshold = measure.get("max_threshold")
result.append(f"[#FFFFFF]{indent}{indent}│ Métrica(s):") # Use the ASCII character │ (code 179)
metrics = measure_to_metric.get(measure_key, []) # Get associated metrics
for metric in metrics:
result.append(f"[#FFFFFF]{indent}{indent}│ └─[#00FF00]{metric}") # Print metrics in green color
result.append(f"[#FFFFFF]{indent}{indent}│ │ Valores de referência: Min = [#00FF00]{min_threshold} [#FFFFFF]e Max = [#00FF00]{max_threshold}")
result.append(f"[#FFFFFF]{indent}{indent}│ Fim-Métrica(s)")
result.append(f"[#FFFFFF]{indent}│ Fim-Medida(s)")
result.append("[#FFFFFF]Fim-SubCaracterística")
result.append("[#FFFFFF]Fim-Característica")

return '\n'.join(result)

def command_list_config(args):
console = Console()
console.clear()

file_path = DEFAULT_CONFIG_FILE_PATH
try:
config_path: Path = args["config_path"]

if config_path != DEFAULT_CONFIG_PATH:
print_info(f"[#A9A9A9] Será usado arquivo informado pelo usuário: ")
file_path = str(config_path) + "/msgram.json"
else:
print_info(f"[#A9A9A9] Não foi informado caminho do arquivo de configuração, será usado caminho padrão.")


except Exception as e:
print_error(f"KeyError: args[{e}] - non-existent parameters")
exit(1)


print_rule("[#FFFFFF] Listing Configuration Parameters")

if not (os.path.exists(file_path)):
print_info(f"[#A9A9A9] O arquivo de configuração não foi encontrado. \n Execute o comando msgram init no projeto desejado para criá-lo.")
exit()

print_info(f"MSGram config file [bold red]'{FILE_CONFIG}'[/] exists already!")

#get data
f = open(file_path)

data = json.load(f)

for characteristic in data.get("characteristics", []):
output_string = print_json_tree(characteristic)
print_info(output_string)

print_info(
"\n[#A9A9A9]Para editar o arquivo de configuração utilize em seu terminal o seguinte comando: vim <.msgram/msgram.json>"
)
31 changes: 30 additions & 1 deletion src/cli/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from pathlib import Path

from src.cli.commands import command_init, command_extract, command_calculate
from src.cli.commands.cmd_init import command_init
from src.cli.commands.cmd_extract import command_extract
from src.cli.commands.cmd_calculate import command_calculate
from src.cli.commands.cmd_print_config import command_list_config

from src.config.settings import (
AVAILABLE_IMPORTS,
SUPPORTED_FORMATS,
Expand Down Expand Up @@ -39,6 +43,31 @@ def create_parser():
)
parser_init.set_defaults(func=command_init) # function command init

# =====================================< COMMAND list_config >=====================================
parser_list_config = subparsers.add_parser(
"list",
help="Listing configurations parameters.",
)

parser_list_config.add_argument(
"-cp",
"--config_path",
type=lambda p: Path(p).absolute(),
default=DEFAULT_CONFIG_PATH,
help="Path to default config directory.",
)

parser_list_config.add_argument(
"all",
#type=str,
nargs="?",
help="Show configuration file.",
)

parser_list_config.set_defaults(func=command_list_config) # function command list config



# =====================================< COMMAND extract >=====================================
parser_extract = subparsers.add_parser("extract", help="Extract supported metrics")

Expand Down
2 changes: 2 additions & 0 deletions src/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ def print_panel(menssage: str, title: str = "Next steps"):
width=140,
),
)

# testegit
33 changes: 33 additions & 0 deletions tests/unit/data/expected_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Característica:
reliability
Peso: 50%
Sub-característica(s):
│ testing_status
│ Peso: 100%
│ │ Medida(s):
│ │ │ passed_tests
│ │ │ Peso: 33%
│ │ │ Métrica(s):
│ │ │ └─test_success_density
│ │ │ │ Valores de referência: Min = 0 e Max = 1
│ │ │ Fim-Métrica(s)
│ │ Fim-Medida(s)
│ │ Medida(s):
│ │ │ test_builds
│ │ │ Peso: 33%
│ │ │ Métrica(s):
│ │ │ └─tests
│ │ │ └─tests_execution_time
│ │ │ │ Valores de referência: Min = 0 e Max = 300000
│ │ │ Fim-Métrica(s)
│ │ Fim-Medida(s)
│ │ Medida(s):
│ │ │ test_coverage
│ │ │ Peso: 34%
│ │ │ Métrica(s):
│ │ │ └─coverage
│ │ │ │ Valores de referência: Min = 60 e Max = 100
│ │ │ Fim-Métrica(s)
│ │ Fim-Medida(s)
Fim-SubCaracterística
Fim-Característica
64 changes: 64 additions & 0 deletions tests/unit/data/newmsgram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"characteristics": [
{
"key": "reliability",
"weight": 50,
"subcharacteristics": [
{
"key": "testing_status",
"weight": 100,
"measures": [
{
"key": "passed_tests",
"weight": 33,
"min_threshold": 0,
"max_threshold": 1
},
{
"key": "test_builds",
"weight": 33,
"min_threshold": 0,
"max_threshold": 300000
},
{
"key": "test_coverage",
"weight": 34,
"min_threshold": 60,
"max_threshold": 100
}
]
}
]
},
{
"key": "maintainability",
"weight": 50,
"subcharacteristics": [
{
"key": "modifiability",
"weight": 100,
"measures": [
{
"key": "non_complex_file_density",
"weight": 33,
"min_threshold": 0,
"max_threshold": 10
},
{
"key": "commented_file_density",
"weight": 33,
"min_threshold": 10,
"max_threshold": 30
},
{
"key": "duplication_absense",
"weight": 34,
"min_threshold": 0,
"max_threshold": 5
}
]
}
]
}
]
}
Loading
Loading