<commit_before><?php

/**
 *  A 'weekly' provider, or 'hints' is designed to prompt the
 *  user to remember what they did in the last week, so they can
 *  fill out their weekly report more accurately.
 *
 *  The class name doesn't matter.. It's picked in the config.
 *
 *  Your constructor should accept the following variables:
 *  - $username: The username of the person the hints are for
 *  - $config: An array of the config options that came from config.php
 *  - $events_from: The beginning of the period to show hints for
 *  - $events_to: The end of the period to show hints for
 *
 *  Then, just create a public function 'printHints' that returns HTML to be
 *  inserted into the sidebar of the "add report" page.
 *
 **/

class GithubHints {
    private $github_url;
    private $events_from, $events_to;
    private $username;

    public function __construct($username, $config, $events_from, $events_to) {
        $this->github_url = $config['github_url'];
        $ghusername_fromdb = getGithubUsernameFromDb();
        if (!($ghusername_fromdb == NULL)) {
            $this->username = getGithubUsernameFromDb();
        } else {
            $this->username = $username;
        }
        $this->events_from = $events_from;
        $this->events_to = $events_to;
        if(isset($config['github_token'])) {
            $this->github_token = $config['github_token'];
        } else {
            $this->github_token = false;
        }
    }

    public function printHints() {
        if(!$activities = $this->getGithubActivity()) {
            return insertNotify("error", "No Github activity could be loaded");
        }
        if (count($activities) > 0) {
            $html = "<ul>";
            foreach ($activities as $activity) {
                $repo_base = $activity->repo->name; 
                $date_base = $activity->created_at;
                # There are other activity types other than commit, but for now we'll pretend they don't exist.
                # This block handles direct requests to github.com/username.json 
                if (isset($activity->repository->owner)) {
                    $friendly_name = "{$activity->repository->owner}/{$activity->repository->name}";
                    $url_base = "{$activity->repository->url}/commit/";
                    if (isset($activity->payload->shas)) {
                        foreach ($activity->payload->shas as $commit) {
                            if (((strtotime($date_base)) >= $this->events_from) && ((strtotime($date_base)) <= $this->events_to)) {
                                $html .= '<li><a href="' . $url_base . $commit[0] . '" target="_blank">';
                                $html .= "{$friendly_name}</a> - {$commit[2]}</li>";
                            }    
                        }
                    }
                }
                # This block handles requests via api URL
                if(isset($activity->payload->commits)) {
                    $url_base = "{$this->github_url}/{$activity->repo->name}/commit/";
                    foreach ($activity->payload->commits as $commit) {
                        if (((strtotime($date_base)) >= $this->events_from) && ((strtotime($date_base)) <= $this->events_to)) {
                            $html .= "<li><a href=\"{$url_base}{$commit->sha}\">";
                            $html .= "{$repo_base}</a> - {$commit->message}</li>";
                        }
                    }<commit_msg>Reviewed github provider code<commit_after><?php

/**
 *  A 'weekly' provider, or 'hints' is designed to prompt the
 *  user to remember what they did in the last week, so they can
 *  fill out their weekly report more accurately.
 *
 *  The class name doesn't matter.. It's picked in the config.
 *
 *  Your constructor should accept the following variables:
 *  - $username: The username of the person the hints are for
 *  - $config: An array of the config options that came from config.php
 *  - $events_from: The beginning of the period to show hints for
 *  - $events_to: The end of the period to show hints for
 *
 *  Then, just create a public function 'printHints' that returns HTML to be
 *  inserted into the sidebar of the "add report" page.
 *
 **/

class GithubHints {
    private $github_url;
    private $events_from, $events_to;
    private $username;

    public function __construct($username, $config, $events_from, $events_to) {
        $this->github_url = $config['github_url'];
        $ghusername_fromdb = getGithubUsernameFromDb();
        if (!($ghusername_fromdb == NULL)) {
            $this->username = getGithubUsernameFromDb();
        } else {
            $this->username = $username;
        }
        $this->events_from = $events_from;
        $this->events_to = $events_to;
        if(isset($config['github_token'])) {
            $this->github_token = $config['github_token'];
        } else {
            $this->github_token = false;
        }
    }

    public function printHints() {
        if(!$activities = $this->getGithubActivity()) {
            return insertNotify("error", "No Github activity could be loaded");
        }
        if (count($activities) > 0) {
            $html = "<ul>";
            foreach ($activities as $activity) {
                $date_base = $activity->created_at;
                # There are other activity types other than commit, but for now we'll pretend they don't exist.
                # This block handles direct requests to github.com/username.json 
                if (isset($activity->repository->owner)) {
                    $friendly_name = "{$activity->repository->owner}/{$activity->repository->name}";
                    $url_base = "{$activity->repository->url}/commit/";
                    if (isset($activity->payload->shas)) {
                        foreach ($activity->payload->shas as $commit) {
                            if (((strtotime($date_base)) >= $this->events_from) && ((strtotime($date_base)) <= $this->events_to)) {
                                $html .= '<li><a href="' . $url_base . $commit[0] . '" target="_blank">';
                                $html .= "{$friendly_name}</a> - {$commit[2]}</li>";
                            }    
                        }
                    }
                }
                # This block handles requests via api URL
                if(isset($activity->payload->commits)) {
                    $friendly_name = $activity->repo->name; 
                    $url_base = "{$this->github_url}/{$activity->repo->name}/commit/";
                    foreach ($activity->payload->commits as $commit) {
                        if (((strtotime($date_base)) >= $this->events_from) && ((strtotime($date_base)) <= $this->events_to)) {
                            $html .= "<li><a href=\"{$url_base}{$commit->sha}\">";
                            $html .= "{$friendly_name}</a> - {$commit->message}</li>";
                        }
                    }
{'fraction_non_alphanumeric': 0.13789141051422005, 'fraction_numerical': 0.0008618213157138753, 'mean_word_length': 1.906093489148581, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5871520', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1827, 'n_words': 497}