From 4fa4254b37d479f3bf90afd9db2ea41073a6957a Mon Sep 17 00:00:00 2001 From: Jason Silberman Date: Fri, 21 Jun 2019 17:23:24 -0700 Subject: [PATCH] fix: add back commitInfo actions --- packages/@best/frontend/server/api.ts | 2 +- .../src/modules/store/actions/actions.js | 31 +++++++++++++++++++ packages/@best/types/src/config.ts | 4 +++ packages/best-benchmarks/best.config.js | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/@best/frontend/server/api.ts b/packages/@best/frontend/server/api.ts index 2ec264fc..392b8ed3 100644 --- a/packages/@best/frontend/server/api.ts +++ b/packages/@best/frontend/server/api.ts @@ -1,7 +1,7 @@ import { Router } from 'express' import { loadDbFromConfig } from '@best/api-db' import { GithubApplicationFactory } from '@best/github-integration' -import { ApiDatabaseConfig, FrontendConfig } from '@best/types'; +import { FrontendConfig } from '@best/types'; export default (config: FrontendConfig): Router => { const db = loadDbFromConfig(config); diff --git a/packages/@best/frontend/src/modules/store/actions/actions.js b/packages/@best/frontend/src/modules/store/actions/actions.js index 7cb2799d..cefbc8dd 100755 --- a/packages/@best/frontend/src/modules/store/actions/actions.js +++ b/packages/@best/frontend/src/modules/store/actions/actions.js @@ -94,4 +94,35 @@ export function selectProject(project, shouldResetView) { dispatch(fetchBenchmarks(project)); dispatch({ type: PROJECT_SELECTED, id: project.id }); }; +} + +/* + * COMMIT INFO +*/ + +function normalizeCommit(commit) { + return commit.slice(0, 7); +} + +function shouldFetchCommitInfo(state, commit) { + return !state.commitInfo.hasOwnProperty(normalizeCommit(commit)); +} + +function commitInfoReceived(commit, commitInfo) { + return { type: COMMIT_INFO_RECEIVED, commit: normalizeCommit(commit), commitInfo }; +} + +function fetchCommitInfo(commit) { + return async (dispatch) => { + const commitInfo = await api.fetchCommitInfo(commit); + dispatch(commitInfoReceived(commit, commitInfo)); + } +} + +export function fetchCommitInfoIfNeeded(commit) { + return (dispatch, getState) => { + if (shouldFetchCommitInfo(getState(), commit)) { + dispatch(fetchCommitInfo(commit)); + } + } } \ No newline at end of file diff --git a/packages/@best/types/src/config.ts b/packages/@best/types/src/config.ts index 3935c117..91788458 100644 --- a/packages/@best/types/src/config.ts +++ b/packages/@best/types/src/config.ts @@ -28,6 +28,10 @@ export interface ApiDatabaseConfig { export interface FrontendConfig { apiDatabase: ApiDatabaseConfig; + githubConfig?: { + repo: string; + owner: string; + } } export interface CliConfig { diff --git a/packages/best-benchmarks/best.config.js b/packages/best-benchmarks/best.config.js index 5a9e92e4..a373363d 100644 --- a/packages/best-benchmarks/best.config.js +++ b/packages/best-benchmarks/best.config.js @@ -14,5 +14,5 @@ module.exports = { "remoteRunner": "@best/runner-headless" } } - ], + ] };