@@ -41,10 +41,33 @@ function getData() {
41
41
}
42
42
43
43
$ data = json_decode ( $ data );
44
+ $ data = normalizeData ( $ data );
44
45
$ data ->repo = $ repo ;
45
46
return $ data ;
46
47
}
47
48
49
+ // The web hook used to only log the audit result, not the full data.
50
+ // So we normalize old data to the new format
51
+ function normalizeData ( $ data ) {
52
+
53
+ // Since we didn't store error info before, errors got logged as undefined,
54
+ // which come across as null in PHP
55
+ if ( is_null ( $ data ) ) {
56
+ return (object ) array (
57
+ 'error ' => 'Unknown error '
58
+ );
59
+ }
60
+
61
+ // If we're missing the fully structured data, just move the audit result
62
+ // to the proper location
63
+ if ( !empty ( $ data ->commits ) ) {
64
+ return (object ) array ( 'data ' => $ data );
65
+ }
66
+
67
+ // We have proper data, just return it as is
68
+ return $ data ;
69
+ }
70
+
48
71
function validateData ( $ data ) {
49
72
if ( is_null ( $ data ) ) {
50
73
global $ wp_query ;
@@ -59,21 +82,34 @@ function getProcessedPost( $data ) {
59
82
the_post ();
60
83
$ content = get_the_content ();
61
84
62
- if ( count ( $ data ->neglectedAuthors ) ) {
63
- $ content = preg_replace ( "/<!-- ifsuccess -->.*<!-- endifsuccess -->/s " , '' , $ content );
64
- $ content = preg_replace ( "/<!-- neglected-authors -->/ " , neglectedAuthors ( $ data ), $ content );
85
+ if ( !empty ( $ data ->error ) ) {
86
+ $ content = preg_replace ( '/<!-- ifsuccess -->.*<!-- endifsuccess -->/s ' , '' , $ content );
87
+ $ content = preg_replace ( '/<!-- iffailure -->.*<!-- endiffailure -->/s ' , '' , $ content );
88
+ $ content = preg_replace (
89
+ '/<!-- error -->/ ' ,
90
+ '<pre> ' . htmlspecialchars ( $ data ->error ) . '</pre> ' ,
91
+ $ content
92
+ );
93
+
94
+ return $ content ;
95
+ }
96
+
97
+ if ( count ( $ data ->data ->neglectedAuthors ) ) {
98
+ $ content = preg_replace ( '/<!-- ifsuccess -->.*<!-- endifsuccess -->/s ' , '' , $ content );
99
+ $ content = preg_replace ( '/<!-- neglected-authors -->/ ' , neglectedAuthors ( $ data ), $ content );
65
100
} else {
66
- $ content = preg_replace ( " /<!-- iferror -->.*<!-- endiferror -->/s " , '' , $ content );
101
+ $ content = preg_replace ( ' /<!-- iffailure -->.*<!-- endiffailure -->/s ' , '' , $ content );
67
102
}
68
103
69
- $ content = preg_replace ( "/<!-- commit-log -->/ " , commitLog ( $ data ), $ content );
104
+ $ content = preg_replace ( '/<!-- iferror -->.*<!-- endiferror -->/s ' , '' , $ content );
105
+ $ content = preg_replace ( '/<!-- commit-log -->/ ' , commitLog ( $ data ), $ content );
70
106
71
107
return $ content ;
72
108
}
73
109
74
110
function neglectedAuthors ( $ data ) {
75
111
$ html = "<ul> \n" ;
76
- foreach ( $ data ->neglectedAuthors as $ author ) {
112
+ foreach ( $ data ->data -> neglectedAuthors as $ author ) {
77
113
$ html .= "<li> " . htmlspecialchars ( "$ author ->name < $ author ->email > " ) . "</li> \n" ;
78
114
}
79
115
$ html .= "</ul> \n" ;
@@ -84,7 +120,7 @@ function commitLog( $data ) {
84
120
$ commitPrefix = "http://github.com/jquery/ $ data ->repo /commit/ " ;
85
121
86
122
$ html = "<dl> \n" ;
87
- foreach ( $ data ->commits as $ commit ) {
123
+ foreach ( $ data ->data -> commits as $ commit ) {
88
124
$ html .= "<dt><a href=' $ commitPrefix$ commit ->hash '> $ commit ->hash </a></dt> \n" ;
89
125
$ html .= "<dd> " . htmlspecialchars ( "$ commit ->name < $ commit ->email > " ) . "</dd \n" ;
90
126
}
0 commit comments