From 40ea5fe396b91020c6c6e34496757cd64bb75e62 Mon Sep 17 00:00:00 2001 From: Lew Cirne Date: Fri, 15 May 2020 15:51:19 -0600 Subject: [PATCH 1/2] add a pull requests tab --- nerdlets/github-about/contributors.js | 13 ++- nerdlets/github-about/main.js | 28 ++++- nerdlets/github-about/pull-requests.js | 139 +++++++++++++++++++++++++ nerdlets/github-about/styles.scss | 27 +++++ package-lock.json | 7 +- package.json | 1 + 6 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 nerdlets/github-about/pull-requests.js diff --git a/nerdlets/github-about/contributors.js b/nerdlets/github-about/contributors.js index 9bec933..8f52eab 100644 --- a/nerdlets/github-about/contributors.js +++ b/nerdlets/github-about/contributors.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import Github from './github'; +import humanizeDuration from 'humanize-duration'; export default class Contributors extends React.PureComponent { static propTypes = { @@ -135,17 +136,25 @@ export default class Contributors extends React.PureComponent { Name Email Commits - Most Recent + Most Recent {committers.map(committer => { + const duration = + new Date() - new Date(committer.mostRecentCommit); + const durationStr = humanizeDuration(duration, { + largest: 2, + units: ['y', 'mo', 'w', 'd', 'h', 'm'], + round: true + }); + return ( {committer.name} {committer.email} {committer.commitCount} - {committer.mostRecentCommit} + {durationStr} ago ); })} diff --git a/nerdlets/github-about/main.js b/nerdlets/github-about/main.js index 4d7bf63..02a82af 100644 --- a/nerdlets/github-about/main.js +++ b/nerdlets/github-about/main.js @@ -21,6 +21,7 @@ import Setup from './setup'; import RepoPicker from './repo-picker'; import Readme from './readme'; import Contributors from './contributors'; +import PullRequests from './pull-requests'; import Header from './header'; import { formatGithubUrl } from '../shared/utils'; @@ -62,7 +63,17 @@ export default class GithubAbout extends React.PureComponent { }; } - async componentDidMount() { + componentDidMount() { + this.load(); + } + + componentDidUpate({ nerdletUrlState }) { + if (nerdletUrlState.entityGuid !== this.props.nerdletUrlState.entityGuid) { + this.load(); + } + } + + async load() { await this.fetchEntityData(); await this._getGithubUrl(); await this.checkGithubUrl(); @@ -260,6 +271,7 @@ export default class GithubAbout extends React.PureComponent { return 'repository'; } + // return 'pull-requests' return visibleTab || 'readme'; }; @@ -292,6 +304,20 @@ export default class GithubAbout extends React.PureComponent { userToken={userToken} /> + + + 0) { + const error = new Error(`Bad repository url: ${path}`); + this.setState({ error: error.message }); + return; + } + + let pullRequests = null; + try { + pullRequests = await github.get(path); + this.setState({ pullRequests }); + } catch (e) { + const error = + pullRequests && pullRequests.message + ? pullRequests.message + : 'unknown error'; + this.setState({ error }); + console.error(e); // eslint-disable-line no-console + } + } + + render() { + const { error, pullRequests } = this.state; + + if (error) { + return ( + <> +

An error occurred:

+

{error}

+ + ); + } + + if (!pullRequests) { + return 'Loading Pull Requests...'; + } + + return ( +
+

Pull Requests

+ + + + + + + + + {pullRequests.map(pr => ( + + ))} + +
Pull RequestAge
+
+ ); + } +} + +function PullRequest({ html_url, title, created_at }) { + const duration = new Date() - new Date(created_at); + const durationStr = humanizeDuration(duration, { + largest: 2, + units: ['y', 'mo', 'w', 'd', 'h', 'm'], + round: true + }); + + let className = 'pr-green'; + const DAY = 24 * 60 * 60 * 1000; + if (duration > 7 * DAY) className = 'pr-yellow'; + if (duration > 14 * DAY) className = 'pr-red'; + + return ( + + + {title} + + +
+
+ {durationStr} +
+ + + ); +} + +PullRequest.propTypes = { + html_url: PropTypes.string, + title: PropTypes.string, + created_at: PropTypes.string +}; diff --git a/nerdlets/github-about/styles.scss b/nerdlets/github-about/styles.scss index 4548cab..29b02d9 100644 --- a/nerdlets/github-about/styles.scss +++ b/nerdlets/github-about/styles.scss @@ -61,6 +61,29 @@ tr.active { } +.pr { + width: 12px; + height: 12px; + border-radius: 12px; + margin-right: 12px; + margin-top: 1px; + border: 3px solid; +} + +.pr-red { + background-color: #f3d3d7; + border: 3px solid red; +} +.pr-yellow { + background-color: rgb(253, 222, 163); + border-color: orange; +} +.pr-green { + background-color: rgb(168, 243, 168); + border-color: green; +} + + .container { width: 100%; min-height: 100%; @@ -188,4 +211,8 @@ ul[class*=Tabs-navigation] { .gh-access-error-container { padding: 20px 32px 32px; +} + +.right { + text-align: right; } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index b3d777d..bfe25b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nr1-github", - "version": "0.5.1", + "version": "0.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1417,6 +1417,11 @@ "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==", "dev": true }, + "humanize-duration": { + "version": "3.22.0", + "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.22.0.tgz", + "integrity": "sha512-kq2Ncl1E8I7LJtjWhraQS8/LCsdt6fTQ+fwrGJ8dLSNFITW5YQpGWAgPgzjfIErAID7QHv0PA+HZBPfAf6f7IA==" + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index d35e954..348758b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "eslint-fix": "eslint nerdlets/ --fix" }, "dependencies": { + "humanize-duration": "^3.22.0", "is-url": "^1.2.4", "lodash.get": "^4.4.2", "prop-types": "^15.6.2", From b9e94995e6679fefe02a09692b7233c8cce0c1b1 Mon Sep 17 00:00:00 2001 From: Joel Worrall Date: Sat, 16 May 2020 10:36:48 -0400 Subject: [PATCH 2/2] fix: method name correction --- nerdlets/github-about/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nerdlets/github-about/main.js b/nerdlets/github-about/main.js index 02a82af..0e9fc2e 100644 --- a/nerdlets/github-about/main.js +++ b/nerdlets/github-about/main.js @@ -67,7 +67,7 @@ export default class GithubAbout extends React.PureComponent { this.load(); } - componentDidUpate({ nerdletUrlState }) { + componentDidUpdate({ nerdletUrlState }) { if (nerdletUrlState.entityGuid !== this.props.nerdletUrlState.entityGuid) { this.load(); }