Connection.php 967 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php

namespace GitLab;

use GuzzleHttp\Client;

class Connection
{
    /** @var Client */
    private $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    public function mergeRequests($state = 'all') {

        $url = env('GITLAB_URL') . '/merge_requests?scope=all&per_page=50&state='. $state;

xiphon's avatar
xiphon committed
21
        $response = $this->client->request('GET', $url);
22 23 24 25

        return collect(json_decode($response->getBody()));
    }

26 27
    public function getNewFiles($merge_request_iid) {
        $url = env('GITLAB_URL') . '/merge_requests/' . $merge_request_iid . '/changes';
xiphon's avatar
xiphon committed
28
        $response = $this->client->request('GET', $url);
29 30 31 32 33 34 35 36 37 38 39 40 41
        $deserialized = collect(json_decode($response->getBody()));

        $result = [];
        foreach ($deserialized['changes'] as $change) {
            if ($change->new_file) {
                $result[] = $change->new_path;
            }
        }

        return $result;
    }


xiphon's avatar
xiphon committed
42
}