GitLab 允许您通过运行删除合并的分支
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/repository/merged_branches
但不返回除状态码外的任何信息。
我怎么知道这个请求删除了哪些分支?
GitLab 允许您通过运行删除合并的分支
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/repository/merged_branches
但不返回除状态码外的任何信息。
我怎么知道这个请求删除了哪些分支?
不幸的是,无法从该请求中得知。我最近创建的一个解决方法是在删除所有合并的分支之前获取它们:
public function getAllMergedFeatures() : array
{
$merge_requests = $this->call("GET",
"{$this->basePath}/merge_requests?state=merged"
);
return array_column($merge_requests, 'source_branch');
}
这将为您提供已合并的所有分支的数组。
这是我使用的调用方法:
public function call(string $method, string $path, array $params = [])
{
try {
return json_decode(
$this->client->request(
$method,
$path,
array_merge(
$this->getHeaders(),
['form_params' => $params]
)
)->getBody()
);
} catch(Exception $e) {
return $e->getMessage();
}
}
调用 delete 方法后,您可以检查它们是否已全部删除或您想要这样做。此外,如果您的功能分支合并到多个分支中,它们将在数组中出现多次。一定要考虑到这一点。
祝你好运,希望这会有帮助。