* Finish count_of_merged_pull_requests_in_codebase.

This commit is contained in:
qixinzhi
2023-10-12 02:58:17 +00:00
parent 28eaa0b057
commit 376e8dd72b
2 changed files with 61 additions and 0 deletions
@@ -0,0 +1,41 @@
<?php
/**
* 按代码库统计合并请求合并次数。
* Count of merged pull requests in codebase.
*
* 范围:code
* 对象:mergeRequest
* 目的:rate
* 度量名称:按代码库统计合并请求合并次数
* 单位:个
* 描述:按代码库统计的合并请求合并次数是指在代码库中完成的全部合并请求的数量。该度量项反映了代码库的合并流程和代码合并质量,有助于评估团队的协作效率和代码更新情况。
* 定义:代码库中合并请求合并次数相加。;不包含已删除。;
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @author qixinzhi <qixinzhi@easycorp.ltd>
* @package
* @uses func
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @Link https://www.zentao.net
*/
class count_of_merged_pull_requests_in_codebase extends baseCalc
{
public $dataset = 'getMRs';
public $fieldList = array('t2.id');
public $result = array();
public function calculate($row)
{
$codebase = $row->id;
if(!isset($this->result[$codebase])) $this->result[$codebase] = 0;
$this->result[$codebase] += 1;
}
public function getResult($options = array())
{
$records = $this->getRecords(array('codebase', 'value'));
return $this->filterByOptions($records, $options);
}
}
@@ -0,0 +1,20 @@
#!/usr/bin/env php
<?php
/**
title=count_of_merged_pull_requests_in_codebase
cid=1
timeout=0
*/
include dirname(__FILE__, 7) . '/test/lib/init.php';
include dirname(__FILE__, 4) . '/calc.class.php';
zdTable('repo')->config('repo', true, 4)->gen(10);
zdTable('mr')->config('mr', true, 4)->gen(1000);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
r($calc->getResult(array('codebase' => '3'))) && p('0:value') && e('54'); // 测试合并请求数。