diff --git a/client/search-ui/src/components/SearchResult.module.scss b/client/search-ui/src/components/SearchResult.module.scss index 9dbe8988f91..5665a891b6a 100644 --- a/client/search-ui/src/components/SearchResult.module.scss +++ b/client/search-ui/src/components/SearchResult.module.scss @@ -83,3 +83,9 @@ flex-grow: 1; min-width: 0; } + +.commit-oid { + background: var(--code-bg); + display: inline-block; + padding: 0.25rem; +} diff --git a/client/search-ui/src/components/SearchResult.tsx b/client/search-ui/src/components/SearchResult.tsx index 5ae4f5790fb..bcb0307b80b 100644 --- a/client/search-ui/src/components/SearchResult.tsx +++ b/client/search-ui/src/components/SearchResult.tsx @@ -4,15 +4,23 @@ import LockIcon from 'mdi-react/LockIcon' import SourceForkIcon from 'mdi-react/SourceForkIcon' import React from 'react' -import { renderMarkdown } from '@sourcegraph/common' import { LastSyncedIcon } from '@sourcegraph/shared/src/components/LastSyncedIcon' -import { Markdown } from '@sourcegraph/shared/src/components/Markdown' +import { displayRepoName } from '@sourcegraph/shared/src/components/RepoFileLink' import { RepoIcon } from '@sourcegraph/shared/src/components/RepoIcon' import { ResultContainer } from '@sourcegraph/shared/src/components/ResultContainer' import { SearchResultStar } from '@sourcegraph/shared/src/components/SearchResultStar' import { PlatformContextProps } from '@sourcegraph/shared/src/platform/context' -import { CommitMatch, getMatchTitle, RepositoryMatch } from '@sourcegraph/shared/src/search/stream' +import { + CommitMatch, + getCommitMatchUrl, + getRepoMatchLabel, + getRepoMatchUrl, + getRepositoryUrl, + RepositoryMatch, +} from '@sourcegraph/shared/src/search/stream' import { formatRepositoryStarCount } from '@sourcegraph/shared/src/util/stars' +import { Timestamp } from '@sourcegraph/web/src/components/time/Timestamp' +import { Link } from '@sourcegraph/wildcard' import { CommitSearchResultMatch } from './CommitSearchResultMatch' import styles from './SearchResult.module.scss' @@ -38,19 +46,28 @@ export const SearchResult: React.FunctionComponent = ({ return (
- + + {result.type === 'commit' && ( + <> + {displayRepoName(result.repository)} + {' › '} + {result.authorName} + {': '} + {result.message.split('\n', 1)[0]} + + )} + {result.type === 'repo' && ( + {displayRepoName(getRepoMatchLabel(result))} + )} + - {result.type === 'commit' && result.detail && ( - <> - - - )} - {result.type === 'commit' && result.detail && formattedRepositoryStarCount && ( -
+ {result.type === 'commit' && ( + + {result.oid.slice(0, 7)}{' '} + + )} + {result.type === 'commit' && formattedRepositoryStarCount &&
} {formattedRepositoryStarCount && ( <> diff --git a/client/shared/src/search/stream.ts b/client/shared/src/search/stream.ts index 96d86b106d7..d0ce2eb2b90 100644 --- a/client/shared/src/search/stream.ts +++ b/client/shared/src/search/stream.ts @@ -5,7 +5,6 @@ import { AggregableBadge } from 'sourcegraph' import { asError, ErrorLike, isErrorLike } from '@sourcegraph/common' -import { displayRepoName } from '../components/RepoFileLink' import { SearchPatternType } from '../graphql-operations' import { SymbolKind } from '../schema' @@ -102,10 +101,12 @@ type MarkdownText = string */ export interface CommitMatch { type: 'commit' - label: MarkdownText url: string - detail: MarkdownText repository: string + oid: string + message: string + authorName: string + authorDate: string repoStars?: number repoLastFetched?: string @@ -513,6 +514,10 @@ export function getRepoMatchUrl(repoMatch: RepositoryMatch): string { return '/' + encodeURI(label) } +export function getCommitMatchUrl(commitMatch: CommitMatch): string { + return '/' + encodeURI(commitMatch.repository) + '/-/commit/' + commitMatch.oid +} + export function getMatchUrl(match: SearchMatch): string { switch (match.type) { case 'path': @@ -520,16 +525,8 @@ export function getMatchUrl(match: SearchMatch): string { case 'symbol': return getFileMatchUrl(match) case 'commit': - return match.url + return getCommitMatchUrl(match) case 'repo': return getRepoMatchUrl(match) } } - -export function getMatchTitle(match: RepositoryMatch | CommitMatch): MarkdownText { - if (match.type === 'commit') { - return match.label - } - - return `[${displayRepoName(getRepoMatchLabel(match))}](${getRepoMatchUrl(match)})` -} diff --git a/client/web/src/integration/streaming-search-mocks.ts b/client/web/src/integration/streaming-search-mocks.ts index a77776f51bf..c8e92efae3e 100644 --- a/client/web/src/integration/streaming-search-mocks.ts +++ b/client/web/src/integration/streaming-search-mocks.ts @@ -10,12 +10,12 @@ export const diffSearchStreamEvents: SearchEvent[] = [ data: [ { type: 'commit', - label: - '[sourcegraph/sourcegraph-lightstep](/gitlab.sgdev.org/sourcegraph/sourcegraph-lightstep) › [Quinn Slack](/gitlab.sgdev.org/sourcegraph/sourcegraph-lightstep/-/commit/65dba23797be9e0ce1941f92c5385a7856bc5a42): [build: set up test deps and scripts](/gitlab.sgdev.org/sourcegraph/sourcegraph-lightstep/-/commit/65dba23797be9e0ce1941f92c5385a7856bc5a42)', + oid: '65dba23797be9e0ce1941f92c5385a7856bc5a42', + message: 'build: set up test deps and scripts\n', + authorName: 'Quinn Slack', + authorDate: '2019-10-29T20:59:15Z', url: '/gitlab.sgdev.org/sourcegraph/sourcegraph-lightstep/-/commit/65dba23797be9e0ce1941f92c5385a7856bc5a42', - detail: - '[`65dba23` 2 years ago](/gitlab.sgdev.org/sourcegraph/sourcegraph-lightstep/-/commit/65dba23797be9e0ce1941f92c5385a7856bc5a42)', repository: 'gitlab.sgdev.org/sourcegraph/sourcegraph-lightstep', content: '```diff\nmocha.opts mocha.opts\n@@ -0,0 +3,2 @@\n+--timeout 200\n+src/**/*.test.ts\n\\ No newline at end of file\npackage.json package.json\n@@ -50,0 +54,3 @@\n+ "exclude": [\n+ "**/*.test.ts"\n+ ],\n@@ -54,1 +64,2 @@\n- "serve": "parcel serve --no-hmr --out-file dist/extension.js src/extension.ts",\n+ "test": "TS_NODE_COMPILER_OPTIONS=\'{\\"module\\":\\"commonjs\\"}\' mocha --require ts-node/register --require source-map-support/register --opts mocha.opts",\n+ "cover": "TS_NODE_COMPILER_OPTIONS=\'{\\"module\\":\\"commonjs\\"}\' nyc --require ts-node/register --require source-map-support/register --all mocha --opts mocha.opts --timeout 10000",\n@@ -57,2 +70,2 @@\n- "sourcegraph:prepublish": "parcel build src/extension.ts"\n+ "sourcegraph:prepublish": "yarn typecheck && yarn test && yarn build"\n },\nyarn.lock yarn.lock\n@@ -3736,0 +4204,3 @@ number-is-nan@^1.0.0:\n+ spawn-wrap "^1.4.2"\n+ test-exclude "^5.1.0"\n+ uuid "^3.3.2"\n@@ -5550,1 +6166,5 @@ terser@^3.7.3, terser@^3.8.1:\n \n+test-exclude@^5.1.0:\n+ version "5.1.0"\n+ resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.1.0.tgz#6ba6b25179d2d38724824661323b73e03c0c1de1"\n+ integrity sha512-gwf0S2fFsANC55fSeSqpb8BYk6w3FDvwZxfNjeF6FRgvFa43r+7wRiA/Q0IxoRU37wB/LE8IQ4221BsNucTaCA==\n```', @@ -48,12 +48,12 @@ export const commitSearchStreamEvents: SearchEvent[] = [ data: [ { type: 'commit', - label: - '[sourcegraph/sourcegraph-sentry](/gitlab.sgdev.org/sourcegraph/sourcegraph-sentry) › [Vanesa](/gitlab.sgdev.org/sourcegraph/sourcegraph-sentry/-/commit/7e69ceb49adc30cb46bbe50335e1a371a0f2f6b1): [add more tests, use the Sourcegraph stubs api and improve repo matching. (#13)](/gitlab.sgdev.org/sourcegraph/sourcegraph-sentry/-/commit/7e69ceb49adc30cb46bbe50335e1a371a0f2f6b1)', + oid: '7e69ceb49adc30cb46bbe50335e1a371a0f2f6b1', + message: 'add more tests, use the Sourcegraph stubs api and improve repo matching. (#13)', + authorName: 'Vanesa', + authorDate: '2019-10-29T20:59:15Z', url: '/gitlab.sgdev.org/sourcegraph/sourcegraph-sentry/-/commit/7e69ceb49adc30cb46bbe50335e1a371a0f2f6b1', - detail: - '[`7e69ceb` 2 years ago](/gitlab.sgdev.org/sourcegraph/sourcegraph-sentry/-/commit/7e69ceb49adc30cb46bbe50335e1a371a0f2f6b1)', repository: 'gitlab.sgdev.org/sourcegraph/sourcegraph-sentry', content: '```COMMIT_EDITMSG\nadd more tests, use the Sourcegraph stubs api and improve repo matching. (#13)\n\n* add more tests, refactor to use extension api stubs\r\n* improve repo matching\r\nCo-Authored-By: Felix Becker \n```', diff --git a/cmd/frontend/internal/search/search.go b/cmd/frontend/internal/search/search.go index 96cb6808f04..2202d17ab5a 100644 --- a/cmd/frontend/internal/search/search.go +++ b/cmd/frontend/internal/search/search.go @@ -561,6 +561,10 @@ func fromCommit(commit *result.CommitMatch, repoCache map[api.RepoID]*types.Sear URL: commit.URL().String(), Detail: commit.Detail(), Repository: string(commit.Repo.Name), + OID: string(commit.Commit.ID), + Message: string(commit.Commit.Message), + AuthorName: commit.Commit.Author.Name, + AuthorDate: commit.Commit.Author.Date, Content: hls.Value, Ranges: ranges, } diff --git a/internal/search/streaming/http/events.go b/internal/search/streaming/http/events.go index f8cebf1b0a8..b7f63602243 100644 --- a/internal/search/streaming/http/events.go +++ b/internal/search/streaming/http/events.go @@ -137,6 +137,10 @@ type EventCommitMatch struct { Detail string `json:"detail"` RepositoryID int32 `json:"repositoryID"` Repository string `json:"repository"` + OID string `json:"oid"` + Message string `json:"message"` + AuthorName string `json:"authorName"` + AuthorDate time.Time `json:"authorDate"` RepoStars int `json:"repoStars,omitempty"` RepoLastFetched *time.Time `json:"repoLastFetched,omitempty"` Content string `json:"content"`