Skip to content

Commit 221baa7

Browse files
committed
Move hosted-git-info handling to npm service based on dependency changes
1 parent 7945d91 commit 221baa7

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

services/npm.js

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const LRU = require('lru-cache');
66
const express = require('express');
77
const npmUser = require('@pkgstats/npm-user');
88
const router = express.Router();
9+
const hostedGitInfo = require('hosted-git-info');
910

1011
const Rollbar = require("rollbar");
1112
const rollbar = new Rollbar(process.env.ROLLBAR_ACCESS_TOKEN);
@@ -112,6 +113,20 @@ router.get('/pkg/:pkg/:version?', async (req, res) => {
112113

113114
const response = await fetch(url);
114115
const json = await response.json();
116+
117+
if (json.hasOwnProperty('repository') && json.repository.url) {
118+
try {
119+
const gitInfo = hostedGitInfo.fromUrl(json.repository.url);
120+
if (gitInfo) {
121+
json.repository.url = gitInfo.browse();
122+
}
123+
}
124+
catch (e) {
125+
rollbar.error('Error parsing repository url', e);
126+
console.error('Error parsing repository url', e);
127+
}
128+
}
129+
115130
cache.set(req.url, json);
116131

117132
res.json(json);

src/pages/pkg.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import dayjs from 'dayjs';
88
import relativeTime from 'dayjs/plugin/relativeTime';
99
import gravatar from 'gravatar';
1010
import ReactMarkdown from 'react-markdown/with-html';
11-
import hostedGitInfo from 'hosted-git-info';
1211

1312
import Link from 'components/base/Link';
1413
import CopyButton from 'components/packages/CopyButton';
@@ -152,7 +151,8 @@ class Pkg extends Component {
152151
break;
153152

154153
case 'repository':
155-
linkUrl = `${hostedGitInfo.fromUrl(pkg.repository.url).browse()}?ref=pkgstats.com`;
154+
console.debug(pkg.repository.url);
155+
linkUrl = `${pkg.repository.url}?ref=pkgstats.com`;
156156
linkString = <svg viewBox="0 0 92 92" version="1.1" xmlns="http://www.w3.org/2000/svg"><title>Git</title><g stroke="none"><path d="M90.155,41.965 L50.036,1.847 C47.726,-0.464 43.979,-0.464 41.667,1.847 L33.336,10.179 L43.904,20.747 C46.36,19.917 49.176,20.474 51.133,22.431 C53.102,24.401 53.654,27.241 52.803,29.706 L62.989,39.891 C65.454,39.041 68.295,39.59 70.264,41.562 C73.014,44.311 73.014,48.768 70.264,51.519 C67.512,54.271 63.056,54.271 60.303,51.519 C58.235,49.449 57.723,46.409 58.772,43.861 L49.272,34.362 L49.272,59.358 C49.942,59.69 50.575,60.133 51.133,60.69 C53.883,63.44 53.883,67.896 51.133,70.65 C48.383,73.399 43.924,73.399 41.176,70.65 C38.426,67.896 38.426,63.44 41.176,60.69 C41.856,60.011 42.643,59.497 43.483,59.153 L43.483,33.925 C42.643,33.582 41.858,33.072 41.176,32.389 C39.093,30.307 38.592,27.249 39.661,24.691 L29.243,14.271 L1.733,41.779 C-0.578,44.092 -0.578,47.839 1.733,50.15 L41.854,90.268 C44.164,92.578 47.91,92.578 50.223,90.268 L90.155,50.336 C92.466,48.025 92.466,44.275 90.155,41.965"></path></g></svg>;
157157
break;
158158

@@ -307,13 +307,15 @@ class Pkg extends Component {
307307
<div className="details--main">
308308
<div className="details__readme">
309309
<h3 className="details__header">Readme</h3>
310-
<ReactMarkdown
311-
className="details__readme__src"
312-
source={pkg.readme || readme}
313-
linkTarget="_blank"
314-
escapeHtml={false}
315-
transformLinkUri={this.parseTransformLinkUri}
316-
/>
310+
{!!(pkg.readme || readme) && (
311+
<ReactMarkdown
312+
className="details__readme__src"
313+
source={pkg.readme || readme}
314+
linkTarget="_blank"
315+
escapeHtml={false}
316+
transformLinkUri={this.parseTransformLinkUri}
317+
/>
318+
)}
317319
</div>
318320
</div>
319321
</Styled.DetailsSection>

0 commit comments

Comments
 (0)