* [bug#59402] add get merge requests method for gitea.

This commit is contained in:
caoyanyi
2025-01-22 08:56:21 +08:00
committed by 田淑杰
parent 4a956675c9
commit 292b5c9b85
+36
View File
@@ -392,4 +392,40 @@ class giteaModel extends model
return $newBranches;
}
/**
* API获取项目的合并请求列表。
* Get Merge Requests by API.
*
* @param int $giteaID
* @param string $project
* @access public
* @return array
*/
public function apiGetMergeRequests(int $giteaID, string $project): array
{
$apiRoot = $this->getApiRoot($giteaID, false);
$apiPath = "/repos/{$project}/pulls";
$url = sprintf($apiRoot, $apiPath);
$mrList = json_decode(common::http($url));
foreach($mrList as $mr)
{
$mr->web_url = $mr->url;
$mr->iid = $mr->number;
$mr->state = $mr->state == 'open' ? 'opened' : $mr->state;
if($mr->merged) $mr->state = 'merged';
$mr->merge_status = $mr->mergeable ? 'can_be_merged' : 'cannot_be_merged';
$mr->description = $mr->body;
$mr->target_branch = $mr->base->ref;
$mr->source_branch = $mr->head->ref;
$mr->source_project_id = $project;
$mr->target_project_id = $project;
$mr->has_conflicts = empty($diff) ? true : false;
$mr->is_draft = strpos($mr->title, 'Draft:') === 0;
}
return $mrList;
}
}