Skip to content

Commit

Permalink
Add condition not to post skipped files comment when it has been done…
Browse files Browse the repository at this point in the history
… in the same PR before

+Adjust var names to keep consistency
  • Loading branch information
ariskataoka committed Oct 26, 2021
1 parent 14729f8 commit 18e2a10
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 23 deletions.
216 changes: 216 additions & 0 deletions build/requirements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Test Documentation</title>
<style>
body {
text-rendering: optimizeLegibility;
font-variant-ligatures: common-ligatures;
font-kerning: normal;
margin-left: 2em;
}

body > ul > li {
font-family: Source Serif Pro, PT Sans, Trebuchet MS, Helvetica, Arial;
font-size: 2em;
}

h2 {
font-family: Tahoma, Helvetica, Arial;
font-size: 3em;
}

ul {
list-style: none;
margin-bottom: 1em;
}
</style>
</head>
<body>
<h2 id="Vipgoci\Tests\Unit\A00IrcApiAlertQueueTest">A00 Irc Api Alert Queue (Vipgoci\Tests\Unit\A00IrcApiAlertQueue)</h2>
<ul>
<li style="color: #555753;">✓ Irc queue 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\A00IrcApiAlertQueueUniqueTest">A00 Irc Api Alert Queue Unique (Vipgoci\Tests\Unit\A00IrcApiAlertQueueUnique)</h2>
<ul>
<li style="color: #555753;">✓ Irc queue unique 1</li>
<li style="color: #555753;">✓ Irc queue unique 2</li>
<li style="color: #555753;">✓ Irc queue unique 3</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\A00StatsCountersTest">A00 Stats Counters (Vipgoci\Tests\Unit\A00StatsCounters)</h2>
<ul>
<li style="color: #555753;">✓ Counter report 1</li>
<li style="color: #555753;">✓ Counter report 2</li>
<li style="color: #555753;">✓ Counter update with issues found 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\GitHubApiCurlHeadersTest">Git Hub Api Curl Headers (Vipgoci\Tests\Unit\GitHubApiCurlHeaders)</h2>
<ul>
<li style="color: #555753;">✓ Curl headers 1</li>
<li style="color: #555753;">✓ Curl headers 2</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\GitHubOauth1HeadersGetTest">Git Hub Oauth1 Headers Get (Vipgoci\Tests\Unit\GitHubOauth1HeadersGet)</h2>
<ul>
<li style="color: #555753;">✓ O auth headers 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\GitHubOauthSignatureGetHmacSha1Test">Git Hub Oauth Signature Get Hmac Sha1 (Vipgoci\Tests\Unit\GitHubOauthSignatureGetHmacSha1)</h2>
<ul>
<li style="color: #555753;">✓ O auth hmac sha 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscBlameFilterCommentsTest">Misc Blame Filter Comments (Vipgoci\Tests\Unit\MiscBlameFilterComments)</h2>
<ul>
<li style="color: #555753;">✓ Blame filter comments 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscCacheTest">Misc Cache (Vipgoci\Tests\Unit\MiscCache)</h2>
<ul>
<li style="color: #555753;">✓ Cache 1</li>
<li style="color: #555753;">✓ Cache 2</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscCachedIndicationStrTest">Misc Cached Indication Str (Vipgoci\Tests\Unit\MiscCachedIndicationStr)</h2>
<ul>
<li style="color: #555753;">✓ Cached indication str 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscConvertStringToTypeTest">Misc Convert String To Type (Vipgoci\Tests\Unit\MiscConvertStringToType)</h2>
<ul>
<li style="color: #555753;">✓ Convert 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscFileExtensionTest">Misc File Extension (Vipgoci\Tests\Unit\MiscFileExtension)</h2>
<ul>
<li style="color: #555753;">✓ File extension 1</li>
<li style="color: #555753;">✓ File extension 2</li>
<li style="color: #555753;">✓ File extension 3</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscFilterFilePathTest">Misc Filter File Path (Vipgoci\Tests\Unit\MiscFilterFilePath)</h2>
<ul>
<li style="color: #555753;">✓ Filter file path 1</li>
<li style="color: #555753;">✓ Filter file path 2</li>
<li style="color: #555753;">✓ Filter file path 3</li>
<li style="color: #555753;">✓ Filter file path 4</li>
<li style="color: #555753;">✓ Filter file path 5</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscFindFieldsInArrayTest">Misc Find Fields In Array (Vipgoci\Tests\Unit\MiscFindFieldsInArray)</h2>
<ul>
<li style="color: #555753;">✓ Find fields 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscGitHubCommentMatchTest">Misc Git Hub Comment Match (Vipgoci\Tests\Unit\MiscGitHubCommentMatch)</h2>
<ul>
<li style="color: #555753;">✓ Comment match 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscGitHubEmojisTest">Misc Git Hub Emojis (Vipgoci\Tests\Unit\MiscGitHubEmojis)</h2>
<ul>
<li style="color: #555753;">✓ Git hub emojis 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscGitHubPrRemoveDraftsTest">Misc Git Hub Pr Remove Drafts (Vipgoci\Tests\Unit\MiscGitHubPrRemoveDrafts)</h2>
<ul>
<li style="color: #555753;">✓ Remove draft prs</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscMarkdownCommentAddPagebreakTest">Misc Markdown Comment Add Pagebreak (Vipgoci\Tests\Unit\MiscMarkdownCommentAddPagebreak)</h2>
<ul>
<li style="color: #555753;">✓ Page break 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscRoundArrayItemsTest">Misc Round Array Items (Vipgoci\Tests\Unit\MiscRoundArrayItems)</h2>
<ul>
<li style="color: #555753;">✓ Round array items</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscSanitizePathPrefixTest">Misc Sanitize Path Prefix (Vipgoci\Tests\Unit\MiscSanitizePathPrefix)</h2>
<ul>
<li style="color: #555753;">✓ Sanitize path prefix 1</li>
<li style="color: #555753;">✓ Sanitize path prefix 2</li>
<li style="color: #555753;">✓ Sanitize path prefix 3</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\MiscSanitizeStringTest">Misc Sanitize String (Vipgoci\Tests\Unit\MiscSanitizeString)</h2>
<ul>
<li style="color: #555753;">✓ Sanitize string 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\OptionsGenericSupportCommentsMatchTest">Options Generic Support Comments Match (Vipgoci\Tests\Unit\OptionsGenericSupportCommentsMatch)</h2>
<ul>
<li style="color: #555753;">✓ Option generic support comments match</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\OptionsGenericSupportCommentsProcessTest">Options Generic Support Comments Process (Vipgoci\Tests\Unit\OptionsGenericSupportCommentsProcess)</h2>
<ul>
<li style="color: #555753;">✓ Option generic support comment process boolean</li>
<li style="color: #555753;">✓ Option generic support comment process string string not lower</li>
<li style="color: #555753;">✓ Option generic support comment process string string lower</li>
<li style="color: #555753;">✓ Option generic support comment process array not lower</li>
<li style="color: #555753;">✓ Option generic support comment process array lower</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\OptionsGetStartingWithTest">Options Get Starting With (Vipgoci\Tests\Unit\OptionsGetStartingWith)</h2>
<ul>
<li style="color: #555753;">✓ Options starting with</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\OptionsSensitiveCleanTest">Options Sensitive Clean (Vipgoci\Tests\Unit\OptionsSensitiveClean)</h2>
<ul>
<li style="color: #555753;">✓ Sensitive clean 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\OptionsSkipFolderHandleTest">Options Skip Folder Handle (Vipgoci\Tests\Unit\OptionsSkipFolderHandle)</h2>
<ul>
<li style="color: #555753;">✓ Option skip folder handle 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\PhpcsScanIssuesFilterDuplicateTest">Phpcs Scan Issues Filter Duplicate (Vipgoci\Tests\Unit\PhpcsScanIssuesFilterDuplicate)</h2>
<ul>
<li style="color: #555753;">✓ Filter duplicate 1</li>
<li style="color: #555753;">✓ Filter duplicate 2</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\PhpcsScanIssuesFilterIrrellevantTest">Phpcs Scan Issues Filter Irrellevant (Vipgoci\Tests\Unit\PhpcsScanIssuesFilterIrrellevant)</h2>
<ul>
<li style="color: #555753;">✓ Do scan issues filter 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\StatsRunTimeMeasureTest">Stats Run Time Measure (Vipgoci\Tests\Unit\StatsRunTimeMeasure)</h2>
<ul>
<li style="color: #555753;">✓ Runtime measure 1</li>
<li style="color: #555753;">✓ Runtime measure 2</li>
<li style="color: #555753;">✓ Runtime measure 3</li>
<li style="color: #555753;">✓ Runtime measure 4</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\StatsStatsInitTest">Stats Stats Init (Vipgoci\Tests\Unit\StatsStatsInit)</h2>
<ul>
<li style="color: #555753;">✓ Stats init</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\SysExitTest">Sys Exit (Vipgoci\Tests\Unit\SysExit)</h2>
<ul>
<li style="color: #555753;">✓ Sys exit 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\VipgociExitStatusTest">Vipgoci Exit Status (Vipgoci\Tests\Unit\VipgociExitStatus)</h2>
<ul>
<li style="color: #555753;">✓ Exit status 1</li>
<li style="color: #555753;">✓ Exit status 2</li>
<li style="color: #555753;">✓ Exit status will return 250 when skipped files is found</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\VipgociOptionsArrayHandleTest">Vipgoci Options Array Handle (Vipgoci\Tests\Unit\VipgociOptionsArrayHandle)</h2>
<ul>
<li style="color: #555753;">✓ Options array handle 1</li>
<li style="color: #555753;">✓ Options array handle 2</li>
<li style="color: #555753;">✓ Options array handle 3</li>
<li style="color: #555753;">✓ Options array handle 4</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\VipgociOptionsBoolHandleTest">Vipgoci Options Bool Handle (Vipgoci\Tests\Unit\VipgociOptionsBoolHandle)</h2>
<ul>
<li style="color: #555753;">✓ Options bool handle 1</li>
<li style="color: #555753;">✓ Options bool handle 2</li>
<li style="color: #555753;">✓ Options bool handle 3</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\VipgociOptionsIntegerHandleTest">Vipgoci Options Integer Handle (Vipgoci\Tests\Unit\VipgociOptionsIntegerHandle)</h2>
<ul>
<li style="color: #555753;">✓ Options integer handle 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\VipgociOptionsPhpcsRuntimeSetTest">Vipgoci Options Phpcs Runtime Set (Vipgoci\Tests\Unit\VipgociOptionsPhpcsRuntimeSet)</h2>
<ul>
<li style="color: #555753;">✓ Options phpcs runtime set 1</li>
</ul>
<h2 id="Vipgoci\Tests\Unit\VipgociSkipFileTest">Vipgoci Skip File (Vipgoci\Tests\Unit\VipgociSkipFile)</h2>
<ul>
<li style="color: #555753;">✓ Get skipped files will return correct value</li>
<li style="color: #555753;">✓ Get skipped files will return correct value for total 0</li>
<li style="color: #555753;">✓ Set skipped files will set correct values</li>
<li style="color: #555753;">✓ Set p rs implicated skipped files will set correct values</li>
<li style="color: #555753;">✓ Get skipped files message</li>
<li style="color: #555753;">✓ Get skipped files message with number of lines exceeded different than default</li>
<li style="color: #555753;">✓ Get skipped files issue message</li>
<li style="color: #555753;">✓ Vipgoci verify skip file message duplication</li>
<li style="color: #555753;">✓ Get large files from comments</li>
<li style="color: #555753;">✓ Get large files from comments will return empty when comment is not about skipped files</li>
<li style="color: #555753;">✓ Get large files from p r comments</li>
<li style="color: #555753;">✓ Get large files from p r comments when comments are not about skipped files will return empty</li>
</ul>
</body>
</html>
31 changes: 29 additions & 2 deletions github-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,18 @@ function vipgoci_github_pr_review_submit(
'comments' => array(),
);

