Changeset 11544
- Timestamp:
- 02/10/2022 09:38:45 AM (3 years ago)
- Location:
- sites/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/functions.php
r11255 r11544 103 103 * Find a WordPress.org user by a Github login. 104 104 */ 105 function find_wporg_user_by_github( $github_user ) {105 function find_wporg_user_by_github( $github_user, $what = 'user_login' ) { 106 106 global $wpdb; 107 107 108 if ( ! in_array( $what, [ 'ID', 'user_login' ], true ) ) { 109 return false; 110 } 111 108 112 return $wpdb->get_var( $wpdb->prepare( 109 "SELECT u. user_login113 "SELECT u.{$what} 110 114 FROM wporg_github_users g 111 115 JOIN {$wpdb->users} u ON g.user_id = u.ID -
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/index.php
r11099 r11544 7 7 $trac = preg_replace( '![^a-z]!', '', $_GET['trac'] ?? '' ); 8 8 $ticket = intval( $_GET['ticket'] ?? 0 ); 9 $author = wp_unslash( $_GET['author'] ?? '' ); 9 10 $authenticated = ! empty( $_GET['authenticated'] ); // Longer caches for logged out requests. 10 11 11 if ( empty( $trac ) || empty( $ticket ) ) { 12 header( 'Content-Type: application/json' ); 13 header( 'Access-Control-Allow-Origin: *' ); 14 15 if ( empty( $trac ) || ( empty( $ticket ) && empty( $author ) ) ) { 12 16 header( 'HTTP/1.0 400 Bad Request' ); 13 header( 'Content-Type: application/json' ); 14 die( '{"error":"Ticket number is invalid."}' ); 17 die( '{"error":"Trac, Ticket number, or Author is invalid."}' ); 18 } 19 20 // Type one: Return PRs by Author. 21 if ( $author ) { 22 header( 'Cache-Control: max-age=' . HOUR_IN_SECONDS ); 23 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s \G\M\T', time() + HOUR_IN_SECONDS ) ); 24 25 $user_id = get_user_by( 'slug', $author )->ID ?? 0; 26 27 $tickets = $wpdb->get_col( $wpdb->prepare( 28 "SELECT `ticket` 29 FROM `trac_github_prs` 30 WHERE trac = %s AND author = %d", 31 $trac, 32 $user_id 33 ) ); 34 35 echo wp_json_encode( $tickets ); 36 die(); 15 37 } 16 38 17 39 // Fetch any linked PRs 18 40 $prs = $wpdb->get_results( $wpdb->prepare( 19 "SELECT `repo`, `pr`, `data`, `last_checked` 41 "SELECT `repo`, `pr`, `data`, `last_checked`, `author` 20 42 FROM `trac_github_prs` 21 43 WHERE trac = %s AND ticket = %s", … … 65 87 unset( $data->data->trac_ticket ); 66 88 89 // Check if we now have an author for this PR, the author may link their account after creating the PR. 90 if ( ! $data->author ) { 91 $data->author = (int) find_wporg_user_by_github( $pr_data->user->name, 'ID' ); 92 } 93 67 94 $wpdb->update( 68 95 'trac_github_prs', … … 70 97 'data' => json_encode( $pr_data ), 71 98 'last_checked' => gmdate( 'Y-m-d H:i:s' ), 99 'author' => $data->author, 72 100 ], 73 101 [ … … 98 126 header( 'Cache-Control: max-age=' . $expiry ); 99 127 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s \G\M\T', time() + $expiry ) ); 100 header( 'Content-Type: application/json' );101 header( 'Access-Control-Allow-Origin: *' );102 128 103 129 // Only return the actual PR data needed -
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/webhook.php
r11099 r11544 81 81 // Step 3. If not in DB, or $pr_data->trac_ticket isn't yet in the DB, add a new row of it. 82 82 if ( $pr_data->trac_ticket && ( ! $existing_refs || ! $matched_existing_ref ) ) { 83 84 $user_id = (int) find_wporg_user_by_github( $pr_data->user->name, 'ID' ); 85 83 86 $wpdb->insert( 84 87 'trac_github_prs', … … 91 94 'pr' => $pr_number, 92 95 'data' => json_encode( $_pr_data_no_ticket ), 96 'author' => $user_id, 93 97 ] 94 98 ); -
sites/trunk/trac.wordpress.org/templates/site.html
r11540 r11544 5 5 6 6 <?python 7 scripts_version = '16 1'7 scripts_version = '162' 8 8 project_slug = req.environ['HTTP_HOST'].split(':')[0].split('.')[0] 9 9 wporg_endpoint = 'https://make.wordpress.org/' + project_slug + '/' -
sites/trunk/trac.wordpress.org/templates/wporg-head.html
r11499 r11544 46 46 .has-text-align-justify{text-align:justify;} 47 47 </style> 48 <link rel="stylesheet" id="wporg-global-header-footer-css" href="https://wordpress.org/wp-content/mu-plugins/pub-sync/blocks/global-header-footer/build/style.css?ver=1643748 587" type="text/css" media="all"/>48 <link rel="stylesheet" id="wporg-global-header-footer-css" href="https://wordpress.org/wp-content/mu-plugins/pub-sync/blocks/global-header-footer/build/style.css?ver=1643748639" type="text/css" media="all"/> 49 49 <link rel="stylesheet" id="mediaelement-css" href="https://wordpress.org/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css?ver=4.2.16" type="text/css" media="all"/> 50 50 <link rel="stylesheet" id="wp-mediaelement-css" href="https://wordpress.org/wp-includes/js/mediaelement/wp-mediaelement.min.css?ver=6.0-alpha-52660" type="text/css" media="all"/> -
sites/trunk/wordpress.org/public_html/style/trac/wp-trac.js
r11540 r11544 1666 1666 } 1667 1667 1668 if ( ! trac ) { 1669 return; 1670 } 1671 1672 // Add ability to include GitHub tickets into a 'my-patches' report. 1673 // "Just" include a variable called '$GITHUBTICKETS' in the Query. 1674 var $warning = $("#warning.system-message:contains('GITHUBTICKETS')"); 1675 if ( $warning.length ) { 1676 renderReportLoadGitHubTickets( $warning ); 1677 } 1678 1668 1679 // This seems to be the easiest place to find the current Ticket ID.. 1669 1680 var canonical = $( 'link[rel="canonical"]' ).prop( 'href' ); … … 1672 1683 } 1673 1684 1674 if ( ! t rac || ! ticket ) {1685 if ( ! ticket ) { 1675 1686 return; 1676 1687 } … … 1733 1744 return ! $div.hasClass( 'collapsed' ); 1734 1745 } ); 1746 } 1747 1748 function renderReportLoadGitHubTickets( $warning ) { 1749 var user = wpTracCurrentUser, 1750 match = document.location.search.match( /USER=([^&]+)/ ); 1751 if ( match ) { 1752 user = match[1]; 1753 } 1754 1755 // Logged out requests without a user context. 1756 if ( 'anonymous' === user ) { 1757 $warning.remove(); 1758 return; 1759 } 1760 1761 $warning.html( 1762 '<strong>Warning:</strong> Tickets with an attached GitHub PRs not included <button>Load PRs</button>' 1763 ); 1764 1765 $warning.on( 'click', function() { 1766 $(this).find('button').prop( 'disabled', 'disabled' ).text( 'Please wait..' ); 1767 1768 $.ajax( 1769 apiEndpoint 1770 + '?trac=' + trac 1771 + '&author=' + user 1772 + ( authenticated ? '&authenticated=1' : '' ) 1773 ).success( function( ticketList ) { 1774 document.location = document.location.toString() + 1775 ( document.location.search ? '&' : '?' ) + 1776 'GITHUBTICKETS=' + ticketList.join(','); 1777 } ); 1778 } ) 1779 1735 1780 } 1736 1781
Note: See TracChangeset
for help on using the changeset viewer.