Changeset 9340
- Timestamp:
- 12/13/2019 05:02:31 AM (5 years ago)
- Location:
- sites/trunk
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/style/trac/wp-trac.css
r9058 r9340 2293 2293 } 2294 2294 } 2295 #github-prs .hidden { 2296 display: none; 2297 } 2298 #github-prs ul.pull-requests { 2299 border: 1px solid #ccc; 2300 padding: 0 1em; 2301 position: relative; 2302 } 2303 #github-prs ul.pull-requests li { 2304 align-items: center; 2305 display: flex; 2306 justify-content: space-between; 2307 padding: 0; 2308 } 2309 #github-prs ul.pull-requests li div { 2310 margin: 0.5em 0; 2311 } 2312 #github-prs .button { 2313 color: black; 2314 } 2315 #github-prs ins { 2316 color: green; 2317 text-decoration: none 2318 } 2319 #github-prs del { 2320 color: red; 2321 text-decoration: none; 2322 } 2323 @media screen and (max-width: 782px) { 2324 #github-prs .button { 2325 line-height: 20px; 2326 margin-right: 0.3em; 2327 } 2328 #github-prs li { 2329 display: block; 2330 } 2331 } -
sites/trunk/wordpress.org/public_html/style/trac/wp-trac.js
r9304 r9340 85 85 wpTrac.linkMentions(); 86 86 wpTrac.linkGutenbergIssues(); 87 wpTrac.githubPRs.init(); 87 88 88 89 if ( ! $body.hasClass( 'plugins' ) ) { … … 1542 1543 }()), 1543 1544 1545 githubPRs: (function() { 1546 var apiEndpoint = 'https://api.wordpress.org/dotorg/trac/pr/', 1547 authenticated = !! ( wpTracCurrentUser && wpTracCurrentUser !== "anonymous" ), 1548 trac = false, ticket = 0, 1549 container; 1550 1551 function init() { 1552 // TODO: If this is added to other Trac's, expand this.. 1553 if ( $body.hasClass( 'core' ) ) { 1554 trac = 'core'; 1555 } 1556 1557 // This seems to be the easiest place to find the current Ticket ID.. 1558 var canonical = $( 'link[rel="canonical"]' ).prop( 'href' ); 1559 if ( canonical ) { 1560 ticket = canonical.match( /\/ticket\/(\d+)$/ )[1]; 1561 } 1562 1563 if ( ! trac || ! ticket ) { 1564 return; 1565 } 1566 1567 // Add the section immediately. 1568 renderAddSection(); 1569 1570 if ( authenticated ) { 1571 // Fetch the PRs immediately for authenciated users. 1572 fetchPRs(); 1573 1574 // ..and expand the section by default. 1575 container.toggleClass( 'collapsed', false ); 1576 } else { 1577 // Not authenticated? Fetch PRs upon expanding. 1578 container.find( 'h3 a' ).one( 'click', function() { 1579 fetchPRs(); 1580 }); 1581 } 1582 } 1583 1584 function fetchPRs() { 1585 $.ajax( 1586 apiEndpoint 1587 + '?trac=' + trac 1588 + '&ticket=' + ticket 1589 + ( authenticated ? '&authenticated=1' : '' ) 1590 ).success( function( data ) { 1591 // Update the number 1592 container.find( 'h3 .trac-count' ).removeClass( 'hidden' ).find( 'span' ).text( data.length ); 1593 1594 var prContainer = container.find( '.pull-requests' ); 1595 if ( data.length ) { 1596 // Remove the placeholder. 1597 prContainer.find( '.loading' ).remove(); 1598 1599 // Render the PRs 1600 for ( var i in data ) { 1601 renderPR( prContainer, data[i] ); 1602 } 1603 } else { 1604 // Change the loading placeholder 1605 prContainer.find( '.loading' ).text( 'No linked PRs found.' ); 1606 } 1607 }); 1608 } 1609 1610 function renderAddSection() { 1611 // Add the Pull Requests section. 1612 $( '#attachments' ).append( 1613 '<div id="github-prs" class="collapsed">' + 1614 '<h3 class="foldable"><a id="section-pr" href="#section-pr">Pull requests <span class="trac-count hidden">(<span></span>)</span></a></h3>' + 1615 '<ul class="pull-requests">' + 1616 '<li class="loading">Loading...</li>' + 1617 '</ul>' + 1618 '</div>' 1619 ); 1620 // keep this for later. 1621 container = $( '#github-prs' ); 1622 1623 // Make the section collapse. 1624 container.find( '#section-pr' ).on( 'click', function() { 1625 var $div = $( this.parentNode.parentNode ).toggleClass( 'collapsed' ); 1626 return ! $div.hasClass( 'collapsed' ); 1627 } ); 1628 } 1629 1630 // Logic to determine what the PRs status is 1631 function prStatus( data ) { 1632 // Closed? 1633 if ( data.closed_at ) { 1634 if ( data.mergeable_state == 'clean' ) { 1635 return '✅ Closed'; 1636 } else { 1637 return '❌ Closed' 1638 } 1639 } 1640 1641 // Merge State then 1642 switch ( data.mergeable_state ) { 1643 case 'draft': 1644 return 'Work in progress'; 1645 case 'clean': 1646 return '✅ All checks pass'; 1647 case 'dirty': 1648 return '❌ Merge conflicts'; 1649 case 'unstable': 1650 return '❌ Failing tests'; 1651 } 1652 } 1653 1654 function renderPR( container, data ) { 1655 // Not the nicest, but it works and escapes things properly if given correct inputs. 1656 var htmlElement = function( element, attributes, text = '' ) { 1657 return $( '<p>' ).append( 1658 $( '<' + element + '/>', attributes ).text( text ) 1659 ).html(); 1660 } 1661 1662 container.append( 1663 '<li>' + 1664 '<div>' + 1665 htmlElement( 1666 'a', 1667 { href: data.changes.html_url, title: data.title }, 1668 '#' + data.number + ' ' + 1669 ( data.title.length > 23 ? data.title.substr( 0, 20 ) + '...' : data.title ) 1670 ) + 1671 ' by ' + 1672 htmlElement( 'a', { href: data.user.url }, '@' + data.user.name ) + 1673 '</div>' + 1674 '<div>' + 1675 prStatus( data ) + 1676 '</div>' + 1677 '<div>' + 1678 htmlElement( 'ins', {}, '+' + data.changes.additions ) + 1679 ' ' + 1680 htmlElement( 'del', {}, '-' + data.changes.deletions ) + 1681 '</div>' + 1682 '<div>' + 1683 htmlElement( 'a', { href: data.changes.patch_url, class: 'button' }, 'View patch' ) + 1684 ' ' + 1685 htmlElement( 'a', { href: data.changes.html_url, class: 'button' }, 'View PR' ) + 1686 '</div>' + 1687 '</li>' 1688 ); 1689 } 1690 1691 return { 1692 init: init 1693 }; 1694 }()), 1695 1544 1696 patchTracFor122Changes: function() { 1545 1697 console.log( "wp-trac: Applying compat patches for Trac 1.2.2" );
Note: See TracChangeset
for help on using the changeset viewer.