add closing of failed tests
This commit is contained in:
parent
b2c3faf5c1
commit
30db5377eb
@ -11,6 +11,7 @@ Enable in phpunit.xml with
|
|||||||
<!--env name="GiteaPass" value="xxx"/--> <!--probably set this on the machine env-->
|
<!--env name="GiteaPass" value="xxx"/--> <!--probably set this on the machine env-->
|
||||||
<env name="GiteaRepoUser" value="bobemoe"/>
|
<env name="GiteaRepoUser" value="bobemoe"/>
|
||||||
<env name="GiteaRepo" value="test"/>
|
<env name="GiteaRepo" value="test"/>
|
||||||
|
<env name="GiteaTitle" value="project name"/>
|
||||||
</php>
|
</php>
|
||||||
|
|
||||||
<logging>
|
<logging>
|
||||||
|
@ -3,6 +3,11 @@ namespace JHodges\GiteaBotPHPUnit;
|
|||||||
|
|
||||||
use \JHodges\GiteaBot\Client;
|
use \JHodges\GiteaBot\Client;
|
||||||
|
|
||||||
|
/* creates a new issue for each failed test
|
||||||
|
* if it already exists then report is added as a comment
|
||||||
|
* if it passes then the issue is closed
|
||||||
|
*/
|
||||||
|
|
||||||
final class PostFailedTests{
|
final class PostFailedTests{
|
||||||
|
|
||||||
private $fails=[];
|
private $fails=[];
|
||||||
@ -26,23 +31,15 @@ final class PostFailedTests{
|
|||||||
$this->process($this->xml);
|
$this->process($this->xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function findIssue($title){
|
|
||||||
foreach($this->repo->getIssues(['q' => $title]) as $issue) {
|
|
||||||
// loop through the current issues comments
|
|
||||||
if($issue->title===$title){
|
|
||||||
return $issue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function fail($name,$error,$message,$att){
|
private function fail($name,$att,$error,$message){
|
||||||
$issue_title="$this->title $error $name";
|
//composer the issue message
|
||||||
|
$issue_title="$this->title $name ($error)";
|
||||||
if(trim($message)) $message="```plain\n$message\n```\n";
|
if(trim($message)) $message="```plain\n$message\n```\n";
|
||||||
foreach($att as $k=>$v){
|
foreach($att as $k=>$v){
|
||||||
$message.=" * $k = $v\n";
|
$message.=" * $k = $v\n";
|
||||||
}
|
}
|
||||||
|
// upload any screenshots and add to message
|
||||||
if(file_exists("/tmp/$name.png")){
|
if(file_exists("/tmp/$name.png")){
|
||||||
$data=$this->repo->addReleaseAttachment(1,"/tmp/$name.png");
|
$data=$this->repo->addReleaseAttachment(1,"/tmp/$name.png");
|
||||||
$url=$data->browser_download_url;
|
$url=$data->browser_download_url;
|
||||||
@ -50,8 +47,8 @@ final class PostFailedTests{
|
|||||||
unlink("/tmp/$name.png");
|
unlink("/tmp/$name.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
$issue=$this->findIssue($issue_title);
|
// does the issue exist
|
||||||
|
$issue=$this->repo->getIssues(['q' => $issue_title])[0]??null;
|
||||||
if($issue){
|
if($issue){
|
||||||
$issue->addComment($message);
|
$issue->addComment($message);
|
||||||
}else{
|
}else{
|
||||||
@ -62,13 +59,29 @@ final class PostFailedTests{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function success($name,$att){
|
||||||
|
$issue_title="$this->title $name";
|
||||||
|
|
||||||
|
$issue=$this->repo->getIssues(['q' => $issue_title])[0]??null;
|
||||||
|
|
||||||
|
if($issue){
|
||||||
|
$issue->state='closed';
|
||||||
|
$issue->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function process($item){
|
private function process($item){
|
||||||
if(isset($item->testcase)){
|
if(isset($item->testcase)){
|
||||||
foreach($item->testcase as $testcase) {
|
foreach($item->testcase as $testcase) {
|
||||||
$att=$testcase->attributes();
|
$att=$testcase->attributes();
|
||||||
$name=$testcase->attributes()->class[0].'::'.$testcase->attributes()->name[0];
|
$name=$testcase->attributes()->class[0].'::'.$testcase->attributes()->name[0];
|
||||||
|
$fail=false;
|
||||||
foreach($testcase as $k=>$v){
|
foreach($testcase as $k=>$v){
|
||||||
$this->fail($name,$k,$v,$att);
|
$this->fail($name,$att,$k,$v);
|
||||||
|
$fail=true;
|
||||||
|
}
|
||||||
|
if(!$fail){
|
||||||
|
$this->success($name,$att);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user