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 16
feat(review-board): add review board support #98
Open
KattMingMing
wants to merge
1
commit into
master
Choose a base branch
from
rb-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
&__unstyled-list { | ||
list-style-type: none; | ||
padding: 0; | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { from, Observable } from 'rxjs' | ||
import { ReviewBoardRepository } from '../util' | ||
|
||
function getRepository(repoID: number): Promise<ReviewBoardRepository> { | ||
return new Promise((resolve, reject) => { | ||
fetch(`${window.location.origin}/api/repositories/${repoID}/`, { | ||
method: 'GET', | ||
credentials: 'include', | ||
headers: new Headers({ Accept: 'application/json' }), | ||
}) | ||
.then(resp => resp.json()) | ||
.then(resp => resolve(resp.repository)) | ||
.catch(err => reject(err)) | ||
}) | ||
} | ||
|
||
export function getRepositoryFromReviewBoardAPI(repoID: number): Observable<ReviewBoardRepository> { | ||
return from(getRepository(repoID)) | ||
} |
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,119 @@ | ||
import { DiffPart, DOMFunctions } from '@sourcegraph/codeintellify' | ||
|
||
/** | ||
* Gets the `<td>` element for a target that contains the code | ||
*/ | ||
const getCodeCellFromTarget = (target: HTMLElement): HTMLElement | null => { | ||
if (target.nodeName === 'PRE') { | ||
return null | ||
} | ||
const pre = target.closest('pre') as HTMLElement | ||
if (!pre) { | ||
return null | ||
} | ||
if (target.innerText.trim().length === 0) { | ||
return null | ||
} | ||
const closest = (target.closest('.l') || target.closest('.r')) as HTMLElement | ||
if (!closest.classList.contains('trimmed') && closest.classList.contains('annotated')) { | ||
const firstChild = closest.firstElementChild | ||
if ( | ||
firstChild && | ||
firstChild.nodeName === 'SPAN' && | ||
firstChild.textContent && | ||
firstChild.innerHTML.trim().length === 0 | ||
) { | ||
const newElement = document.createElement('span') | ||
newElement.innerHTML = ' ' | ||
closest.replaceChild(newElement, firstChild) | ||
} | ||
closest.classList.add('trimmed') | ||
} | ||
return closest | ||
} | ||
|
||
const getBlobCodeInner = (codeCell: HTMLElement) => { | ||
if (codeCell.classList.contains('l') || codeCell.classList.contains('r')) { | ||
return codeCell | ||
} | ||
return (codeCell.closest('.l') || codeCell.closest('.r')) as HTMLElement | ||
} | ||
|
||
/** | ||
* Gets the line number for a given code element on unified diff, split diff and blob views | ||
*/ | ||
const getLineNumberFromCodeElement = (codeElement: HTMLElement): number => { | ||
// In diff views, the code element is the `<span>` inside the cell | ||
// On blob views, the code element is the `<td>` itself, so `closest()` will simply return it | ||
// Walk all previous sibling cells until we find one with the line number | ||
let cell = codeElement.closest('td') as HTMLElement | ||
while (cell) { | ||
if (cell.nodeName === 'TH') { | ||
return parseInt(cell.innerText, 10) | ||
} | ||
cell = cell.previousElementSibling as HTMLTableRowElement | ||
} | ||
|
||
cell = codeElement.closest('tr')! as HTMLTableRowElement | ||
if (cell.getAttribute('line')) { | ||
return parseInt(cell.getAttribute('line')!, 10) | ||
} | ||
throw new Error('Could not find a line number in any cell') | ||
} | ||
|
||
/** | ||
* getDeltaFileName returns the path of the file container. Reviewboard will always be a diff. | ||
*/ | ||
export function getDeltaFileName(container: HTMLElement): { headFilePath: string; baseFilePath: string } { | ||
const info = container.querySelector('.filename-row') as HTMLElement | ||
if (!info) { | ||
throw new Error(`Unable to getDeltaFileName for container: ${container}`) | ||
} | ||
return { headFilePath: info.innerText, baseFilePath: info.innerText } | ||
} | ||
|
||
const getDiffCodePart = (codeElement: HTMLElement): DiffPart => { | ||
const td = codeElement.closest('td')! | ||
// If there are more cells on the right, this is the base, otherwise the head | ||
return td.classList.contains('l') ? 'base' : 'head' | ||
} | ||
|
||
/** | ||
* Implementations of the DOM functions for diff code views | ||
*/ | ||
export const diffDomFunctions: DOMFunctions = { | ||
getCodeElementFromTarget: target => { | ||
const codeCell = getCodeCellFromTarget(target) | ||
return codeCell && getBlobCodeInner(codeCell) | ||
}, | ||
getCodeElementFromLineNumber: () => null, | ||
getLineNumberFromCodeElement, | ||
getDiffCodePart, | ||
} | ||
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. I would propose to not have these in a |
||
|
||
/** | ||
* createBlobAnnotatorMount creates a <div> element and adds it to the DOM | ||
* where the BlobAnnotator component should be mounted. | ||
*/ | ||
export function createBlobAnnotatorMount(fileContainer: HTMLElement, isBase?: boolean): HTMLElement | null { | ||
const className = 'sourcegraph-app-annotator' + (isBase ? '-base' : '') | ||
const existingMount = fileContainer.querySelector('.' + className) as HTMLElement | ||
if (existingMount) { | ||
return existingMount | ||
} | ||
|
||
const mountEl = document.createElement('div') | ||
mountEl.style.display = 'inline-flex' | ||
mountEl.style.verticalAlign = 'middle' | ||
mountEl.style.alignItems = 'center' | ||
mountEl.className = className | ||
mountEl.style.cssFloat = 'right' | ||
|
||
const fileActions = fileContainer.querySelector('.filename-row') as HTMLElement | ||
if (!fileActions || !fileActions.firstElementChild) { | ||
return null | ||
} | ||
;(fileActions.firstElementChild as HTMLElement).style.overflow = 'visible' | ||
fileActions.firstElementChild!.appendChild(mountEl) | ||
return mountEl | ||
} |
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.
You shouldn't use the Promise constructor here,
fetch
already returns a Promise.