-
-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP attempt at using the FS beforehand the API for github #991
Open
orta
wants to merge
6
commits into
main
Choose a base branch
from
fs_lookup
base: main
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cbdbf9d
WIP attempt at using the FS isntead of the API for github
orta 0aa0ea5
Merge branch 'main' into fs_lookup
fbartho 896aee7
Prettier was rewriting Changelog.md changing line lengths from what w…
fbartho 8f6dfcd
Add changelog entry for @orta's fs-optimization #991
fbartho e3c4da3
Cleanup Typos
fbartho f58b6a1
Merge pull request #1192 from danger/fb/fs_lookup
orta 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 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 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 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,20 @@ | ||
import { debug } from "../../debug" | ||
import { exec } from "child_process" | ||
|
||
const d = debug("localGetHeadSHA") | ||
|
||
export const localGetHeadSHA = () => | ||
new Promise<string>(done => { | ||
const call = `git rev-parse HEAD` | ||
d(call) | ||
|
||
exec(call, (err, stdout, _stderr) => { | ||
if (err) { | ||
console.error(`Could not get the git HEAD for the current path`) | ||
console.error(err) | ||
return | ||
} | ||
|
||
done(stdout.trim()) | ||
}) | ||
}) |
This file contains 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 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,98 @@ | ||
function rangesOfDifferBetweenTwoStrings(source: string, target: string) { | ||
const ranges = [] as { start: number; length: number }[] | ||
|
||
const addToIndex = (index: number) => { | ||
const closestIndex = ranges[ranges.length - 1] | ||
if (closestIndex) { | ||
const doesAddToIndex = closestIndex.start + closestIndex.length === index - 1 | ||
if (doesAddToIndex) { | ||
closestIndex.length = closestIndex.length + 1 | ||
} else { | ||
ranges.push({ start: index - 1, length: 1 }) | ||
} | ||
} else { | ||
ranges.push({ start: index - 1, length: 1 }) | ||
} | ||
} | ||
|
||
for (let index = 0; index < source.length; index++) { | ||
const srcChar = source[index] | ||
const targetChar = target[index] | ||
if (srcChar !== targetChar) { | ||
addToIndex(index) | ||
} | ||
} | ||
|
||
return ranges | ||
} | ||
|
||
function highlightDifferenceBetweenInStrings(source: string, target: string) { | ||
const ranges = rangesOfDifferBetweenTwoStrings(source, target) | ||
let emTarget = target | ||
ranges.forEach((range, index) => { | ||
const lhs = `\e[3m` | ||
const rhs = `\e[0m` | ||
const additionalOffset = index * lhs.length + index * rhs.length | ||
const before = emTarget.slice(0, range.start + 1 + additionalOffset) | ||
const between = emTarget.slice( | ||
range.start + 1 + additionalOffset, | ||
range.start + range.length + 1 + additionalOffset | ||
) | ||
const after = emTarget.slice(range.start + range.length + 1 + additionalOffset, emTarget.length) | ||
emTarget = before + lhs + between + rhs + after | ||
}) | ||
return emTarget | ||
} | ||
|
||
it("sees a difference", () => { | ||
const src = "Hello world" | ||
const target = "Hello w0rld" | ||
expect(highlightDifferenceBetweenInStrings(src, target)).toMatchInlineSnapshot(`"Hello we[3m0e[0mrld"`) | ||
|
||
const src2 = "Hello world" | ||
const target2 = "H3llo w0rld" | ||
expect(highlightDifferenceBetweenInStrings(src2, target2)).toMatchInlineSnapshot(`"He[3m3e[0mllo we[3m0e[0mrld"`) | ||
|
||
const src3 = "Hello world ok then" | ||
const target3 = "H3llo w0rld no then" | ||
expect(highlightDifferenceBetweenInStrings(src3, target3)).toMatchInlineSnapshot( | ||
`"He[3m3e[0mllo we[3m0e[0mrld e[3mnoe[0m then"` | ||
) | ||
|
||
// expect(rangesOfDifferBetweenTwoStrings(src, target)).toMatchInlineSnapshot(` | ||
// Array [ | ||
// Object { | ||
// "length": 1, | ||
// "start": 6, | ||
// }, | ||
// ] | ||
// `) | ||
|
||
// const multilineInput = ` | ||
// ↓ | ||
// (↓ | ||
// ····<div>↓ | ||
// ······text↓ | ||
// ····</div>↓ | ||
// ) | ||
// ` | ||
// const multilineOutput = ` | ||
// ↓ | ||
// (↓ | ||
// ····<div>↓ | ||
// ········text↓ | ||
// ······</div>↓ | ||
// )` | ||
// expect(rangesOfDifferBetweenTwoStrings(multilineInput, multilineOutput)).toMatchInlineSnapshot(` | ||
// Array [ | ||
// Object { | ||
// "length": 8, | ||
// "start": 22, | ||
// }, | ||
// Object { | ||
// "length": 10, | ||
// "start": 32, | ||
// }, | ||
// ] | ||
// `) | ||
}) |
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.
Not sure if this was a copy-pasted test file, or if you actually want these tests to work?