-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(alert-cli): change
diff
by replacing github-api
by a local di…
…ff (#972)
- Loading branch information
Showing
6 changed files
with
89 additions
and
130 deletions.
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 was deleted.
Oops, something went wrong.
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,11 @@ | ||
import { getDiff } from "../get-diff"; | ||
|
||
describe("getDiff", () => { | ||
it("should return an empty array if the project does not exist", async () => { | ||
const project = "does-not-exist-blabla"; | ||
const fromTag = "v1.0.0"; | ||
const toTag = "v2.0.0"; | ||
const diff = await getDiff(project, fromTag, toTag); | ||
expect(diff).toEqual([]); | ||
}); | ||
}); |
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,46 @@ | ||
import { GithubDiffFile } from "../APIs/api"; | ||
import { simpleGit } from "simple-git"; | ||
import { parsePatch } from "diff"; | ||
import fs from "fs"; | ||
|
||
export async function getDiff( | ||
project: string, | ||
fromTag: string, | ||
toTag: string | ||
): Promise<GithubDiffFile[]> { | ||
const repoPath = `/tmp/${project}`; | ||
try { | ||
if (fs.existsSync(repoPath)) { | ||
// remove the repo if it already exists | ||
fs.rmdirSync(repoPath, { recursive: true }); | ||
} | ||
await simpleGit().clone(`https://github.com/${project}`); | ||
const diffString = await simpleGit(repoPath).diff([ | ||
`${fromTag}...${toTag}`, | ||
]); | ||
const diffDetail = parsePatch(diffString); | ||
const result: GithubDiffFile[] = []; | ||
diffDetail.forEach((file) => { | ||
if (file.newFileName && !file.oldFileName) { | ||
result.push({ | ||
filename: file.newFileName, | ||
status: "added", | ||
}); | ||
} else if (file.newFileName && file.oldFileName) { | ||
result.push({ | ||
filename: file.newFileName, | ||
status: "modified", | ||
}); | ||
} else if (!file.newFileName && file.oldFileName) { | ||
result.push({ | ||
filename: file.oldFileName, | ||
status: "removed", | ||
}); | ||
} | ||
}); | ||
return result; | ||
} catch (error) { | ||
console.error(error); | ||
return []; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2135,6 +2135,18 @@ | |
methods "^1.1.2" | ||
path-to-regexp "^6.1.0" | ||
|
||
"@kwsites/file-exists@^1.1.1": | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/@kwsites/file-exists/-/file-exists-1.1.1.tgz#ad1efcac13e1987d8dbaf235ef3be5b0d96faa99" | ||
integrity sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw== | ||
dependencies: | ||
debug "^4.1.1" | ||
|
||
"@kwsites/promise-deferred@^1.1.1": | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz#8ace5259254426ccef57f3175bc64ed7095ed919" | ||
integrity sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw== | ||
|
||
"@lerna/[email protected]": | ||
version "5.6.2" | ||
resolved "https://registry.yarnpkg.com/@lerna/add/-/add-5.6.2.tgz#d0e25fd4900b6f8a9548f940cc016ce8a3e2d2ba" | ||
|
@@ -4661,6 +4673,11 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/diff@^5.0.3": | ||
version "5.0.3" | ||
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-5.0.3.tgz#1f89e49ff83b5d200d78964fb896c68498ce1828" | ||
integrity sha512-amrLbRqTU9bXMCc6uX0sWpxsQzRIo9z6MJPkH1pkez/qOxuqSZVuryJAWoBRq94CeG8JxY+VK4Le9HtjQR5T9A== | ||
|
||
"@types/express-serve-static-core@^4.17.33": | ||
version "4.17.35" | ||
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.35.tgz#c95dd4424f0d32e525d23812aa8ab8e4d3906c4f" | ||
|
@@ -8115,7 +8132,7 @@ diff@^4.0.1: | |
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" | ||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== | ||
|
||
diff@^5.0.0: | ||
diff@^5.0.0, diff@^5.1.0: | ||
version "5.1.0" | ||
resolved "https://registry.yarnpkg.com/diff/-/diff-5.1.0.tgz#bc52d298c5ea8df9194800224445ed43ffc87e40" | ||
integrity sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw== | ||
|
@@ -16374,6 +16391,15 @@ signal-exit@^4.0.1: | |
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.0.2.tgz#ff55bb1d9ff2114c13b400688fa544ac63c36967" | ||
integrity sha512-MY2/qGx4enyjprQnFaZsHib3Yadh3IXyV2C321GY0pjGfVBu4un0uDJkwgdxqO+Rdx8JMT8IfJIRwbYVz3Ob3Q== | ||
|
||
simple-git@^3.19.1: | ||
version "3.19.1" | ||
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-3.19.1.tgz#ff9c021961a3d876a1b115b1893bed9a28855d30" | ||
integrity sha512-Ck+rcjVaE1HotraRAS8u/+xgTvToTuoMkT9/l9lvuP5jftwnYUp6DwuJzsKErHgfyRk8IB8pqGHWEbM3tLgV1w== | ||
dependencies: | ||
"@kwsites/file-exists" "^1.1.1" | ||
"@kwsites/promise-deferred" "^1.1.1" | ||
debug "^4.3.4" | ||
|
||
simple-oauth2@^4.2.0: | ||
version "4.3.0" | ||
resolved "https://registry.yarnpkg.com/simple-oauth2/-/simple-oauth2-4.3.0.tgz#8b8c28a7f7145a77a2a03086b1adb1e9ba5abc98" | ||
|