Skip to content

Commit

Permalink
fix: ishikawa python and yml
Browse files Browse the repository at this point in the history
  • Loading branch information
jvJUCA committed May 29, 2024
1 parent ba8131c commit 58c8e73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 44 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ishikawa-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 15 additions & 42 deletions ishikawa_tools/ishikawa_tools_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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]
Expand All @@ -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}'}
Expand All @@ -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())
Expand All @@ -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}'}
Expand All @@ -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)
Expand All @@ -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()

0 comments on commit 58c8e73

Please sign in to comment.