From 58c8e73caf5475685777566fe173b7b082ea01ba Mon Sep 17 00:00:00 2001 From: jvJUCA Date: Wed, 29 May 2024 17:35:57 -0300 Subject: [PATCH] fix: ishikawa python and yml --- .github/workflows/ishikawa-tools.yml | 9 +++- ishikawa_tools/ishikawa_tools_script.py | 57 +++++++------------------ 2 files changed, 22 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ishikawa-tools.yml b/.github/workflows/ishikawa-tools.yml index 37014975..755077c9 100644 --- a/.github/workflows/ishikawa-tools.yml +++ b/.github/workflows/ishikawa-tools.yml @@ -24,17 +24,22 @@ jobs: pip install matplotlib pandas requests PyGithub - name: Check environment variables + env: + ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + USER: ${{ secrets.USER }} + PROJECT: ${{ secrets.PROJECT }} run: | echo "User: $USER" echo "Project: $PROJECT" - echo "Token: ${#ACCESS_TOKEN}" # This will print the length of the token to ensure it's set, without exposing it. + echo "Token length: ${#ACCESS_TOKEN}" # This will print the length of the token to ensure it's set, without exposing it. - name: Run report generation script env: - ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + TOKEN: ${{ secrets.ACCESS_TOKEN }} USER: ${{ secrets.USER }} PROJECT: ${{ secrets.PROJECT }} run: python ishikawa_tools/ishikawa_tools_script.py + - uses: actions/upload-artifact@v4 with: name: ishikawa-screenshots diff --git a/ishikawa_tools/ishikawa_tools_script.py b/ishikawa_tools/ishikawa_tools_script.py index 34cec5b6..4c407a9f 100644 --- a/ishikawa_tools/ishikawa_tools_script.py +++ b/ishikawa_tools/ishikawa_tools_script.py @@ -7,19 +7,16 @@ from textwrap import wrap from pathlib import Path - def fetch_issues(repo_owner, repo_name, github_token): url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues" headers = {'Authorization': f'token {github_token}'} response = requests.get(url, headers=headers) if response.status_code != 200: print(f"Failed to fetch issues. Status code: {response.status_code}") - print(response.text) + print(response.json()) # Print the full error message return None else: - issues = response.json() - return issues - + return response.json() def generate_pareto_diagram(issues): labels_count = {} @@ -53,18 +50,11 @@ def generate_pareto_diagram(issues): plt.tight_layout() plt.savefig('./ishikawa_tools/output/pereto.pdf') - def generate_weekly_report(github_token, username, repository_name): - # Crear una instancia de la clase Github g = Github(github_token) - - # Obtener el repositorio repo = g.get_repo(f"{username}/{repository_name}") - - # Obtener todas las issues del repositorio issues = repo.get_issues(state='all') - # Diccionario para almacenar el recuento de issues por día de la semana weekly_counts = { 'Monday': {'opened': 0, 'closed': 0}, 'Tuesday': {'opened': 0, 'closed': 0}, @@ -94,7 +84,6 @@ def get_day_of_week(date_str): day_of_week = get_day_of_week(str(closed_at)) weekly_counts[day_of_week]['closed'] += 1 - # Extraer los datos para la tabla dias = list(weekly_counts.keys()) abiertas = [weekly_counts[d]["opened"] for d in weekly_counts] cerradas = [weekly_counts[d]["closed"] for d in weekly_counts] @@ -105,30 +94,17 @@ def get_day_of_week(date_str): "Cerradas": cerradas } - # Crear la tabla df = pd.DataFrame(data) - # Crear figura y eje fig, ax = plt.subplots() - - # Eliminar marcas del eje ax.axis('off') + tabla = ax.table(cellText=df.values, colLabels=df.columns, cellLoc='center', loc='center') - # Crear tabla - tabla = ax.table(cellText=df.values, - colLabels=df.columns, - cellLoc='center', - loc='center') - - # Ajustar tamaño de la fuente tabla.auto_set_font_size(False) tabla.set_fontsize(12) - - # Ajustar tamaño de la tabla tabla.scale(1.5, 1.5) plt.savefig('./ishikawa_tools/output/checklist.pdf') - def generate_histogram_report(repo_owner, repo_name, github_token): url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues" headers = {'Authorization': f'token {github_token}'} @@ -140,16 +116,11 @@ def generate_histogram_report(repo_owner, repo_name, github_token): else: issues = response.json() - labels_count = { - } - + labels_count = {} for issue in issues: for label in issue['labels']: label_name = label['name'] - if label_name in labels_count: - labels_count[label_name] += 1 - else: - labels_count[label_name] = 1 + labels_count[label_name] = labels_count.get(label_name, 0) + 1 plt.figure(figsize=(10, 6)) plt.bar(labels_count.keys(), labels_count.values()) @@ -159,7 +130,6 @@ def generate_histogram_report(repo_owner, repo_name, github_token): plt.yticks(range(0, max(labels_count.values()) + 1)) plt.savefig('./ishikawa_tools/output/histogram.pdf') - def generate_scatter_diagram_report(repo_owner, repo_name, github_token): url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues" headers = {'Authorization': f'token {github_token}'} @@ -176,8 +146,7 @@ def generate_scatter_diagram_report(repo_owner, repo_name, github_token): for issue in issues: created_at = datetime.strptime(issue['created_at'], '%Y-%m-%dT%H:%M:%SZ') - closed_at = datetime.strptime(issue['closed_at'], '%Y-%m-%dT%H:%M:%SZ') if issue[ - 'closed_at'] else datetime.now() + closed_at = datetime.strptime(issue['closed_at'], '%Y-%m-%dT%H:%M:%SZ') if issue['closed_at'] else datetime.now() time_to_close = (closed_at - created_at).days days_to_close.append(time_to_close) issue_created_dates.append(created_at) @@ -190,20 +159,24 @@ def generate_scatter_diagram_report(repo_owner, repo_name, github_token): plt.grid(True) plt.savefig('./ishikawa_tools/output/scatter.pdf') - def main(): - github_token = os.getenv('ACCESS_TOKEN') + github_token = os.getenv('TOKEN') username = os.getenv('USER') repository_name = os.getenv('PROJECT') + if not all([github_token, username, repository_name]): + print("One or more environment variables are missing.") + return + issues = fetch_issues(username, repository_name, github_token) - Path("./ishikawa_tools/output").mkdir(parents=True, exist_ok=True) + if issues is None: + print("Exiting script due to fetch issues failure.") + return generate_pareto_diagram(issues) + generate_weekly_report(github_token, username, repository_name) generate_histogram_report(username, repository_name, github_token) generate_scatter_diagram_report(username, repository_name, github_token) - generate_weekly_report(github_token, username, repository_name) - if __name__ == "__main__": main()