$pr_reviews_commented = vipgoci_github_pr_reviews_get(
$repo_owner,
$repo_name,
$pr_number,
$github_token,
array(
'login' => 'myself',
'state' => array( 'COMMENTED' )
)
);

$results['skipped-files'][ $pr_number ] = vipgo_skip_file_check_previous_pr_comments( $results['skipped-files'][ $pr_number ], $pr_reviews_commented );

/*
* For each issue reported, format
Expand Down Expand Up @@ -2806,9 +2818,24 @@ function vipgoci_github_pr_review_submit(
}

/**
* Format skipped files message if it validation has issues
* Check if there're previous existent comments about the same files
*/
$pr_reviews_commented = vipgoci_github_pr_reviews_get(
$repo_owner,
$repo_name,
$pr_number,
$github_token,
array(
'login' => 'myself',
'state' => array( 'COMMENTED' )
)
);
$results['skipped-files'][ $pr_number ] = vipgo_skip_file_check_previous_pr_comments( $results['skipped-files'][ $pr_number ], $pr_reviews_commented );

/**
* Format skipped files message if the validation has issues
*/
if ( ! empty( $results[ VIPGOCI_SKIPPED_FILES ][ $pr_number ]['issues'] ) ) {
if ( 0 === $results[ VIPGOCI_SKIPPED_FILES ][ $pr_number ]['total'] ) {
vipgoci_markdown_comment_add_pagebreak(
$github_postfields['body']
);
Expand Down
26 changes: 13 additions & 13 deletions skip-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ function vipgoci_set_prs_implicated_skipped_files(

/**
* @param array $skipped
* @param int $skip_large_files_limit
* @param int $skip_files_lines_limit
*
* @return string
*/
function vipgoci_get_skipped_files_message( array $skipped, int $skip_large_files_limit ): string {
function vipgoci_get_skipped_files_message( array $skipped, int $skip_files_lines_limit ): string {
$body = PHP_EOL . '**' . VIPGOCI_SKIPPED_FILES . '**' . PHP_EOL . PHP_EOL;
foreach ( $skipped['issues'] as $issue => $file ) {
$body .= vipgoci_get_skipped_files_issue_message(
$skipped['issues'][ $issue ],
$issue,
$skip_large_files_limit
$skip_files_lines_limit
);
}

Expand Down Expand Up @@ -105,17 +105,17 @@ function vipgoci_get_skipped_files_issue_message(
* when there are previous comments
* preventing duplicated comments
*
* @return array
* @return array $pr_issues_result
*/
function vipgo_skip_file_check_previous_pr_comments( array $pr_issues_results = [], array $comments = [] ): array {
/**
* If there is no previous comments in this PR, return
*/
if ( 0 === count( $comments ) ) {
if ( 0 === count( $comments ) || 0 === $pr_issues_results['total'] ) {
return $pr_issues_results;
}

$large_files = vipgo_get_large_files_from_pr_comments( $comments );
$skipped_files = vipgo_get_skipped_files_from_pr_comments( $comments );
$result = [ 'issues' => [ 'max-lines' => [] ], 'total' => 0 ];

/**
Expand All @@ -124,7 +124,7 @@ function vipgo_skip_file_check_previous_pr_comments( array $pr_issues_results =
* If so, prevent a new comment about the same file
*/
foreach ( $pr_issues_results['issues']['max-lines'] as $file ) {
if ( in_array( $file, $large_files, true ) ) {
if ( in_array( $file, $skipped_files, true ) ) {
continue;
}

Expand All @@ -143,8 +143,8 @@ function vipgo_skip_file_check_previous_pr_comments( array $pr_issues_results =
* @return array
* @todo add unit tests
*/
function vipgo_get_large_files_from_pr_comments( array $comments ): array {
$large_files = [];
function vipgo_get_skipped_files_from_pr_comments( array $comments ): array {
$skipped_files = [];

foreach ( $comments as $comment ) {
/**
Expand All @@ -154,19 +154,19 @@ function vipgo_get_large_files_from_pr_comments( array $comments ): array {
if ( false === strpos( $comment->body, 'skipped-files' ) ) {
continue;
}
$files = vipgo_get_large_files_from_comment( $comment );
$large_files = array_merge( $large_files, $files );
$files = vipgo_get_skipped_files_from_comment( $comment );
$skipped_files = array_merge( $skipped_files, $files );
}

return $large_files;
return $skipped_files;
}

/**
* @param $comment
*
* @return string[]
*/
function vipgo_get_large_files_from_comment( $comment ): array {
function vipgo_get_skipped_files_from_comment( $comment ): array {
$prefix = '):';
$suffix = strlen( PHP_EOL . PHP_EOL . VIPGOCI_VALIDATION_MAXIMUM_DETAIL_MSG );

Expand Down
Loading

0 comments on commit 18e2a10

Please sign in to comment.