Exemple #1
0
def getDailyCommitData(repositoryList: list) -> str:
    print("Generating Daily Commit Data... ")

    if getenv('INPUT_TIMEZONE') == None:
        tz = "Asia/Kolkata"
    else:
        tz = getenv('INPUT_TIMEZONE')

    morning = 0  # 4 - 10
    daytime = 0  # 10 - 16
    evening = 0  # 16 - 22
    nighttime = 0  # 0 - 4

    for repository in repositoryList:
        result = Query.runGithubGraphqlQuery(
            createCommittedDateQuery.substitute(owner=repository["owner"]["login"], name=repository["name"], id=id))
        try:
            commitedDates = result["data"]["repository"]["ref"]["target"]["history"]["edges"]

            for committedDate in commitedDates:
                date = datetime.strptime(committedDate["node"]["committedDate"],
                                         "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=utc).astimezone(
                    timezone(tz))

                hour = date.hour

                if 6 <= hour < 12:
                    morning += 1
                if 12 <= hour < 18:
                    daytime += 1
                if 18 <= hour < 24:
                    evening += 1
                if 0 <= hour < 6:
                    nighttime += 1
        except Exception as exception:
            print("ERROR", repository["name"], "is private!")

    totalCommits = morning + daytime + evening + nighttime

    if morning + daytime >= evening + nighttime:
        title = "I'm an early 🐤"
    else:
        title = "I'm a night 🦉"

    eachDay = [
        {"name": "🌞 Morning", "text": str(
            morning) + " commits", "percent": round((morning / totalCommits) * 100, 2)},
        {"name": "🌆 Daytime", "text": str(
            daytime) + " commits", "percent": round((daytime / totalCommits) * 100, 2)},
        {"name": "🌃 Evening", "text": str(
            evening) + " commits", "percent": round((evening / totalCommits) * 100, 2)},
        {"name": "🌙 Night", "text": str(
            nighttime) + " commits", "percent": round((nighttime / totalCommits) * 100, 2)},
    ]

    print("Daily Commit Data created!")

    return "**" + title + "** \n\n" + \
        "```text\n" + makeCommitList(eachDay) + "\n\n```\n"
def getWeeklyCommitData(repositoryList: list) -> str:
    print("Generating Weekly Commit Data... ")

    tz = getenv('INPUT_TIMEZONE')

    weekdays = [0, 0, 0, 0, 0, 0, 0]

    for repository in repositoryList:
        result = Query.runGithubGraphqlQuery(
            createCommittedDateQuery.substitute(owner=username, name=repository["name"], id=id))
        try:
            commitedDates = result["data"]["repository"]["ref"]["target"]["history"]["edges"]

            for committedDate in commitedDates:
                date = datetime.strptime(committedDate["node"]["committedDate"],
                                         "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=utc).astimezone(
                    timezone(tz))

                weekday = date.strftime('%A')

                if weekday == "Monday":
                    weekdays[0] += 1
                if weekday == "Tuesday":
                    weekdays[1] += 1
                if weekday == "Wednesday":
                    weekdays[2] += 1
                if weekday == "Thursday":
                    weekdays[3] += 1
                if weekday == "Friday":
                    weekdays[4] += 1
                if weekday == "Saturday":
                    weekdays[5] += 1
                if weekday == "Sunday":
                    weekdays[6] += 1

        except Exception as exception:
            print("ERROR", repository["name"])

    totalCommits = sum(weekdays)

    dayOfWeek = [
        {"name": "Monday", "text": str(
            weekdays[0]) + " commits", "percent": round((weekdays[0] / totalCommits) * 100, 2)},
        {"name": "Tuesday", "text": str(
            weekdays[1]) + " commits", "percent": round((weekdays[1] / totalCommits) * 100, 2)},
        {"name": "Wednesday", "text": str(
            weekdays[2]) + " commits", "percent": round((weekdays[2] / totalCommits) * 100, 2)},
        {"name": "Thursday", "text": str(
            weekdays[3]) + " commits", "percent": round((weekdays[3] / totalCommits) * 100, 2)},
        {"name": "Friday", "text": str(
            weekdays[4]) + " commits", "percent": round((weekdays[4] / totalCommits) * 100, 2)},
        {"name": "Saturday", "text": str(
            weekdays[5]) + " commits", "percent": round((weekdays[5] / totalCommits) * 100, 2)},
        {"name": "Sunday", "text": str(
            weekdays[6]) + " commits", "percent": round((weekdays[6] / totalCommits) * 100, 2)},
    ]

    max_element = {
        'percent': 0
    }

    for day in dayOfWeek:
        if day['percent'] > max_element['percent']:
            max_element = day

    print("Weekly Commit Data created!")

    title = 'I\'m Most Productive on ' + max_element['name'] + 's'
    return "📅 **" + title + "** \n"+"""
| | | | |
| --- | --- | --- | --- |
""" + makeCommitList(dayOfWeek) + """