mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-21 04:20:53 +02:00
Set up CI with ESLint linter and Mocha test runner (#661)
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 22
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run lint
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 22
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm test
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import eslint from "@eslint/js";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
eslint.configs.recommended,
|
||||||
|
...tseslint.configs.recommended,
|
||||||
|
{
|
||||||
|
ignores: ["build/", "public/", "gulpfile.js", "healthcheck.js", "opentelemetry.js"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-explicit-any": "warn",
|
||||||
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"warn",
|
||||||
|
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-require-imports": "off",
|
||||||
|
"@typescript-eslint/no-empty-object-type": "off",
|
||||||
|
"no-empty": "warn",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ["test/**/*.js"],
|
||||||
|
languageOptions: {
|
||||||
|
sourceType: "commonjs",
|
||||||
|
globals: {
|
||||||
|
describe: "readonly",
|
||||||
|
it: "readonly",
|
||||||
|
before: "readonly",
|
||||||
|
after: "readonly",
|
||||||
|
beforeEach: "readonly",
|
||||||
|
afterEach: "readonly",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
Generated
+1905
-25
File diff suppressed because it is too large
Load Diff
+5
-1
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --reporter spec",
|
"test": "mocha --reporter spec",
|
||||||
|
"lint": "eslint .",
|
||||||
"start": "node --inspect=5858 -r ts-node/register ./src/server/index.ts",
|
"start": "node --inspect=5858 -r ts-node/register ./src/server/index.ts",
|
||||||
"dev": "nodemon --transpile-only ./src/server/index.ts",
|
"dev": "nodemon --transpile-only ./src/server/index.ts",
|
||||||
"build": "rm -rf build && tsc && gulp",
|
"build": "rm -rf build && tsc && gulp",
|
||||||
@@ -73,6 +74,7 @@
|
|||||||
"unzip-stream": "^0.3.1"
|
"unzip-stream": "^0.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^10.0.1",
|
||||||
"@types/archiver": "^5.3.4",
|
"@types/archiver": "^5.3.4",
|
||||||
"@types/compression": "^1.7.5",
|
"@types/compression": "^1.7.5",
|
||||||
"@types/crypto-js": "^4.2.2",
|
"@types/crypto-js": "^4.2.2",
|
||||||
@@ -88,6 +90,7 @@
|
|||||||
"@types/passport-github2": "^1.2.9",
|
"@types/passport-github2": "^1.2.9",
|
||||||
"@types/unzip-stream": "^0.3.4",
|
"@types/unzip-stream": "^0.3.4",
|
||||||
"chai": "^4.5.0",
|
"chai": "^4.5.0",
|
||||||
|
"eslint": "^10.2.0",
|
||||||
"gulp": "^5.0.0",
|
"gulp": "^5.0.0",
|
||||||
"gulp-clean-css": "^4.3.0",
|
"gulp-clean-css": "^4.3.0",
|
||||||
"gulp-concat": "^2.6.1",
|
"gulp-concat": "^2.6.1",
|
||||||
@@ -97,7 +100,8 @@
|
|||||||
"mocha": "^10.4.0",
|
"mocha": "^10.4.0",
|
||||||
"nodemon": "^3.1.0",
|
"nodemon": "^3.1.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.4.3"
|
"typescript": "^5.4.3",
|
||||||
|
"typescript-eslint": "^8.58.2"
|
||||||
},
|
},
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ const config: Config = {
|
|||||||
S3_REGION: null,
|
S3_REGION: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let conf in process.env) {
|
for (const conf in process.env) {
|
||||||
if ((config as any)[conf] !== undefined) {
|
if ((config as any)[conf] !== undefined) {
|
||||||
(config as any)[conf] = process.env[conf];
|
(config as any)[conf] = process.env[conf];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ export default class AnonymizedFile {
|
|||||||
.startActiveSpan("AnonymizedFile.send", async (span) => {
|
.startActiveSpan("AnonymizedFile.send", async (span) => {
|
||||||
span.setAttribute("repoId", this.repository.repoId);
|
span.setAttribute("repoId", this.repository.repoId);
|
||||||
span.setAttribute("anonymizedPath", this.anonymizedPath);
|
span.setAttribute("anonymizedPath", this.anonymizedPath);
|
||||||
|
// eslint-disable-next-line no-async-promise-executor
|
||||||
return new Promise<void>(async (resolve, reject) => {
|
return new Promise<void>(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (config.STREAMER_ENTRYPOINT) {
|
if (config.STREAMER_ENTRYPOINT) {
|
||||||
|
|||||||
+2
-2
@@ -135,7 +135,7 @@ export default class User {
|
|||||||
}).exec()
|
}).exec()
|
||||||
).map((d) => new Repository(d));
|
).map((d) => new Repository(d));
|
||||||
const promises = [];
|
const promises = [];
|
||||||
for (let repo of repositories) {
|
for (const repo of repositories) {
|
||||||
if (
|
if (
|
||||||
repo.status == "ready" &&
|
repo.status == "ready" &&
|
||||||
repo.options.expirationMode != "never" &&
|
repo.options.expirationMode != "never" &&
|
||||||
@@ -163,7 +163,7 @@ export default class User {
|
|||||||
}).exec()
|
}).exec()
|
||||||
).map((d) => new PullRequest(d));
|
).map((d) => new PullRequest(d));
|
||||||
const promises = [];
|
const promises = [];
|
||||||
for (let repo of pullRequests) {
|
for (const repo of pullRequests) {
|
||||||
if (
|
if (
|
||||||
repo.status == "ready" &&
|
repo.status == "ready" &&
|
||||||
repo.options.expirationMode != "never" &&
|
repo.options.expirationMode != "never" &&
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export class ContentAnonimizer {
|
|||||||
}
|
}
|
||||||
// remove image in markdown
|
// remove image in markdown
|
||||||
return content.replace(
|
return content.replace(
|
||||||
/!\[[^\]]*\]\((?<filename>.*?)(?=\"|\))(?<optionalpart>\".*\")?\)/g,
|
/!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalpart>".*")?\)/g,
|
||||||
() => {
|
() => {
|
||||||
this.wasAnonymized = true;
|
this.wasAnonymized = true;
|
||||||
return config.ANONYMIZATION_MASK;
|
return config.ANONYMIZATION_MASK;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ export default class GitHubStream extends GitHubBase {
|
|||||||
span.setAttribute("file", file.anonymizedPath);
|
span.setAttribute("file", file.anonymizedPath);
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
file.filePath;
|
void file.filePath;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// compute the original path if ambiguous
|
// compute the original path if ambiguous
|
||||||
await file.originalPath();
|
await file.originalPath();
|
||||||
|
|||||||
@@ -145,10 +145,10 @@ export default class FileSystem extends StorageBase {
|
|||||||
.startActiveSpan("fs.listFiles", async (span) => {
|
.startActiveSpan("fs.listFiles", async (span) => {
|
||||||
span.setAttribute("path", dir);
|
span.setAttribute("path", dir);
|
||||||
const fullPath = join(config.FOLDER, this.repoPath(repoId), dir);
|
const fullPath = join(config.FOLDER, this.repoPath(repoId), dir);
|
||||||
let files = await fs.promises.readdir(fullPath);
|
const files = await fs.promises.readdir(fullPath);
|
||||||
const output2: IFile[] = [];
|
const output2: IFile[] = [];
|
||||||
for (let file of files) {
|
for (const file of files) {
|
||||||
let filePath = join(fullPath, file);
|
const filePath = join(fullPath, file);
|
||||||
try {
|
try {
|
||||||
const stats = await fs.promises.stat(filePath);
|
const stats = await fs.promises.stat(filePath);
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ router.get("/repos", async (req, res) => {
|
|||||||
sort = {};
|
sort = {};
|
||||||
sort[req.query.sort as string] = -1;
|
sort[req.query.sort as string] = -1;
|
||||||
}
|
}
|
||||||
let query = [];
|
const query = [];
|
||||||
if (req.query.search) {
|
if (req.query.search) {
|
||||||
query.push({ repoId: { $regex: req.query.search } });
|
query.push({ repoId: { $regex: req.query.search } });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ router.get(
|
|||||||
);
|
);
|
||||||
|
|
||||||
function validateNewPullRequest(pullRequestUpdate: any): void {
|
function validateNewPullRequest(pullRequestUpdate: any): void {
|
||||||
const validCharacters = /^[0-9a-zA-Z\-\_]+$/;
|
const validCharacters = /^[0-9a-zA-Z\-_]+$/;
|
||||||
if (
|
if (
|
||||||
!pullRequestUpdate.pullRequestId.match(validCharacters) ||
|
!pullRequestUpdate.pullRequestId.match(validCharacters) ||
|
||||||
pullRequestUpdate.pullRequestId.length < 3
|
pullRequestUpdate.pullRequestId.length < 3
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function validateNewRepo(repoUpdate: any): void {
|
function validateNewRepo(repoUpdate: any): void {
|
||||||
const validCharacters = /^[0-9a-zA-Z\-\_]+$/;
|
const validCharacters = /^[0-9a-zA-Z\-_]+$/;
|
||||||
if (
|
if (
|
||||||
!repoUpdate.repoId.match(validCharacters) ||
|
!repoUpdate.repoId.match(validCharacters) ||
|
||||||
repoUpdate.repoId.length < 3
|
repoUpdate.repoId.length < 3
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ function printError(error: any, req?: express.Request) {
|
|||||||
}
|
}
|
||||||
console.error(message);
|
console.error(message);
|
||||||
} else if (error instanceof HTTPError) {
|
} else if (error instanceof HTTPError) {
|
||||||
let message = `[ERROR] HTTP.${
|
const message = `[ERROR] HTTP.${
|
||||||
error.code
|
error.code
|
||||||
} ${error.message.toString()} ${error.stack?.split("\n")[1].trim()}`;
|
} ${error.message.toString()} ${error.stack?.split("\n")[1].trim()}`;
|
||||||
console.error(message);
|
console.error(message);
|
||||||
|
|||||||
Reference in New Issue
Block a user