首页 > 解决方案 > Gitlab:使用Since属性过滤提交也会给出较旧的提交

问题描述

我试图只获得这一天的提交。我正在使用 CURL 发出请求。我已经尝试过 ISO 8601 和 RFC3339,但都没有产生我想要的结果。

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://gitlab.example.com/api/v4/projects/ID/repository/commits",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => array(
                "Private-Token: PRIVATE-TOKEN",
                "since: 2018-09-03T00:00:00Z",
                "until: 2018-09-04T00:00:00Z"

            ),
        )); 

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);
        $commits =  $response;

        print_r($commits);

标签: phpgitcurlgitlab-api

解决方案


我发现为了使它起作用,since 参数(以及与此相关的任何其他可选参数)需要在 url 中;

https://gitlab.example.com/api/v4/projects/ID/repository/commits?since=2018-09-03T00:00:00Z&until=2018-09-04T00:00:00Z

而不是像我一直在做的那样在标题中。


推荐阅读