Ejemplo n.º 1
0
def main():
    metaStats = {"runtimes": []}

    if len(sys.argv) > 1 and sys.argv[1] == "--dry-run":
        configuration["dryRun"] = True

    # Make excludedEntities a list if it isn’t already (for backward compatibility)
    if not isinstance(configuration["excludedEntities"], list):
        configuration["excludedEntities"] = [configuration["excludedEntities"]]

    print("Preparing update of GitHub usage statistics", file=sys.stderr)
    sys.stderr.flush()

    # Prepare the data directory for writing the new data
    dataDirectory = locateDataDirectory()
    prepareDataDirectory(dataDirectory,
                         fetchChanges=not configuration["dryRun"])

    # Verify schema version for forward compatibility
    checkSchemaVersion(dataDirectory)

    configuration["today"] = datetime.date.today()

    # Update reports
    ReportAPIRequests(configuration, dataDirectory, metaStats).update()
    ReportAPIRequestsByUser(configuration, dataDirectory, metaStats).update()
    ReportContributorsByOrg(configuration, dataDirectory, metaStats).update()
    ReportContributorsByRepo(configuration, dataDirectory, metaStats).update()
    ReportFailedWebhooks(configuration, dataDirectory, metaStats).update()
    ReportForksToOrgs(configuration, dataDirectory, metaStats).update()
    ReportGitDownload(configuration, dataDirectory, metaStats).update()
    ReportGitProtocol(configuration, dataDirectory, metaStats).update()
    ReportGitRequests(configuration, dataDirectory, metaStats).update()
    ReportGitVersions(configuration, dataDirectory, metaStats).update()
    ReportGitVersionsNew(configuration, dataDirectory, metaStats).update()
    ReportOrgActivity(configuration, dataDirectory, metaStats).update()
    ReportOrgCollaboration(configuration, dataDirectory, metaStats).update()
    ReportOrgOwners(configuration, dataDirectory, metaStats).update()
    ReportOrgsAbandoned(configuration, dataDirectory, metaStats).update()
    ReportOrgsTotal(configuration, dataDirectory, metaStats).update()
    ReportPRByOrg(configuration, dataDirectory, metaStats).update()
    ReportPRByRepo(configuration, dataDirectory, metaStats).update()
    ReportPRHistory(configuration, dataDirectory, metaStats).update()
    ReportPRUsage(configuration, dataDirectory, metaStats).update()
    ReportRepoActivity(configuration, dataDirectory, metaStats).update()
    ReportRepositoryHistory(configuration, dataDirectory, metaStats).update()
    ReportRepoSize(configuration, dataDirectory, metaStats).update()
    ReportReposPersonalNonOwnerPushes(configuration, dataDirectory,
                                      metaStats).update()
    ReportRepoUsage(configuration, dataDirectory, metaStats).update()
    ReportTeamsLegacy(configuration, dataDirectory, metaStats).update()
    ReportTeamsTotal(configuration, dataDirectory, metaStats).update()
    ReportTokenlessAuth(configuration, dataDirectory, metaStats).update()
    ReportUsers(configuration, dataDirectory, metaStats).update()

    # Write meta infos
    writeMeta(dataDirectory)
    writeMetaStats(metaStats, dataDirectory)

    # Commit changes
    if not configuration["dryRun"]:
        executeCommand(
            ["git", "config", "user.name", configuration["userName"]],
            cwd=dataDirectory)
        executeCommand(
            ["git", "config", "user.email", configuration["userEMail"]],
            cwd=dataDirectory)
        executeCommand(["git", "add", "."], cwd=dataDirectory)
        executeCommand([
            "git", "commit", "--allow-empty",
            "-mUpdated GitHub usage statistics"
        ],
                       cwd=dataDirectory)
        executeCommand(["git", "push"], cwd=dataDirectory)

    print("Finished update of GitHub usage statistics", file=sys.stderr)
    sys.stderr.flush()
Ejemplo n.º 2
0
def main():
    metaStats = {"runtimes": []}

    if len(sys.argv) > 1 and sys.argv[1] == "--dry-run":
        configuration["dryRun"] = True

    # Make excludedEntities a list if it isn’t already (for backward compatibility)
    if not isinstance(configuration["excludedEntities"], list):
        configuration["excludedEntities"] = [configuration["excludedEntities"]]

    print("Preparing update of GitHub usage statistics", file=sys.stderr)
    sys.stderr.flush()

    localRepositoryName = "hubble-data"
    tmpDirectory = configuration["tmpDirectory"]
    dataDirectory = os.path.join(tmpDirectory, localRepositoryName)

    # Create data directory if not existing
    if not os.path.exists(dataDirectory):
        os.makedirs(dataDirectory)

    # Commit changes
    if not configuration["dryRun"]:
        # Clone data repository if necessary
        if not os.path.exists(os.path.join(dataDirectory, ".git")):
            executeCommand(
                ["git", "clone", configuration["repositoryURL"], "."],
                cwd=dataDirectory)
        else:
            executeCommand(["git", "fetch"], cwd=dataDirectory)
            executeCommand(["git", "reset", "--hard", "origin/master"],
                           cwd=dataDirectory)

    configuration["today"] = datetime.date.today()

    # Update reports
    ReportAPIRequests(configuration, dataDirectory, metaStats).update()
    ReportContributorsByOrg(configuration, dataDirectory, metaStats).update()
    ReportContributorsByRepo(configuration, dataDirectory, metaStats).update()
    ReportForksToOrgs(configuration, dataDirectory, metaStats).update()
    ReportGitDownload(configuration, dataDirectory, metaStats).update()
    ReportGitRequests(configuration, dataDirectory, metaStats).update()
    ReportGitVersions(configuration, dataDirectory, metaStats).update()
    ReportOrgCollaboration(configuration, dataDirectory, metaStats).update()
    ReportOrgOwners(configuration, dataDirectory, metaStats).update()
    ReportOrgsTotal(configuration, dataDirectory, metaStats).update()
    ReportPRByOrg(configuration, dataDirectory, metaStats).update()
    ReportPRByRepo(configuration, dataDirectory, metaStats).update()
    ReportPRHistory(configuration, dataDirectory, metaStats).update()
    ReportPRUsage(configuration, dataDirectory, metaStats).update()
    ReportRepoActivity(configuration, dataDirectory, metaStats).update()
    ReportRepositoryHistory(configuration, dataDirectory, metaStats).update()
    ReportTeamsTotal(configuration, dataDirectory, metaStats).update()
    ReportTokenlessAuth(configuration, dataDirectory, metaStats).update()
    ReportUsers(configuration, dataDirectory, metaStats).update()

    # Write meta infos
    writeMeta(dataDirectory)
    writeMetaStats(metaStats, dataDirectory)

    # Commit changes
    if not configuration["dryRun"]:
        executeCommand(
            ["git", "config", "user.name", configuration["userName"]],
            cwd=dataDirectory)
        executeCommand(
            ["git", "config", "user.email", configuration["userEMail"]],
            cwd=dataDirectory)
        executeCommand(["git", "add", "."], cwd=dataDirectory)
        executeCommand([
            "git", "commit", "--allow-empty",
            "-mUpdated GitHub usage statistics"
        ],
                       cwd=dataDirectory)
        executeCommand(["git", "push"], cwd=dataDirectory)

    print("Finished update of GitHub usage statistics", file=sys.stderr)
    sys.stderr.flush()