-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from fga-eps-mds/fix/tests
fix
- Loading branch information
Showing
4 changed files
with
93 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import json | ||
import sys | ||
import urllib.request | ||
from datetime import datetime | ||
|
||
def generate_metrics(): | ||
# url base do sonar, inicio da rota que devolverá as métricas | ||
base_url = "https://sonarcloud.io/api/measures/component_tree?component=" | ||
# prefixo da disciplina, identificador da organização no sonarcloud | ||
prefix = "fga-eps-mds" | ||
# todas as métricas que serão requisitadas para o sonarcloud | ||
metrics = [ | ||
"files", | ||
"functions", | ||
"complexity", | ||
"comment_lines_density", | ||
"duplicated_lines_density", | ||
"coverage", | ||
"ncloc", | ||
"tests", | ||
"test_errors", | ||
"test_failures", | ||
"test_execution_time", | ||
"security_rating" | ||
] | ||
|
||
# nome do repositório, vem como argumento no release.yml | ||
repository_name = sys.argv[1] | ||
# nome da branch onde foi chamada o script, vem de argumento no release.yml | ||
ref_name = sys.argv[2] | ||
|
||
# url montada | ||
# base url = api do sonar | ||
# prefix = id da org da disciplina | ||
# repository_name = nome do repositorio (unido com prefix separado por _ é o identificador do projeto no sonar) | ||
# o join do metrics une as métricas a serem solicitadas como parâmetros | ||
# branch = específica o nome da branch para pegar as métricas daquela branch em específicp | ||
|
||
# Verifica se a referência é uma branch ou uma tag | ||
url = f'{base_url}{prefix}_{repository_name}&metricKeys={",".join(metrics)}&branch={ref_name}' if 'refs/heads/' in sys.argv[2] else f'{base_url}{prefix}_{repository_name}&metricKeys={",".join(metrics)}&tag={ref_name}' | ||
|
||
|
||
with urllib.request.urlopen(url) as res: | ||
data = json.load(res) | ||
date = datetime.now() | ||
date_padrao_hilmer = f"{date.month}-{date.day}-{date.year}-{date.hour}-{date.minute}-{date.second}" | ||
|
||
underlined_repo_name = repository_name[:16] + \ | ||
repository_name[16:].replace('-', "_") | ||
|
||
filename = f"{prefix}-{underlined_repo_name}-{date_padrao_hilmer}-{ref_name}.json" | ||
print(filename) | ||
with open(filename, "w") as file: | ||
json.dump(data, file) | ||
|
||
|
||
if __name__ == "__main__": | ||
generate_metrics() |
This file was deleted.
Oops, something went wrong.