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="GiteaRepoUser" value="bobemoe"/>
<env name="GiteaRepo" value="test"/>
<env name="GiteaTitle" value="project name"/>
</php>
<logging>

View File

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

View File

@ -13,7 +13,7 @@ final class PostFullReport{
$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;
// open connection and repo
$this->client=new Client($url, $user, $pass);
@ -23,7 +23,7 @@ final class PostFullReport{
// create the issue
if(trim($this->report)){
$issue=$this->repo->createIssue([
'title'=>"$title ({$this->failCount} fail)",
'title'=>'Test Results',
'body'=>$this->report
]);
}

View File

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