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';
let fetchpromise;
let resolvers = [];
export function resolveCommit(commits, { resolve, entry }) {
const commit = commits.find(c => c.fileName === entry.name && c.type === entry.type);
export function resolveCommit(commits, path, { resolve, entry }) {
const commit = commits.find(c => c.filePath === `${path}/${entry.name}` && c.type === entry.type);
if (commit) {
resolve(commit);
......@@ -35,13 +35,13 @@ export function fetchLogsTree(client, path, offset, resolver = null) {
.then(({ data, headers }) => {
const headerLogsOffset = headers['more-logs-offset'];
const { commits } = client.readQuery({ query: getCommits });
const newCommitData = [...commits, ...normalizeData(data)];
const newCommitData = [...commits, ...normalizeData(data, path)];
client.writeQuery({
query: getCommits,
data: { commits: newCommitData },
});
resolvers.forEach(r => resolveCommit(newCommitData, r));
resolvers.forEach(r => resolveCommit(newCommitData, path, r));
fetchpromise = null;
......
// eslint-disable-next-line import/prefer-default-export
export function normalizeData(data, extra = () => {}) {
export function normalizeData(data, path, extra = () => {}) {
return data.map(d => ({
sha: d.commit.id,
message: d.commit.message,
committedDate: d.commit.committed_date,
commitPath: d.commit_path,
fileName: d.file_name,
filePath: `${path}/${d.file_name}`,
type: d.type,
__typename: 'LogTreeCommit',
...extra(d),
......
import { normalizeData as normalizeDataFOSS } from '~/repository/utils/commit';
// eslint-disable-next-line import/prefer-default-export
export function normalizeData(data) {
return normalizeDataFOSS(data, d => ({
export function normalizeData(data, path) {
return normalizeDataFOSS(data, path, d => ({
lockLabel: d.lock_label,
}));
}
......@@ -16,13 +16,14 @@ const mockData = [
describe('normalizeData', () => {
it('normalizes data into LogTreeCommit object', () => {
expect(normalizeData(mockData)).toEqual([
expect(normalizeData(mockData, '')).toEqual([
{
sha: '123',
message: 'testing message',
committedDate: '2019-01-01',
commitPath: 'https://test.com',
fileName: 'index.js',
filePath: '/index.js',
type: 'blob',
lockLabel: 'Locked',
__typename: 'LogTreeCommit',
......
......@@ -21,11 +21,18 @@ describe('resolveCommit', () => {
entry: { name: 'index.js', type: 'blob' },
resolve: jest.fn(),
};
const commits = [{ fileName: 'index.js', type: 'blob' }];
resolveCommit(commits, resolver);
expect(resolver.resolve).toHaveBeenCalledWith({ fileName: 'index.js', type: 'blob' });
const commits = [
{ fileName: 'index.js', filePath: '/index.js', type: 'blob' },
{ fileName: 'index.js', filePath: '/app/assets/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', () => {
commitPath: 'https://test.com',
committedDate: '2019-01-01',
fileName: 'index.js',
filePath: '/index.js',
message: 'testing message',
sha: '123',
type: 'blob',
......@@ -101,6 +109,7 @@ describe('fetchLogsTree', () => {
commitPath: 'https://test.com',
committedDate: '2019-01-01',
fileName: 'index.js',
filePath: '/index.js',
message: 'testing message',
sha: '123',
type: 'blob',
......
......@@ -15,13 +15,14 @@ const mockData = [
describe('normalizeData', () => {
it('normalizes data into LogTreeCommit object', () => {
expect(normalizeData(mockData)).toEqual([
expect(normalizeData(mockData, '')).toEqual([
{
sha: '123',
message: 'testing message',
committedDate: '2019-01-01',
commitPath: 'https://test.com',
fileName: 'index.js',
filePath: '/index.js',
type: 'blob',
__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