make repeat fails just link to previous post rather than posting again
This commit is contained in:
parent
a5be144041
commit
e8ef5f535c
@ -30,34 +30,80 @@ final class PostFailedTests{
|
||||
|
||||
|
||||
private function fail($name,$att,$error,$message){
|
||||
//composer the issue
|
||||
$issueTitle="Failed test $name";
|
||||
$issueBody="";
|
||||
// upload any screenshots and add to message
|
||||
//stick the error type into the atts array
|
||||
$att['result']=$error;
|
||||
//trim the message
|
||||
$message=trim($message);
|
||||
|
||||
// get any existing issue
|
||||
$issue=$this->repo->getIssues(['q' => $name])[0]??null;
|
||||
|
||||
// if existing issue, is the error the same?
|
||||
if($issue){
|
||||
if( $this->doesMessageMatch($issue->body,$message,$att) ){
|
||||
$issue->addComment("Failed again. Same errors [above]($issue->html_url#issue-{$issue->id})");
|
||||
return;
|
||||
}else{
|
||||
foreach($issue->getComments() as $comment){
|
||||
if( $this->doesMessageMatch($comment->body,$message,$att) ){
|
||||
$issue->addComment("Failed again. Same errors as [above]($issue->html_url#issuecomment-{$comment->id})");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//so its a new iss or changed error, lets upload screenshot and compose the body
|
||||
$issueBody='';
|
||||
if(file_exists("/tmp/$name.png")){
|
||||
$data=$this->repo->addReleaseAttachment(1,"/tmp/$name.png");
|
||||
$url=$data->browser_download_url;
|
||||
$issueBody.="\n\n";
|
||||
unlink("/tmp/$name.png");
|
||||
}
|
||||
//add the message
|
||||
if(trim($message)) $issueBody.="```plain\n$message.\n```\n";
|
||||
// add the atts
|
||||
$issueBody.=" * result = $error\n";
|
||||
if($message) $issueBody.="```plain\n$message\n```\n";
|
||||
foreach($att as $k=>$v){
|
||||
$issueBody.=" * $k = $v\n";
|
||||
}
|
||||
|
||||
// does the issue exist
|
||||
$issue=$this->repo->getIssues(['q' => $issueTitle])[0]??null;
|
||||
//post the body
|
||||
if($issue){
|
||||
$issue->addComment($issueBody);
|
||||
}else{
|
||||
$issue=$this->repo->createIssue([
|
||||
'title'=>$issueTitle,
|
||||
'title'=>'Failed test '.$name,
|
||||
'body'=>$issueBody
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function doesMessageMatch($body,$message,$att){
|
||||
// extract the old message
|
||||
preg_match('#```plain\n(.*)\n```#s',$body,$match);
|
||||
$messageOld=$match[1]??'';
|
||||
// return false if not the same
|
||||
if( $message != $messageOld ){
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract the old atts
|
||||
$attOld=[];
|
||||
preg_match_all('# \* (.*?) = (.*)#',$body,$m);
|
||||
foreach($m[0]??[] as $k=>$v){
|
||||
$attOld[$m[1][$k]]=$m[2][$k];
|
||||
}
|
||||
// make sure all current attributes (except time) are the same as old
|
||||
// return false on first mis-match
|
||||
foreach($att as $k=>$v){
|
||||
if($k=='time') continue;
|
||||
if(($attOld[$k]??null) != $v){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// all matches, error message is the same
|
||||
return true;
|
||||
}
|
||||
|
||||
private function success($name,$att){
|
||||
|
Loading…
Reference in New Issue
Block a user