Skip to content
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

chore: run format #314

Merged
merged 1 commit into from
Jan 18, 2025
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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
170 changes: 85 additions & 85 deletions .github/workflows/stats.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
name: pkg.pr.new stats
on:
push:
jobs:
stats:
runs-on: ubuntu-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Fetch and Count Data Iteratively
uses: actions/github-script@v6
with:
script: |
async function fetchAndCountData(url) {
const counts = {
templates: 0,
packages: 0,
orgs: new Set(),
repos: new Set(),
commits: 0,
prsAndBranches: 0,
};
let cursor = null;
do {
try {
// Construct the URL with cursor if available
const fetchUrl = cursor ? `${url}?cursor=${encodeURIComponent(cursor)}` : url;
// Fetch the data from the API
const response = await fetch(fetchUrl);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const responseData = await response.json();
// Process the current page of data
if (responseData.data) {
for (const item of responseData.data) {
if (item.type === "template") {
counts.templates += 1;
} else if (item.type === "package") {
counts.packages += 1;
counts.orgs.add(item.org);
counts.repos.add(item.repo);
counts.commits += 1; // Count one commit per package
} else if (item.type === "cursor") {
counts.orgs.add(item.org);
counts.repos.add(item.repo);
// Count PR numbers and branch names combined
counts.prsAndBranches += 1;
}
}
}
// Update the cursor for the next page
cursor = responseData.nextCursor || null;
} catch (error) {
console.error(`Error fetching data: ${error.message}`);
cursor = null; // Exit the loop on error
}
} while (cursor);
return {
templates: counts.templates,
packages: counts.packages,
orgs: counts.orgs.size,
repos: counts.repos.size,
commits: counts.commits,
prsAndBranches: counts.prsAndBranches,
};
}
const url = "https://pkg.pr.new/stats";
const counts = await fetchAndCountData(url);
console.log("Counts:", counts);
name: pkg.pr.new stats

on:
push:

jobs:
stats:
runs-on: ubuntu-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Fetch and Count Data Iteratively
uses: actions/github-script@v6
with:
script: |
async function fetchAndCountData(url) {
const counts = {
templates: 0,
packages: 0,
orgs: new Set(),
repos: new Set(),
commits: 0,
prsAndBranches: 0,
};
let cursor = null;

do {
try {
// Construct the URL with cursor if available
const fetchUrl = cursor ? `${url}?cursor=${encodeURIComponent(cursor)}` : url;

// Fetch the data from the API
const response = await fetch(fetchUrl);

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const responseData = await response.json();

// Process the current page of data
if (responseData.data) {
for (const item of responseData.data) {
if (item.type === "template") {
counts.templates += 1;
} else if (item.type === "package") {
counts.packages += 1;
counts.orgs.add(item.org);
counts.repos.add(item.repo);
counts.commits += 1; // Count one commit per package
} else if (item.type === "cursor") {
counts.orgs.add(item.org);
counts.repos.add(item.repo);

// Count PR numbers and branch names combined
counts.prsAndBranches += 1;
}
}
}

// Update the cursor for the next page
cursor = responseData.nextCursor || null;
} catch (error) {
console.error(`Error fetching data: ${error.message}`);
cursor = null; // Exit the loop on error
}
} while (cursor);

return {
templates: counts.templates,
packages: counts.packages,
orgs: counts.orgs.size,
repos: counts.repos.size,
commits: counts.commits,
prsAndBranches: counts.prsAndBranches,
};
}

const url = "https://pkg.pr.new/stats";
const counts = await fetchAndCountData(url);

console.log("Counts:", counts);
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- release
pull_request:


jobs:
ci:
runs-on: [ubuntu-latest]
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm-lock.yaml
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 @@ -7,7 +7,7 @@ config({ path: ".dev.vars" });
const nitroSigner = createSigner({
algorithm: "RS256",
key: process.env.NITRO_PRIVATE_KEY!,
})
});

function generateJWT() {
const payload = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { WorkflowData } from "../../../types";
import { abbreviateCommitHash } from "@pkg-pr-new/utils";
import { normalizeKey } from 'unstorage'
import { normalizeKey } from "unstorage";

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

export default eventHandler(async (event) => {
const params = getRouterParams(event) as Params;
let [encodedPackageName, longerRefOrSha] = params.packageAndRefOrSha.split("@");
let [encodedPackageName, longerRefOrSha] =
params.packageAndRefOrSha.split("@");
const packageName = decodeURIComponent(encodedPackageName);
longerRefOrSha = longerRefOrSha.split('.tgz')[0] // yarn support
longerRefOrSha = longerRefOrSha.split(".tgz")[0]; // yarn support
const isSha = isValidGitHash(longerRefOrSha);
const refOrSha = isSha ? abbreviateCommitHash(longerRefOrSha) : longerRefOrSha;
const refOrSha = isSha
? abbreviateCommitHash(longerRefOrSha)
: longerRefOrSha;

let base = `${params.owner}:${params.repo}:${refOrSha}`;
let packageKey = `${base}:${packageName}`;
Expand All @@ -35,7 +38,9 @@ export default eventHandler(async (event) => {

// longer sha support with precision
const binding = useBinding(event);
const { objects } = await binding.list({ prefix: `${usePackagesBucket.base}:${base}` })
const { objects } = await binding.list({
prefix: `${usePackagesBucket.base}:${base}`,
});
for (const { key } of objects) {
// bucket:package:stackblitz-labs:pkg.pr.new:ded05e838c418096e5dd77a29101c8af9e73daea:playground-b
const trimmedKey = key.slice(usePackagesBucket.base.length + 1);
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/server/routes/multipart/create.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default eventHandler(async (event) => {
});
}
const workflowsBucket = useWorkflowsBucket(event);

if (!(await workflowsBucket.hasItem(workflowKey))) {
throw createError({
statusCode: 401,
Expand All @@ -37,7 +37,7 @@ export default eventHandler(async (event) => {

const binding = useBinding(event);

const base = `${workflowData.owner}:${workflowData.repo}:${workflowData.sha}`
const base = `${workflowData.owner}:${workflowData.repo}:${workflowData.sha}`;
const packageKey = `${base}:${packageName}`;

const key = joinKeys(usePackagesBucket.base, packageKey);
Expand Down
6 changes: 1 addition & 5 deletions packages/backend/server/routes/publish.post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
Comment,
isPullRequest,
isWhitelisted,
} from "@pkg-pr-new/utils";
import { Comment, isPullRequest, isWhitelisted } from "@pkg-pr-new/utils";
import { randomUUID } from "uncrypto";
import { setItemStream, useTemplatesBucket } from "~/utils/bucket";
import { useOctokitInstallation } from "~/utils/octokit";
Expand Down
Loading
Loading