diff --git a/build/requirements.html b/build/requirements.html new file mode 100644 index 000000000..daed6bc4b --- /dev/null +++ b/build/requirements.html @@ -0,0 +1,216 @@ + + + + + Test Documentation + + + +

A00 Irc Api Alert Queue (Vipgoci\Tests\Unit\A00IrcApiAlertQueue)

+ +

A00 Irc Api Alert Queue Unique (Vipgoci\Tests\Unit\A00IrcApiAlertQueueUnique)

+ +

A00 Stats Counters (Vipgoci\Tests\Unit\A00StatsCounters)

+ +

Git Hub Api Curl Headers (Vipgoci\Tests\Unit\GitHubApiCurlHeaders)

+ +

Git Hub Oauth1 Headers Get (Vipgoci\Tests\Unit\GitHubOauth1HeadersGet)

+ +

Git Hub Oauth Signature Get Hmac Sha1 (Vipgoci\Tests\Unit\GitHubOauthSignatureGetHmacSha1)

+ +

Misc Blame Filter Comments (Vipgoci\Tests\Unit\MiscBlameFilterComments)

+ +

Misc Cache (Vipgoci\Tests\Unit\MiscCache)

+ +

Misc Cached Indication Str (Vipgoci\Tests\Unit\MiscCachedIndicationStr)

+ +

Misc Convert String To Type (Vipgoci\Tests\Unit\MiscConvertStringToType)

+ +

Misc File Extension (Vipgoci\Tests\Unit\MiscFileExtension)

+ +

Misc Filter File Path (Vipgoci\Tests\Unit\MiscFilterFilePath)

+ +

Misc Find Fields In Array (Vipgoci\Tests\Unit\MiscFindFieldsInArray)

+ +

Misc Git Hub Comment Match (Vipgoci\Tests\Unit\MiscGitHubCommentMatch)

+ +

Misc Git Hub Emojis (Vipgoci\Tests\Unit\MiscGitHubEmojis)

+ +

Misc Git Hub Pr Remove Drafts (Vipgoci\Tests\Unit\MiscGitHubPrRemoveDrafts)

+ +

Misc Markdown Comment Add Pagebreak (Vipgoci\Tests\Unit\MiscMarkdownCommentAddPagebreak)

+ +

Misc Round Array Items (Vipgoci\Tests\Unit\MiscRoundArrayItems)

+ +

Misc Sanitize Path Prefix (Vipgoci\Tests\Unit\MiscSanitizePathPrefix)

+ +

Misc Sanitize String (Vipgoci\Tests\Unit\MiscSanitizeString)

+ +

Options Generic Support Comments Match (Vipgoci\Tests\Unit\OptionsGenericSupportCommentsMatch)

+ +

Options Generic Support Comments Process (Vipgoci\Tests\Unit\OptionsGenericSupportCommentsProcess)

+ +

Options Get Starting With (Vipgoci\Tests\Unit\OptionsGetStartingWith)

+ +

Options Sensitive Clean (Vipgoci\Tests\Unit\OptionsSensitiveClean)

+ +

Options Skip Folder Handle (Vipgoci\Tests\Unit\OptionsSkipFolderHandle)

+ +

Phpcs Scan Issues Filter Duplicate (Vipgoci\Tests\Unit\PhpcsScanIssuesFilterDuplicate)

+ +

Phpcs Scan Issues Filter Irrellevant (Vipgoci\Tests\Unit\PhpcsScanIssuesFilterIrrellevant)

+ +

Stats Run Time Measure (Vipgoci\Tests\Unit\StatsRunTimeMeasure)

+ +

Stats Stats Init (Vipgoci\Tests\Unit\StatsStatsInit)

+ +

Sys Exit (Vipgoci\Tests\Unit\SysExit)

+ +

Vipgoci Exit Status (Vipgoci\Tests\Unit\VipgociExitStatus)

+ +

Vipgoci Options Array Handle (Vipgoci\Tests\Unit\VipgociOptionsArrayHandle)

+ +

Vipgoci Options Bool Handle (Vipgoci\Tests\Unit\VipgociOptionsBoolHandle)

+ +

Vipgoci Options Integer Handle (Vipgoci\Tests\Unit\VipgociOptionsIntegerHandle)

+ +

Vipgoci Options Phpcs Runtime Set (Vipgoci\Tests\Unit\VipgociOptionsPhpcsRuntimeSet)

+ +

Vipgoci Skip File (Vipgoci\Tests\Unit\VipgociSkipFile)

