Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
{
"extends": ["eslint-config-unjs"]
"extends": ["eslint-config-unjs"],
"rules": {
"unicorn/no-null": "off",
"require-await": "error",
"unicorn/filename-case": "off",
"unicorn/no-process-exit": "error",
"unicorn/prefer-ternary": "error",
"unicorn/prefer-top-level-await": "off",
"no-useless-constructor": "error",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
},
],
"@typescript-eslint/no-namespace": "error",
"camelcase": "off",
"unicorn/prefer-code-point": "error",
"unicorn/prefer-string-slice": "off",
"unicorn/prefer-at": "off",
"unicorn/explicit-length-check": "off",
"unicorn/prefer-set-has": "off",
"no-empty": [
"error",
{
"allowEmptyCatch": true,
},
],
"prefer-const": "error",
"unicorn/no-empty-file": "error",
"@typescript-eslint/no-non-null-assertion": "off",
},
}
33 changes: 33 additions & 0 deletions .github/workflows/lint-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI Linting

on:
pull_request:

jobs:
linting:
name: Run Linting
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Enable Corepack
run: corepack enable

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Lint JavaScript
run: pnpm run lint:js

- name: Check formatting
run: pnpm run lint:format

- name: Type checking
run: pnpm run lint:types
11 changes: 6 additions & 5 deletions e2e/publish.test.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { exec } from "child_process";
import { platform } from "os";
import wp from "wait-port";
/* eslint-disable unicorn/no-process-exit */
import { exec } from "node:child_process";
import { platform } from "node:os";
import assert from "node:assert";
import wp from "wait-port";
import ezSpawn from "@jsdevtools/ez-spawn";
import pushWorkflowRunInProgressFixture from "./fixtures/workflow_run.in_progress.json" with { type: "json" };
import prWorkflowRunRequestedFixture from "./fixtures/pr.workflow_run.requested.json" with { type: "json" };
Expand Down Expand Up @@ -246,8 +247,8 @@ async function killPort() {
killSignal: "SIGINT",
});
}
} catch (e) {
console.error(e);
} catch (error) {
console.error(error);
c.abort();
process.exit(1);
} finally {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint": "pnpm run \"/lint:.*/\"",
"lint:js": "eslint --cache .",
"lint:format": "prettier --check --cache .",
"lint:fix": "prettier --write --cache .",
"lint:types": "pnpm -r --parallel run typecheck",
"release": "tsx script/release.ts",
"test": "tsx e2e/publish.test.mts",
Expand Down
7 changes: 1 addition & 6 deletions packages/backend/objects.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { DurableObjectState } from "@cloudflare/workers-types";
import type { Env } from "nitro-cloudflare-dev";

export class Workflows {
constructor(state: DurableObjectState, env: Env) {}

async fetch(request: Request) {
fetch() {
return new Response("Hello World");
}
}
14 changes: 8 additions & 6 deletions packages/backend/script/ci.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
if (process.env.CI) {
const content = Object.entries(process.env)
.filter(([k]) => k.startsWith("NITRO"))
.map(([k, v]) => `${k}="${v}"`)
.concat(["NITRO_TEST=true", "GITHUB_TOKEN=" + process.env.GITHUB_TOKEN!])
.join("\n");
const content = [
...Object.entries(process.env)
.filter(([k]) => k.startsWith("NITRO"))
.map(([k, v]) => `${k}="${v}"`),
"NITRO_TEST=true",
"GITHUB_TOKEN=" + process.env.GITHUB_TOKEN!,
].join("\n");
await fs.writeFile(".dev.vars", content);
}
2 changes: 1 addition & 1 deletion packages/backend/script/octokit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import esbuild from "esbuild";
import { fileURLToPath } from "node:url";
import esbuild from "esbuild";
import { polyfillNode } from "esbuild-plugin-polyfill-node";

await esbuild.build({
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/script/update-webhook-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const octokit = new Octokit({
auth: jwtToken,
});

let {
const {
data: { url },
} = await octokit.request("GET /app/hook/config");

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/server/middleware/cors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default defineEventHandler((event) => {
if (handleCors(event, {})) {
return;
console.log("CORS was successfully handled");
}
});
22 changes: 11 additions & 11 deletions packages/backend/server/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import { createAppAuth } from "@octokit/auth-app";
import { OAuthApp } from "@octokit/oauth-app";
import { Webhooks, type EmitterWebhookEvent } from "@octokit/webhooks";

import type { Octokit } from "@octokit/core";
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";

// https://github.com/octokit/app.js/blob/main/src/types.ts
import type { Endpoints } from "@octokit/types";

type Constructor<T> = new (...args: any[]) => T;

type OctokitType<TOptions extends Options> =
Expand Down Expand Up @@ -64,6 +70,7 @@ export class App<TOptions extends Options = Options> {
clientType: "github-app";
Octokit: OctokitClassType<TOptions>;
}>;

log: {
debug: (message: string, additionalInfo?: object) => void;
info: (message: string, additionalInfo?: object) => void;
Expand Down Expand Up @@ -136,9 +143,6 @@ export class App<TOptions extends Options = Options> {
}
}

import type { Octokit } from "@octokit/core";
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";

export function webhooks(
appOctokit: Octokit,
options: Required<Options>["webhooks"],
Expand Down Expand Up @@ -173,11 +177,10 @@ export function webhooks(
return new auth.octokit.constructor({
...auth.octokitOptions,
authStrategy: createAppAuth,
...{
auth: {
...auth,
installationId,
},

auth: {
...auth,
installationId,
},
});
},
Expand All @@ -201,9 +204,6 @@ export function webhooks(
});
}

// https://github.com/octokit/app.js/blob/main/src/types.ts
import type { Endpoints } from "@octokit/types";

export type Options = {
appId?: number | string;
privateKey?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/server/plugins/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default defineNitroPlugin((nitro) => {
nitro.hooks.hook("error", async (error, { event }) => {
nitro.hooks.hook("error", (error, { event }) => {
console.error(`${event?.path} Application error:`, error);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Params = Omit<WorkflowData, "sha" | "isPullRequest" | "ref"> & {
packageAndRefOrSha: string;
};

export default eventHandler(async (event) => {
export default eventHandler((event) => {
const params = getRouterParams(event) as Params;
const [noScopePackageName, refOrSha] = params.packageAndRefOrSha.split("@");
const packageName = params.npmOrg + "/" + noScopePackageName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { WorkflowData } from "../../../types";
import { abbreviateCommitHash } from "@pkg-pr-new/utils";
import { normalizeKey } from "unstorage";
import { WorkflowData } from "../../../types";

type Params = Omit<WorkflowData, "sha" | "ref"> & {
packageAndRefOrSha: string;
};

export default eventHandler(async (event) => {
const params = getRouterParams(event) as Params;
// eslint-disable-next-line prefer-const
let [encodedPackageName, longerRefOrSha] =
params.packageAndRefOrSha.split("@");
const packageName = decodeURIComponent(encodedPackageName);
Expand All @@ -17,7 +18,7 @@ export default eventHandler(async (event) => {
? abbreviateCommitHash(longerRefOrSha)
: longerRefOrSha;

let base = `${params.owner}:${params.repo}:${refOrSha}`;
const base = `${params.owner}:${params.repo}:${refOrSha}`;
let packageKey = `${base}:${packageName}`;

const cursorKey = base;
Expand Down Expand Up @@ -48,7 +49,9 @@ export default eventHandler(async (event) => {
// https://github.com/unjs/unstorage/blob/e42c01d0c22092f394f57e3ec114371fc8dcf6dd/src/drivers/utils/index.ts#L14-L19
const [keySha, ...keyPackageNameParts] = trimmedKey.split(":").slice(2);
const keyPackageName = keyPackageNameParts.join(":");
if (keyPackageName !== normalizeKey(packageName)) continue;
if (keyPackageName !== normalizeKey(packageName)) {
continue;
}

if (keySha.startsWith(longerRefOrSha)) {
packageKey = trimmedKey;
Expand Down Expand Up @@ -81,8 +84,8 @@ export default eventHandler(async (event) => {
});
});

const sha1Regex = /^[a-f0-9]{40}$/i;
const sha256Regex = /^[a-f0-9]{64}$/i;
const sha1Regex = /^[\da-f]{40}$/i;
const sha256Regex = /^[\da-f]{64}$/i;

function isValidGitHash(hash: string): boolean {
return sha1Regex.test(hash) || sha256Regex.test(hash);
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/server/routes/[owner]/[repo]/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPackageManifest } from "query-registry";
import { WorkflowData } from "../../../types";
import { extractOwnerAndRepo, extractRepository } from "@pkg-pr-new/utils";
import { WorkflowData } from "../../../types";

type Params = Omit<WorkflowData, "sha" | "ref">;

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/server/routes/[packageAndRefOrSha].get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WorkflowData } from "../types";
import { getPackageManifest } from "query-registry";
import { extractOwnerAndRepo, extractRepository } from "@pkg-pr-new/utils";
import { WorkflowData } from "../types";

type Params = Omit<WorkflowData, "sha" | "ref"> & {
packageAndRefOrSha: string;
Expand Down
6 changes: 1 addition & 5 deletions packages/backend/server/routes/multipart/complete.post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { R2UploadedPart } from "@cloudflare/workers-types";

export default eventHandler(async (event) => {
const {
key: key,
id: id,
"uploaded-parts": uploadedPartsHeader,
} = getHeaders(event);
const { key, id, "uploaded-parts": uploadedPartsHeader } = getHeaders(event);

const binding = useBinding(event);

Expand Down
6 changes: 1 addition & 5 deletions packages/backend/server/routes/multipart/upload.put.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export default eventHandler(async (event) => {
const {
key: key,
id: id,
"part-number": partNumberHeader,
} = getHeaders(event);
const { key, id, "part-number": partNumberHeader } = getHeaders(event);

const partNumber = Number(partNumberHeader);
const binding = useBinding(event);
Expand Down
Loading
Loading