forked from Automattic/vip-go-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-reports.php
99 lines (91 loc) · 2.33 KB
/
lint-reports.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* PHP lint reporting logic for vip-go-ci.
*
* @package Automattic/vip-go-ci
*/
declare(strict_types=1);
/**
* Returns beginning of a PHP lint report comment.
*
* @param string $repo_owner Repository owner.
* @param string $repo_name Repository name.
* @param string $commit_id Current commit-ID.
* @param string $name_to_use Name to use in reports to identify the bot.
*
* @return string Beginning of comment.
*/
function vipgoci_lint_report_comment_start(
string $repo_owner,
string $repo_name,
string $commit_id,
string $name_to_use
) :string {
$view_code_url =
VIPGOCI_GITHUB_WEB_BASE_URL . '/' .
rawurlencode( $repo_owner ) . '/' .
rawurlencode( $repo_name ) . '/' .
'tree/' .
rawurlencode( $commit_id );
$comment_start =
'# ' . VIPGOCI_LINT_ERROR_STR . PHP_EOL .
sprintf(
VIPGOCI_LINT_REPORT_START,
vipgoci_output_html_escape( $name_to_use ),
vipgoci_output_html_escape( $commit_id ),
$view_code_url
) .
"\n\r";
vipgoci_markdown_comment_add_pagebreak(
$comment_start
);
return $comment_start;
}
/**
* Formats PHP lint results for submission to pull request.
*
* @param string $repo_owner Repository owner.
* @param string $repo_name Repository name.
* @param string $commit_id Commit-ID of current commit.
* @param string $file_name Name of file which result belongs to.
* @param int $file_line Line number in file which result belongs to.
* @param string $issue_level Issue level; error, warning or info.
* @param string $issue_message Details of issue.
*
* @return string Formatted result.
*/
function vipgoci_lint_report_comment_format_result(
string $repo_owner,
string $repo_name,
string $commit_id,
string $file_name,
int $file_line,
string $issue_level,
string $issue_message
) :string {
return '**' .
// Add level (error, warning).
vipgoci_output_html_escape(
ucfirst(
strtolower( $issue_level )
)
) .
'**' .
': ' .
// Then the message.
str_replace(
'\'',
'`',
$issue_message // Is escaped lint-scan.php.
) .
"\n\r\n\r" .
// And finally an URL to the issue.
VIPGOCI_GITHUB_WEB_BASE_URL . '/' .
rawurlencode( $repo_owner ) . '/' .
rawurlencode( $repo_name ) . '/' .
'blob/' .
rawurlencode( $commit_id ) . '/' .
rawurlencode( $file_name ) . '#L' .
rawurlencode( (string) $file_line ) .
"\n\r";
}