+ + + \ No newline at end of file diff --git a/github-api.php b/github-api.php index 40eb79e29..2f1d7ab19 100644 --- a/github-api.php +++ b/github-api.php @@ -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 @@ -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'] ); diff --git a/skip-file.php b/skip-file.php index f48dc6c2c..ff8f179e4 100644 --- a/skip-file.php +++ b/skip-file.php @@ -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 ); } @@ -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 ]; /** @@ -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; } @@ -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 ) { /** @@ -154,11 +154,11 @@ 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; } /** @@ -166,7 +166,7 @@ function vipgo_get_large_files_from_pr_comments( array $comments ): array { * * @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 ); diff --git a/tests/unit/VipgociSkipFileTest.php b/tests/unit/VipgociSkipFileTest.php index dc18484a9..daf153a53 100644 --- a/tests/unit/VipgociSkipFileTest.php +++ b/tests/unit/VipgociSkipFileTest.php @@ -270,12 +270,36 @@ public function testVipgociVerifySkipFileMessageDuplication(): void { } /** - * @covers ::vipgo_get_large_files_from_comment + * @covers ::vipgo_skip_file_check_previous_pr_comments + * @dataProvider vipgociVerifySkipFileMessageDuplicationWillReturnOfCommentsOreIssuesResultsAreZeroProvider + */ + public function testVipgociVerifySkipFileMessageDuplicationWillReturnOfCommentsOreIssuesResultsAreZero( array $skipped_files_result, array $comments ): void { + $result = vipgo_skip_file_check_previous_pr_comments( + $skipped_files_result, + $comments, + ); + + $this->assertSame( + $result, + $skipped_files_result, + ); + } + + public function vipgociVerifySkipFileMessageDuplicationWillReturnOfCommentsOreIssuesResultsAreZeroProvider(): array { + return [ + [ [ 'total' => 0 ], [ 'any' ] ], + [ [ 'total' => 2 ], [] ], + [ [ 'issues' => [ 'max-lines' => [ 'test.php' ] ], 'total' => 1 ], [ $this->getCommentMock() ] ], + ]; + } + + /** + * @covers ::vipgo_get_skipped_files_from_comment */ public function testGetLargeFilesFromComments(): void { $skippedFileCommentMock = $this->getSkippedFilesCommentMock(); - $result = vipgo_get_large_files_from_comment( $skippedFileCommentMock ); + $result = vipgo_get_skipped_files_from_comment( $skippedFileCommentMock ); $expected = [ 'GoogleAtom.php', 'MySuccessClass.php', @@ -292,12 +316,12 @@ public function testGetLargeFilesFromComments(): void { } /** - * @covers ::vipgo_get_large_files_from_comment + * @covers ::vipgo_get_skipped_files_from_comment */ public function testGetLargeFilesFromCommentsWillReturnEmptyWhenCommentIsNotAboutSkippedFiles(): void { $commentMock = $this->getCommentMock(); - $result = vipgo_get_large_files_from_comment( $commentMock ); + $result = vipgo_get_skipped_files_from_comment( $commentMock ); $expected = array(); $this->assertSame( @@ -307,12 +331,12 @@ public function testGetLargeFilesFromCommentsWillReturnEmptyWhenCommentIsNotAbou } /** - * @covers ::vipgo_get_large_files_from_pr_comments + * @covers ::vipgo_get_skipped_files_from_pr_comments */ public function testGetLargeFilesFromPRComments(): void { $commentsSkippedFilesMock = $this->getSkippedFilesCommentsMock(); - $result = vipgo_get_large_files_from_pr_comments( $commentsSkippedFilesMock ); + $result = vipgo_get_skipped_files_from_pr_comments( $commentsSkippedFilesMock ); $expected = [ 'GoogleAtom.php', 'MySuccessClass.php', @@ -329,12 +353,12 @@ public function testGetLargeFilesFromPRComments(): void { } /** - * @covers ::vipgo_get_large_files_from_pr_comments + * @covers ::vipgo_get_skipped_files_from_pr_comments */ public function testGetLargeFilesFromPRCommentsWhenCommentsAreNotAboutSkippedFilesWillReturnEmpty(): void { $commentsMock = $this->getCommentMock(); - $result = vipgo_get_large_files_from_pr_comments( [ $commentsMock ] ); + $result = vipgo_get_skipped_files_from_pr_comments( [ $commentsMock ] ); $expected = array(); $this->assertSame(