Skip to content

Commit

Permalink
feat(schema): move git head into githubRepo
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed May 24, 2017
1 parent 67142c4 commit 5cbf4e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ For every single NPM package, we create a record in the Algolia index. The resul
"githubRepo": {
"user": "babel",
"project": "babel",
"path": "/tree/master/packages/babel-core"
"path": "/tree/master/packages/babel-core",
"head": "f6ad789eba27db50d25cc7eac062bbb0dde19c16"
},
"readme": "# babel-core\n> Babel compiler core.\n```javascript\nvar babel = require(\"babel-core\");\nimport { transform } from 'babel-core';\nimport * as babel from 'babel-core';\n```\nAll transformations will use your local configuration files (.babelrc or in package.json). See [options](#options) to disable it.\n## babel.transform(code: string, [options?](#options): Object)\nTransforms the passed in `code`. Returning an object with the generated code,\nsource map, and AST.\n```js\nbabel.transform(code, options)", //truncated at 200kb with **TRUNCATED**
"owner": {
Expand Down
31 changes: 15 additions & 16 deletions formatPkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ export default function formatPkg(pkg) {
return undefined;
}

const githubRepo = cleaned.repository
? getGitHubRepoInfo(cleaned.repository)
: null;
const lastPublisher = cleaned.lastPublisher
? formatUser(cleaned.lastPublisher)
: null;
const author = getAuthor(cleaned);
const license = getLicense(cleaned);

const version = cleaned.version ? cleaned.version : '0.0.0';

const gitHead = getGitHead(pkg, version);
const versions = getVersions(cleaned);
const githubRepo = cleaned.repository
? getGitHubRepoInfo({ repository: cleaned.repository, versions, version })
: null;

if (!githubRepo && !lastPublisher && !author) {
return undefined; // ignore this package, we cannot link it to anyone
Expand All @@ -40,8 +39,6 @@ export default function formatPkg(pkg) {
const devDependencies = cleaned.devDependencies || {};
const concatenatedName = cleaned.name.replace(/[-/@_.]+/g, '');

const versions = getVersions(cleaned);

const rawPkg = {
objectID: cleaned.name,
name: cleaned.name,
Expand All @@ -57,7 +54,6 @@ export default function formatPkg(pkg) {
devDependencies,
originalAuthor: cleaned.author,
githubRepo,
gitHead,
readme: pkg.readme,
owner,
deprecated: cleaned.deprecated !== undefined ? cleaned.deprecated : false,
Expand Down Expand Up @@ -139,13 +135,6 @@ function getGravatar(obj) {
return gravatarUrl(obj.email);
}

function getGitHead(pkg, version) {
if (pkg.versions && pkg.versions[version] && pkg.versions[version].gitHead) {
return pkg.versions[version].gitHead;
}
return 'master';
}

function getVersions(cleaned) {
if (cleaned.other && cleaned.other.time) {
return Object.keys(cleaned.other.time)
Expand All @@ -170,7 +159,14 @@ function getKeywords(cleaned) {
return [];
}

function getGitHubRepoInfo(repository) {
function getGitHead({ versions, version }) {
if (versions[version] && versions[version].gitHead) {
return versions[version].gitHead;
}
return 'master';
}

function getGitHubRepoInfo({ repository, versions, version }) {
if (!repository || typeof repository !== 'string') return null;

const result = repository.match(
Expand All @@ -185,10 +181,13 @@ function getGitHubRepoInfo(repository) {
return null;
}

const head = getGitHead({ versions, version });

return {
user: result[1],
project: result[2],
path: result[3] || '',
head,
};
}

Expand Down
6 changes: 3 additions & 3 deletions github.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import got from 'got';
import race from 'promise-rat-race';

function getChangelog({ githubRepo, gitHead }) {
function getChangelog(githubRepo) {
if (githubRepo === null) {
return { changelogFilename: null };
}

const { user, project, path } = githubRepo;
const { user, project, path, head } = githubRepo;
if (user.length < 1 || project.length < 1) {
return { changelogFilename: null };
}

const baseGithubURL = `https://raw.githubusercontent.com/${user}/${project}/${gitHead}/${`${path.replace('/tree/', '')}`}`;
const baseGithubURL = `https://raw.githubusercontent.com/${user}/${project}/${head}/${`${path.replace('/tree/', '')}`}`;
const files = [
'CHANGELOG.md',
'ChangeLog.md',
Expand Down

0 comments on commit 5cbf4e4

Please sign in to comment.