From a5be144041f95234cfff2bd598a734be6131c42e Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Feb 2020 13:48:21 +0000 Subject: [PATCH] remove GiteaTitle env var, change title format to allow skipped/failed to use same issue --- README.md | 1 - src/PostFailedTests.php | 35 +++++++++++++++++------------------ src/PostFullReport.php | 4 ++-- src/ResultPrinter.php | 3 +-- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 32b63ce..91f6ec1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Enable in phpunit.xml with - diff --git a/src/PostFailedTests.php b/src/PostFailedTests.php index c155bb4..cb83573 100644 --- a/src/PostFailedTests.php +++ b/src/PostFailedTests.php @@ -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'; diff --git a/src/PostFullReport.php b/src/PostFullReport.php index a9dfd03..9af7fcd 100644 --- a/src/PostFullReport.php +++ b/src/PostFullReport.php @@ -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 ]); } diff --git a/src/ResultPrinter.php b/src/ResultPrinter.php index 069ead2..30df5b8 100644 --- a/src/ResultPrinter.php +++ b/src/ResultPrinter.php @@ -15,8 +15,7 @@ class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter{ getenv('GiteaUser'), getenv('GiteaPass'), getenv('GiteaRepoUser'), - getenv('GiteaRepo'), - getenv('GiteaTitle') + getenv('GiteaRepo') ); }