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

[Statistiques] Suivi du nombre de PR corrigeant un bogue et fusionnées dans la journée #5322

Merged
merged 4 commits into from
Jan 22, 2025

Conversation

celine-m-s
Copy link
Collaborator

@celine-m-s celine-m-s commented Dec 30, 2024

🤔 Pourquoi ?

Afin de suivre la qualité de notre code et d'en parler pendant les comités.
⚠️ Le script de reprise de l'historique est dans le dernier commit. Le code sera lancé à la main dans la console de Clever et le commit sera supprimé avant la fusion de cette PR. le commit est là pour permettre aux relecteurs de laisser des commentaires plus facilement. ^_^

🍰 Comment ?

Récupération de la liste des PR qui ont été étiquetées Bug. Décompte puis conservation dans l'app Analytics.

Script de récupération du stock :

import datetime
import logging

from dateutil.rrule import DAILY, rrule
from django import db
from django.db import transaction
from django.forms import models
from django.utils import timezone

from itou.analytics.models import Datum, DatumCode
from itou.utils.apis.github import GithubApiClient


logger = logging.getLogger("itou.analytics")

end = timezone.now()
start = datetime.datetime(2024, 9, 30, tzinfo=datetime.UTC)
days = (end - start).days
dates = list(rrule(freq=DAILY, dtstart=start, count=days))

data = GithubApiClient()._request(endpoint="les-emplois/issues", start=start).json()
counter = 0

for date in dates:
    day = date.date()
    filtered_data = GithubApiClient().filter_by_merged_at(data=data, date=day)
    total = len(filtered_data)
    counter += total

    bucket = day.isoformat()
    logger.info(f"Saving analytics data in '{bucket=}' {total=}.")

    datum = Datum(
        code=DatumCode.TECH_GH_TOTAL_BUGS.value,
        bucket=bucket,
        value=total,
    )
    try:
        with transaction.atomic():
            datum.save()
    except db.IntegrityError:
        logger.error(f"Failed to save {DatumCode.TECH_GH_TOTAL_BUGS.value=} for {bucket=} because it already exists.")
    except models.ValidationError as error:
        message = (
            f"Failed to save {DatumCode.TECH_GH_TOTAL_BUGS.value=} for {bucket=} because of a ValidationError: "
            f"{error.message}"
        )
        logger.error(message)
    else:
        logger.info(f"Successfully saved {DatumCode.TECH_GH_TOTAL_BUGS.value=} {bucket=} {total=}.")

logger.info(f"{counter} bug pull requests were merged since {start.date()}. Great job! 🎉")

🚨 À vérifier

  • Mettre à jour le CHANGELOG_breaking_changes.md ?

@celine-m-s celine-m-s self-assigned this Dec 30, 2024
@celine-m-s celine-m-s force-pushed the celinems/gh-stats branch 2 times, most recently from 24de2cc to 77f100e Compare December 30, 2024 20:17
@celine-m-s celine-m-s added the no-changelog Ne doit pas figurer dans le journal des changements. label Dec 30, 2024
@celine-m-s celine-m-s changed the title [Statistiques] Suivi du nombre de PR de correctifs fusionnées dans la journée [Statistiques] Suivi du nombre de PR corrigeant un bogue et fusionnées dans la journée Jan 7, 2025
@celine-m-s celine-m-s requested a review from rsebille January 8, 2025 17:09
@celine-m-s celine-m-s marked this pull request as ready for review January 8, 2025 17:10
@celine-m-s celine-m-s requested a review from tonial January 13, 2025 10:33
itou/to_be_deleted.py Outdated Show resolved Hide resolved
itou/utils/apis/github.py Outdated Show resolved Hide resolved
itou/utils/apis/github.py Outdated Show resolved Hide resolved

def test_pagination_required(respx_mock, mocker, caplog):
mocker.patch.object(GithubApiClient, "MAX_RESULTS_PER_PAGE", 2)
with open(os.path.join(settings.ROOT_DIR, "tests", "data", "github.json")) as file:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autre possibilité: tu définis mocker.patch.object(GithubApiClient, "MAX_RESULTS_PER_PAGE", <le nombre de données présentes dans github.json>)

@celine-m-s celine-m-s enabled auto-merge January 22, 2025 10:31
@celine-m-s celine-m-s added this pull request to the merge queue Jan 22, 2025
@celine-m-s celine-m-s removed this pull request from the merge queue due to a manual request Jan 22, 2025
@celine-m-s celine-m-s added this pull request to the merge queue Jan 22, 2025
Merged via the queue into master with commit 70c1b07 Jan 22, 2025
9 checks passed
@celine-m-s celine-m-s deleted the celinems/gh-stats branch January 22, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Ne doit pas figurer dans le journal des changements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants