remove GiteaTitle env var, change title format to allow skipped/failed to use same issue

This commit is contained in:
James 2020-02-13 13:48:21 +00:00
parent 30db5377eb
commit a5be144041
4 changed files with 20 additions and 23 deletions

View File

@ -11,7 +11,6 @@ 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>

View File

@ -13,17 +13,14 @@ final class PostFailedTests{
private $fails=[]; private $fails=[];
private $client=null; private $client=null;
private $repo=null; private $repo=null;
private $title='';
function __construct($xml_path){ function __construct($xml_path){
$this->xml = simplexml_load_file($xml_path); $this->xml = simplexml_load_file($xml_path);
} }
public function post($url, $user, $pass, $repoUser, $repo, $title='Test Results'){ public function post($url, $user, $pass, $repoUser, $repo){
if(!$url) return; if(!$url) return;
$this->title=$title;
// open connection and repo // open connection and repo
$this->client=new Client($url, $user, $pass, true); $this->client=new Client($url, $user, $pass, true);
$this->repo=$this->client->getRepo($repoUser, $repo); $this->repo=$this->client->getRepo($repoUser, $repo);
@ -33,36 +30,38 @@ final class PostFailedTests{
private function fail($name,$att,$error,$message){ private function fail($name,$att,$error,$message){
//composer the issue message //composer the issue
$issue_title="$this->title $name ($error)"; $issueTitle="Failed test $name";
if(trim($message)) $message="```plain\n$message\n```\n"; $issueBody="";
foreach($att as $k=>$v){
$message.=" * $k = $v\n";
}
// upload any screenshots and add to message // 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;
$message="\n![]($url)\n".$message; $issueBody.="\n![]($url)\n";
unlink("/tmp/$name.png"); unlink("/tmp/$name.png");
} }
//add the message
if(trim($message)) $issueBody.="```plain\n$message.\n```\n";
// add the atts
$issueBody.=" * result = $error\n";
foreach($att as $k=>$v){
$issueBody.=" * $k = $v\n";
}
// does the issue exist // does the issue exist
$issue=$this->repo->getIssues(['q' => $issue_title])[0]??null; $issue=$this->repo->getIssues(['q' => $issueTitle])[0]??null;
if($issue){ if($issue){
$issue->addComment($message); $issue->addComment($issueBody);
}else{ }else{
$issue=$this->repo->createIssue([ $issue=$this->repo->createIssue([
'title'=>$issue_title, 'title'=>$issueTitle,
'body'=>$message 'body'=>$issueBody
]); ]);
} }
} }
private function success($name,$att){ private function success($name,$att){
$issue_title="$this->title $name"; $issue=$this->repo->getIssues(['q' => $name])[0]??null;
$issue=$this->repo->getIssues(['q' => $issue_title])[0]??null;
if($issue){ if($issue){
$issue->state='closed'; $issue->state='closed';

View File

@ -13,7 +13,7 @@ final class PostFullReport{
$this->xml = simplexml_load_file($xml_path); $this->xml = simplexml_load_file($xml_path);
} }
public function post($url, $user, $pass, $repoUser, $repo, $title='Test Results'){ public function post($url, $user, $pass, $repoUser, $repo){
if(!$url) return; if(!$url) return;
// open connection and repo // open connection and repo
$this->client=new Client($url, $user, $pass); $this->client=new Client($url, $user, $pass);
@ -23,7 +23,7 @@ final class PostFullReport{
// create the issue // create the issue
if(trim($this->report)){ if(trim($this->report)){
$issue=$this->repo->createIssue([ $issue=$this->repo->createIssue([
'title'=>"$title ({$this->failCount} fail)", 'title'=>'Test Results',
'body'=>$this->report 'body'=>$this->report
]); ]);
} }

View File

@ -15,8 +15,7 @@ class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter{
getenv('GiteaUser'), getenv('GiteaUser'),
getenv('GiteaPass'), getenv('GiteaPass'),
getenv('GiteaRepoUser'), getenv('GiteaRepoUser'),
getenv('GiteaRepo'), getenv('GiteaRepo')
getenv('GiteaTitle')
); );
} }