Changeset 9373
- Timestamp:
- 12/20/2019 08:38:53 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/webhook.php
r9372 r9373 103 103 break; 104 104 105 case 'issue_comment': 106 // This is a singular comment on a PR or issue. 107 // NOT a code review comment. 108 109 $is_edit = isset( $payload->action ) && 'edited' === $payload->action; 110 if ( $is_edit ) { 111 // UNIQUE constraint failed: ticket_change.ticket, ticket_change.time, ticket_change.field 112 die( 'UNSUPPORTED - EDIT' ); 113 } 114 115 // Make sure it's a PR comment.. 116 if ( empty( $payload->issue->pull_request ) ) { 117 die( 'UNSUPPORTED - Only PR comments supported.' ); 118 } 119 120 $pr_repo = $payload->repository->full_name; 121 $pr_number = $payload->issue->number; 122 123 // Find the tickets that this PR is attached to. 124 $tickets = $wpdb->get_results( $wpdb->prepare( 125 "SELECT trac, ticket FROM trac_github_prs WHERE repo = %s AND pr = %d", 126 $pr_repo, 127 $pr_number 128 ) ); 129 if ( ! $tickets ) { 130 die( 'PR Not linked to any tickets' ); 131 } 132 133 $comment_template = "{{{#!comment\n%s\n}}}\n[%s %s] commented on [%s %s]:\n\n%s"; 134 $comment_author = find_wporg_user_by_github( $payload->comment->user->login ); 135 $comment_time = new \DateTime( $payload->comment->created_at ); 136 137 $comment_body = sprintf( 138 $comment_template, 139 $payload->comment->id, 140 $payload->comment->user->html_url, 141 $payload->comment->user->login, 142 $payload->comment->html_url, 143 'PR #' . $payload->issue->number, 144 $payload->comment->body 145 ); 146 147 foreach ( $tickets as $t ) { 148 $trac = get_trac_instance( $t->trac ); 149 150 if ( ! $is_edit ) { 151 $trac->update( 152 $t->ticket, $comment_body, 153 [], false, 154 $comment_author, 155 $comment_time 156 ); 157 } else { 158 // TODO: Need to edit.. 159 // use /wpapi endpoint for that. 160 } 161 162 } 163 164 die( 'OK' ); 165 105 166 case 'pull_request_review': 167 // This is a Pull Request Review. 168 // It's comprised of one or more comments, which are related to a users "review" 169 // The comment(s) in this review may actually be a response to another review or response to a review in response to a review, etc. 170 171 die( 'N/A' ); 106 172 case 'pull_request_review_comment': 107 die( 'N/A' ); 173 // This is a comment within a Pull Request Review, but sent before the review is published. 174 175 die( 'Not Needed?' ); 176 108 177 }
Note: See TracChangeset
for help on using the changeset viewer.