Commit 3325497c authored by Phil Hughes's avatar Phil Hughes

Correctly return the commit data for specific file

Loads the commit data for a row based on file path not file name
This fixes an issue where sometimes the wrong commit data was shown
parent c2bd9591
...@@ -7,8 +7,8 @@ import getRef from './queries/getRef.query.graphql'; ...@@ -7,8 +7,8 @@ import getRef from './queries/getRef.query.graphql';
let fetchpromise; let fetchpromise;
let resolvers = []; let resolvers = [];
export function resolveCommit(commits, { resolve, entry }) { export function resolveCommit(commits, path, { resolve, entry }) {
const commit = commits.find(c => c.fileName === entry.name && c.type === entry.type); const commit = commits.find(c => c.filePath === `${path}/${entry.name}` && c.type === entry.type);
if (commit) { if (commit) {
resolve(commit); resolve(commit);
...@@ -35,13 +35,13 @@ export function fetchLogsTree(client, path, offset, resolver = null) { ...@@ -35,13 +35,13 @@ export function fetchLogsTree(client, path, offset, resolver = null) {
.then(({ data, headers }) => { .then(({ data, headers }) => {
const headerLogsOffset = headers['more-logs-offset']; const headerLogsOffset = headers['more-logs-offset'];
const { commits } = client.readQuery({ query: getCommits }); const { commits } = client.readQuery({ query: getCommits });
const newCommitData = [...commits, ...normalizeData(data)]; const newCommitData = [...commits, ...normalizeData(data, path)];
client.writeQuery({ client.writeQuery({
query: getCommits, query: getCommits,
data: { commits: newCommitData }, data: { commits: newCommitData },
}); });
resolvers.forEach(r => resolveCommit(newCommitData, r)); resolvers.forEach(r => resolveCommit(newCommitData, path, r));
fetchpromise = null; fetchpromise = null;
......
// eslint-disable-next-line import/prefer-default-export // eslint-disable-next-line import/prefer-default-export
export function normalizeData(data, extra = () => {}) { export function normalizeData(data, path, extra = () => {}) {
return data.map(d => ({ return data.map(d => ({
sha: d.commit.id, sha: d.commit.id,
message: d.commit.message, message: d.commit.message,
committedDate: d.commit.committed_date, committedDate: d.commit.committed_date,
commitPath: d.commit_path, commitPath: d.commit_path,
fileName: d.file_name, fileName: d.file_name,
filePath: `${path}/${d.file_name}`,
type: d.type, type: d.type,
__typename: 'LogTreeCommit', __typename: 'LogTreeCommit',
...extra(d), ...extra(d),
......
import { normalizeData as normalizeDataFOSS } from '~/repository/utils/commit'; import { normalizeData as normalizeDataFOSS } from '~/repository/utils/commit';
// eslint-disable-next-line import/prefer-default-export // eslint-disable-next-line import/prefer-default-export
export function normalizeData(data) { export function normalizeData(data, path) {
return normalizeDataFOSS(data, d => ({ return normalizeDataFOSS(data, path, d => ({
lockLabel: d.lock_label, lockLabel: d.lock_label,
})); }));
} }
...@@ -16,13 +16,14 @@ const mockData = [ ...@@ -16,13 +16,14 @@ const mockData = [
describe('normalizeData', () => { describe('normalizeData', () => {
it('normalizes data into LogTreeCommit object', () => { it('normalizes data into LogTreeCommit object', () => {
expect(normalizeData(mockData)).toEqual([ expect(normalizeData(mockData, '')).toEqual([
{ {
sha: '123', sha: '123',
message: 'testing message', message: 'testing message',
committedDate: '2019-01-01', committedDate: '2019-01-01',
commitPath: 'https://test.com', commitPath: 'https://test.com',
fileName: 'index.js', fileName: 'index.js',
filePath: '/index.js',
type: 'blob', type: 'blob',
lockLabel: 'Locked', lockLabel: 'Locked',
__typename: 'LogTreeCommit', __typename: 'LogTreeCommit',
......
...@@ -21,11 +21,18 @@ describe('resolveCommit', () => { ...@@ -21,11 +21,18 @@ describe('resolveCommit', () => {
entry: { name: 'index.js', type: 'blob' }, entry: { name: 'index.js', type: 'blob' },
resolve: jest.fn(), resolve: jest.fn(),
}; };
const commits = [{ fileName: 'index.js', type: 'blob' }]; const commits = [
{ fileName: 'index.js', filePath: '/index.js', type: 'blob' },
resolveCommit(commits, resolver); { fileName: 'index.js', filePath: '/app/assets/index.js', type: 'blob' },
];
expect(resolver.resolve).toHaveBeenCalledWith({ fileName: 'index.js', type: 'blob' });
resolveCommit(commits, '', resolver);
expect(resolver.resolve).toHaveBeenCalledWith({
fileName: 'index.js',
filePath: '/index.js',
type: 'blob',
});
}); });
}); });
...@@ -84,6 +91,7 @@ describe('fetchLogsTree', () => { ...@@ -84,6 +91,7 @@ describe('fetchLogsTree', () => {
commitPath: 'https://test.com', commitPath: 'https://test.com',
committedDate: '2019-01-01', committedDate: '2019-01-01',
fileName: 'index.js', fileName: 'index.js',
filePath: '/index.js',
message: 'testing message', message: 'testing message',
sha: '123', sha: '123',
type: 'blob', type: 'blob',
...@@ -101,6 +109,7 @@ describe('fetchLogsTree', () => { ...@@ -101,6 +109,7 @@ describe('fetchLogsTree', () => {
commitPath: 'https://test.com', commitPath: 'https://test.com',
committedDate: '2019-01-01', committedDate: '2019-01-01',
fileName: 'index.js', fileName: 'index.js',
filePath: '/index.js',
message: 'testing message', message: 'testing message',
sha: '123', sha: '123',
type: 'blob', type: 'blob',
......
...@@ -15,13 +15,14 @@ const mockData = [ ...@@ -15,13 +15,14 @@ const mockData = [
describe('normalizeData', () => { describe('normalizeData', () => {
it('normalizes data into LogTreeCommit object', () => { it('normalizes data into LogTreeCommit object', () => {
expect(normalizeData(mockData)).toEqual([ expect(normalizeData(mockData, '')).toEqual([
{ {
sha: '123', sha: '123',
message: 'testing message', message: 'testing message',
committedDate: '2019-01-01', committedDate: '2019-01-01',
commitPath: 'https://test.com', commitPath: 'https://test.com',
fileName: 'index.js', fileName: 'index.js',
filePath: '/index.js',
type: 'blob', type: 'blob',
__typename: 'LogTreeCommit', __typename: 'LogTreeCommit',
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment