This repository was archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Merged
feat: Gitlab #197
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7dd6643
feat: wip gitlab support
ijsnow a6d0ba8
feat: wip
ijsnow e00c370
feat: wip
ijsnow de36adc
feat: diffs work reliably
ijsnow fc999a9
feat: more reliable diff sha resolving
ijsnow caeeeb7
docs: add doc blocks
ijsnow adedfa6
chore: rm console.log
ijsnow b4804de
fix: diff getCodeElementFromLineNumber
ijsnow db82575
feat: commit page
ijsnow 02c4fab
feat: search
ijsnow b3db104
chore: run prettier
ijsnow 2d6aea2
fix: diff getLineNumberFromCodeElement and address review comments
ijsnow 86f93c7
chore: rm log
ijsnow 2f7374d
refactor: MRResponse -> MergeRequestResponse
ijsnow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,8 @@ | |
| } | ||
| } | ||
| } | ||
| .hover-overlay-mount__gitlab { | ||
| .hover-overlay { | ||
| z-index: 1000; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import storage from '../../browser/storage' | ||
| import { resolveRev } from '../../shared/repo/backend' | ||
| import { getPlatformName, repoUrlCache, sourcegraphUrl } from '../../shared/util/context' | ||
|
|
||
| export interface SearchPageInformation { | ||
| query: string | ||
| repoPath: string | ||
| rev?: string | ||
| } | ||
|
|
||
| /** | ||
| * Interface containing information needed for the search feature. | ||
| */ | ||
| export interface SearchFeature { | ||
| /** | ||
| * Check that we're on the search page. | ||
| */ | ||
| checkIsSearchPage: () => boolean | ||
| /** | ||
| * Get information required for executing a search. | ||
| */ | ||
| getRepoInformation: () => SearchPageInformation | ||
| } | ||
|
|
||
| function getSourcegraphURLProps({ | ||
| repoPath, | ||
| rev, | ||
| query, | ||
| }: SearchPageInformation): { url: string; repo: string; rev: string | undefined; query: string } | undefined { | ||
| if (repoPath) { | ||
| if (rev) { | ||
| return { | ||
| url: `search?q=${encodeURIComponent(query)}&sq=repo:%5E${encodeURIComponent( | ||
| repoPath.replace(/\./g, '\\.') | ||
| )}%24@${encodeURIComponent(rev)}&utm_source=${getPlatformName()}`, | ||
| repo: repoPath, | ||
| rev, | ||
| query: `${encodeURIComponent(query)} ${encodeURIComponent( | ||
| repoPath.replace(/\./g, '\\.') | ||
| )}%24@${encodeURIComponent(rev)}`, | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| url: `search?q=${encodeURIComponent(query)}&sq=repo:%5E${encodeURIComponent( | ||
| repoPath.replace(/\./g, '\\.') | ||
| )}%24&utm_source=${getPlatformName()}`, | ||
| repo: repoPath, | ||
| rev, | ||
| query: `repo:^${repoPath.replace(/\./g, '\\.')}$ ${query}`, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export function initSearch({ getRepoInformation, checkIsSearchPage }: SearchFeature): void { | ||
| if (checkIsSearchPage()) { | ||
| storage.getSync(({ executeSearchEnabled }) => { | ||
| // GitHub search page pathname is <org>/<repo>/search | ||
| if (!executeSearchEnabled) { | ||
| return | ||
| } | ||
|
|
||
| const { repoPath, rev, query } = getRepoInformation() | ||
| if (query) { | ||
| const linkProps = getSourcegraphURLProps({ repoPath, rev, query }) | ||
|
|
||
| if (linkProps) { | ||
| // Ensure that we open the correct sourcegraph server url by checking which | ||
| // server instance can access the repository. | ||
| resolveRev({ repoPath: linkProps.repo }).subscribe(() => { | ||
| const baseUrl = repoUrlCache[linkProps.repo] || sourcegraphUrl | ||
| const url = `${baseUrl}/${linkProps.url}` | ||
| window.open(url, '_blank') | ||
| }) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { first } from 'lodash' | ||
| import { Observable } from 'rxjs' | ||
| import { ajax } from 'rxjs/ajax' | ||
| import { map } from 'rxjs/operators' | ||
|
|
||
| import { memoizeObservable } from '../../shared/util/memoize' | ||
| import { GitLabDiffInfo } from './scrape' | ||
|
|
||
| /** | ||
| * Significant revisions for a merge request. | ||
| */ | ||
| interface DiffRefs { | ||
| base_sha: string | ||
| head_sha: string | ||
| start_sha: string | ||
| } | ||
|
|
||
| /** | ||
| * Response from the GitLab API for fetching a merge request. Note that there | ||
| * is more information returned but we are not using it. | ||
| */ | ||
| interface MergeRequestResponse { | ||
| diff_refs: DiffRefs | ||
| } | ||
|
|
||
| /** | ||
| * Response from the GitLab API for fetching a specific version(diff) of a merge | ||
| * request. Note that there is more information returned but we are not using it. | ||
| */ | ||
| interface DiffVersionsResponse { | ||
| base_commit_sha: string | ||
| } | ||
|
|
||
| type GetBaseCommitIDInput = Pick<GitLabDiffInfo, 'owner' | 'repoName' | 'mergeRequestID' | 'diffID'> | ||
|
|
||
| const buildURL = (owner: string, repoName: string, path: string) => | ||
| `${window.location.origin}/api/v4/projects/${owner}%2f${repoName}${path}` | ||
|
|
||
| const get = <T>(url: string): Observable<T> => ajax.get(url).pipe(map(({ response }) => response as T)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid type parameters that are only used in the return type - it's only a cast in disguise. It's better to cast explicitly.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Casting is actually what I intended with that. I think it's easier to read at the call sights. |
||
|
|
||
| /** | ||
| * Get the base commit ID for a merge request. | ||
| */ | ||
| export const getBaseCommitIDForMergeRequest: (info: GetBaseCommitIDInput) => Observable<string> = memoizeObservable( | ||
| ({ owner, repoName, mergeRequestID, diffID }: GetBaseCommitIDInput) => { | ||
| const mrURL = buildURL(owner, repoName, `/merge_requests/${mergeRequestID}`) | ||
|
|
||
| // If we have a `diffID`, retrieve the information for that individual diff. | ||
| if (diffID) { | ||
| return get<DiffVersionsResponse>(`${mrURL}/versions/${diffID}`).pipe( | ||
| map(({ base_commit_sha }) => base_commit_sha) | ||
| ) | ||
| } | ||
|
|
||
| // Otherwise, just get the overall base `commitID` for the merge request. | ||
| return get<MergeRequestResponse>(mrURL).pipe(map(({ diff_refs: { base_sha } }) => base_sha)) | ||
| }, | ||
| ({ mergeRequestID, diffID }) => mergeRequestID + (diffID ? `/${diffID}` : '') | ||
| ) | ||
|
|
||
| interface CommitResponse { | ||
| parent_ids: string[] | ||
| } | ||
|
|
||
| /** | ||
| * Get the base commit ID for a commit. | ||
| */ | ||
| export const getBaseCommitIDForCommit: ( | ||
| { owner, repoName, commitID }: Pick<GetBaseCommitIDInput, 'owner' | 'repoName'> & { commitID: string } | ||
| ) => Observable<string> = memoizeObservable(({ owner, repoName, commitID }) => | ||
| get<CommitResponse>(buildURL(owner, repoName, `/repository/commits/${commitID}`)).pipe( | ||
| map(({ parent_ids }) => first(parent_ids)!) // ! because it'll always have a parent if we are looking at the commit page. | ||
| ) | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the
URLAPI to avoid manualencodeURIComponentcalls