<commit_before><?php

namespace App\Notifications;

use GuzzleHttp\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use function json_decode;


class ReviewerNotifier extends Notification
{
    use Queueable;

    public $notification;
    public $client;

    /**
     * Create a new notification instance.
     * @param Request $notification
     */
    public function __construct($notification)
    {
        $this->client = new Client();
        $this->notification = $notification;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['slack'];
    }

    /**
     * Get the pull request commits list in markdown format
     *
     * @return array
     */
    public function getCommits()
    {
        $commitsUrl = $this->notification["pull_request"]["commits_url"];
        $commits = json_decode($this->client->get($commitsUrl)
            ->getBody()
            ->getContents(),
            true);

        $commitsList = [];
        foreach ($commits as $commit) {
            $commitsList[] = '- [' . $commit['commit']['message'] . '](' . $commit['html_url'] . ')';
        }

        return $commitsList;
    }

     public function toSlack($notifiable)                                                                                                
     {                                                                                                                                   

         $notification = $this->notification;                                                                                            


         $user = json_decode($this->client->get($notification["sender"]["url"])                                                          
             ->getBody()                                                                                                                 
             ->getContents(),                                                                                                            
             true);                                                                                                                      

         $name = $user['name'] ? $user['name'] : $notification["sender"]["login"];                                                       

         return (new SlackMessage)                                                                                                       
             ->from("Dashi")                                                                                                             
             ->image("http://icons.iconarchive.com/icons/thehoth/seo/256/seo-web-code-icon.png")                                         
             ->success()                                                                                                                 
             ->content(":point_right: ¡{$name} needs you to make him a Code Review to his changes!")                                     
             ->attachment(function ($attachment) use ($notification) {                                                                   
                 $attachment->title("Pull Request: " . $notification["pull_request"]["title"], $notification["pull_request"]["html_url"])
                     ->content("¡Make sure everything is in order before approving the Pull Request!")                                   
                     ->markdown(["Commits", "text"])                                                                                     
                     ->fields([                                                                                                          
                         "User" => $notification["sender"]["login"],                                                                     
                         "File(s) changed" => $notification["pull_request"]["changed_files"]                                                
                     ]);                                                                                                                 
             });                                                                                                                         
     }                                                                                                                                   

}<commit_msg>Add the number of commits in the notification - closes #4<commit_after><?php

namespace App\Notifications;

use GuzzleHttp\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use function json_decode;


class ReviewerNotifier extends Notification
{
    use Queueable;

    public $notification;
    public $client;

    /**
    * Create a new notification instance.
    * @param Request $notification
    */
    public function __construct($notification)
    {
        $this->client = new Client();
        $this->notification = $notification;
    }

    /**
    * Get the notification's delivery channels.
    *
    * @param  mixed $notifiable
    * @return array
    */
    public function via($notifiable)
    {
        return ['slack'];
    }

    /**
    * Get the pull request commits count
    *
    * @return array
    */
    public function getCommitsCount()
    {
        $commitsUrl = $this->notification["pull_request"]["commits_url"];
        $commits = json_decode($this->client->get($commitsUrl)
        ->getBody()
        ->getContents(),
        true);

        return count($commits);
    }

    public function toSlack($notifiable)
    {

        $notification = $this->notification;


        $user = json_decode($this->client->get($notification["sender"]["url"])
        ->getBody()
        ->getContents(),
        true);

        $name = $user['name'] ? $user['name'] : $notification["sender"]["login"];

        return (new SlackMessage)
        ->from("Dashi")
        ->image("http://icons.iconarchive.com/icons/thehoth/seo/256/seo-web-code-icon.png")
        ->success()
        ->content(":eyes: ¡{$name} needs you to make him a Code Review to his changes!")
        ->attachment(function ($attachment) use ($notification) {
            $attachment->title($notification["pull_request"]["title"], $notification["pull_request"]["html_url"])
            ->content(":sleuth_or_spy: ¡Make sure everything is in order before approving the Pull Request!")
            ->fields([
            "User" => $notification["sender"]["login"],
            "Commit(s)" => $this->getCommitsCount(),
            "File(s) changed" => $notification["pull_request"]["changed_files"]
            ]);
        });
    }

}
{'fraction_non_alphanumeric': 0.10487212458922704, 'fraction_numerical': 0.0010001428775539363, 'mean_word_length': 1.0390329158170697, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 80, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3417131', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1393, 'n_words': 297}