mirror of
https://github.com/cloudflare/cloudflare-docs.git
synced 2026-01-16 23:11:06 +00:00
chore: format ts (#16838)
Co-authored-by: kodster28 <kody@cloudflare.com>
This commit is contained in:
parent
943459fed2
commit
3dd03fdad7
8 changed files with 150 additions and 148 deletions
160
.github/actions/label-products/index.ts
vendored
160
.github/actions/label-products/index.ts
vendored
|
|
@ -1,115 +1,113 @@
|
|||
// NOTE: This is the source file!
|
||||
// ~> Run `npm run build` to produce `index.js`
|
||||
|
||||
import * as github from '@actions/github';
|
||||
import * as core from '@actions/core';
|
||||
import * as github from "@actions/github";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
function getTopLevelFolder(path: string): string {
|
||||
const parts = path.split('/');
|
||||
return parts[2];
|
||||
const parts = path.split("/");
|
||||
return parts[2];
|
||||
}
|
||||
|
||||
|
||||
function getSubFolder(path: string): string {
|
||||
const parts = path.split('/');
|
||||
return parts[3];
|
||||
const parts = path.split("/");
|
||||
return parts[3];
|
||||
}
|
||||
|
||||
function getChangedSubFolders(files: any[]): string[] {
|
||||
const changedFolders = new Set<string>();
|
||||
const changedFolders = new Set<string>();
|
||||
|
||||
for (const file of files) {
|
||||
const path = file.filename;
|
||||
const topLevelFolder = getTopLevelFolder(path);
|
||||
for (const file of files) {
|
||||
const path = file.filename;
|
||||
const topLevelFolder = getTopLevelFolder(path);
|
||||
|
||||
// Check if the file is within the top-level /content folder
|
||||
if (topLevelFolder === 'docs') {
|
||||
const subFolder = getSubFolder(path);
|
||||
changedFolders.add(subFolder);
|
||||
}
|
||||
}
|
||||
// Check if the file is within the top-level /content folder
|
||||
if (topLevelFolder === "docs") {
|
||||
const subFolder = getSubFolder(path);
|
||||
changedFolders.add(subFolder);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(changedFolders);
|
||||
return Array.from(changedFolders);
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const ctx = github.context;
|
||||
const token = core.getInput('GITHUB_TOKEN', { required: true });
|
||||
const octokit = github.getOctokit(token);
|
||||
const pr = ctx.payload.pull_request;
|
||||
const prNumber = pr.number;
|
||||
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
|
||||
...ctx.repo,
|
||||
pull_number: pr.number,
|
||||
per_page: 100,
|
||||
});
|
||||
try {
|
||||
const ctx = github.context;
|
||||
const token = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
const octokit = github.getOctokit(token);
|
||||
const pr = ctx.payload.pull_request;
|
||||
const prNumber = pr.number;
|
||||
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
|
||||
...ctx.repo,
|
||||
pull_number: pr.number,
|
||||
per_page: 100,
|
||||
});
|
||||
|
||||
// Get the changed sub-folders within the top-level /content folder
|
||||
const changedFolders = getChangedSubFolders(files);
|
||||
// Get the changed sub-folders within the top-level /content folder
|
||||
const changedFolders = getChangedSubFolders(files);
|
||||
|
||||
// ...
|
||||
// ...
|
||||
|
||||
// Label the PR based on the changed sub-folders
|
||||
await labelPRSubFolders(octokit, ctx.repo, prNumber, changedFolders);
|
||||
// Label the PR based on the changed sub-folders
|
||||
await labelPRSubFolders(octokit, ctx.repo, prNumber, changedFolders);
|
||||
|
||||
// ...
|
||||
} catch (error) {
|
||||
console.error('An error occurred:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
// ...
|
||||
} catch (error) {
|
||||
console.error("An error occurred:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function labelPRSubFolders(
|
||||
octokit: any,
|
||||
repo: any,
|
||||
prNumber: number,
|
||||
changedFolders: string[]
|
||||
octokit: any,
|
||||
repo: any,
|
||||
prNumber: number,
|
||||
changedFolders: string[],
|
||||
): Promise<void> {
|
||||
const labelPrefix = 'product:';
|
||||
const labelsToRemove: string[] = [];
|
||||
const labelsToAdd: string[] = [];
|
||||
const labelPrefix = "product:";
|
||||
const labelsToRemove: string[] = [];
|
||||
const labelsToAdd: string[] = [];
|
||||
|
||||
for (const label of github.context.payload.pull_request.labels) {
|
||||
if (label.name.startsWith(labelPrefix)) {
|
||||
labelsToRemove.push(label.name);
|
||||
}
|
||||
}
|
||||
for (const label of github.context.payload.pull_request.labels) {
|
||||
if (label.name.startsWith(labelPrefix)) {
|
||||
labelsToRemove.push(label.name);
|
||||
}
|
||||
}
|
||||
|
||||
for (const folder of changedFolders) {
|
||||
const label = labelPrefix + folder;
|
||||
labelsToAdd.push(label);
|
||||
}
|
||||
for (const folder of changedFolders) {
|
||||
const label = labelPrefix + folder;
|
||||
labelsToAdd.push(label);
|
||||
}
|
||||
|
||||
const currentLabels = new Set(
|
||||
github.context.payload.pull_request.labels.map((label: any) => label.name)
|
||||
);
|
||||
const currentLabels = new Set(
|
||||
github.context.payload.pull_request.labels.map((label: any) => label.name),
|
||||
);
|
||||
|
||||
for (const labelToRemove of labelsToRemove) {
|
||||
if (!labelsToAdd.includes(labelToRemove)) {
|
||||
await octokit.rest.issues.removeLabel({
|
||||
...repo,
|
||||
issue_number: prNumber,
|
||||
name: labelToRemove,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const labelToRemove of labelsToRemove) {
|
||||
if (!labelsToAdd.includes(labelToRemove)) {
|
||||
await octokit.rest.issues.removeLabel({
|
||||
...repo,
|
||||
issue_number: prNumber,
|
||||
name: labelToRemove,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let newLabels: string[] = [];
|
||||
for (const labelToAdd of labelsToAdd) {
|
||||
if (!currentLabels.has(labelToAdd)) {
|
||||
newLabels.push(labelToAdd);
|
||||
}
|
||||
}
|
||||
let newLabels: string[] = [];
|
||||
for (const labelToAdd of labelsToAdd) {
|
||||
if (!currentLabels.has(labelToAdd)) {
|
||||
newLabels.push(labelToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
if (newLabels.length > 0) {
|
||||
await octokit.rest.issues.addLabels({
|
||||
...repo,
|
||||
issue_number: prNumber,
|
||||
labels: newLabels,
|
||||
});
|
||||
}
|
||||
if (newLabels.length > 0) {
|
||||
await octokit.rest.issues.addLabels({
|
||||
...repo,
|
||||
issue_number: prNumber,
|
||||
labels: newLabels,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
|
|
|
|||
111
.github/actions/label-size/index.ts
vendored
111
.github/actions/label-size/index.ts
vendored
|
|
@ -1,67 +1,68 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import * as core from "@actions/core";
|
||||
import * as github from "@actions/github";
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const ctx = github.context;
|
||||
const token = core.getInput('GITHUB_TOKEN', { required: true });
|
||||
const octokit = github.getOctokit(token);
|
||||
const pr = ctx.payload.pull_request;
|
||||
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
|
||||
...ctx.repo,
|
||||
pull_number: pr.number,
|
||||
per_page: 100
|
||||
});
|
||||
try {
|
||||
const ctx = github.context;
|
||||
const token = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
const octokit = github.getOctokit(token);
|
||||
const pr = ctx.payload.pull_request;
|
||||
const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
|
||||
...ctx.repo,
|
||||
pull_number: pr.number,
|
||||
per_page: 100,
|
||||
});
|
||||
|
||||
const changes = files.reduce((total, file) => total + file.changes, 0);
|
||||
const changes = files.reduce((total, file) => total + file.changes, 0);
|
||||
|
||||
let label: string | undefined;
|
||||
let label: string | undefined;
|
||||
|
||||
switch (true) {
|
||||
case changes <= 10:
|
||||
label = 'size/xs';
|
||||
break;
|
||||
case changes <= 100:
|
||||
label = 'size/s';
|
||||
break;
|
||||
case changes <= 500:
|
||||
label = 'size/m';
|
||||
break;
|
||||
case changes <= 1000:
|
||||
label = 'size/l';
|
||||
break;
|
||||
default:
|
||||
label = 'size/xl';
|
||||
break;
|
||||
}
|
||||
switch (true) {
|
||||
case changes <= 10:
|
||||
label = "size/xs";
|
||||
break;
|
||||
case changes <= 100:
|
||||
label = "size/s";
|
||||
break;
|
||||
case changes <= 500:
|
||||
label = "size/m";
|
||||
break;
|
||||
case changes <= 1000:
|
||||
label = "size/l";
|
||||
break;
|
||||
default:
|
||||
label = "size/xl";
|
||||
break;
|
||||
}
|
||||
|
||||
const currentLabels = pr.labels.map((label) => label.name);
|
||||
const sizeLabels = ['size/xs', 'size/s', 'size/m', 'size/l', 'size/xl'];
|
||||
const currentLabels = pr.labels.map((label) => label.name);
|
||||
const sizeLabels = ["size/xs", "size/s", "size/m", "size/l", "size/xl"];
|
||||
|
||||
// Remove previous size-related labels that are different from the current label
|
||||
const labelsToRemove = currentLabels.filter(
|
||||
(currentLabel) => sizeLabels.includes(currentLabel) && currentLabel !== label
|
||||
);
|
||||
// Remove previous size-related labels that are different from the current label
|
||||
const labelsToRemove = currentLabels.filter(
|
||||
(currentLabel) =>
|
||||
sizeLabels.includes(currentLabel) && currentLabel !== label,
|
||||
);
|
||||
|
||||
for (const labelToRemove of labelsToRemove) {
|
||||
await octokit.rest.issues.removeLabel({
|
||||
...ctx.repo,
|
||||
issue_number: pr.number,
|
||||
name: labelToRemove
|
||||
});
|
||||
}
|
||||
for (const labelToRemove of labelsToRemove) {
|
||||
await octokit.rest.issues.removeLabel({
|
||||
...ctx.repo,
|
||||
issue_number: pr.number,
|
||||
name: labelToRemove,
|
||||
});
|
||||
}
|
||||
|
||||
// Add the current label
|
||||
if (!currentLabels.includes(label)) {
|
||||
await octokit.rest.issues.addLabels({
|
||||
...ctx.repo,
|
||||
issue_number: pr.number,
|
||||
labels: [label]
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
// Add the current label
|
||||
if (!currentLabels.includes(label)) {
|
||||
await octokit.rest.issues.addLabels({
|
||||
...ctx.repo,
|
||||
issue_number: pr.number,
|
||||
labels: [label],
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
|
|||
2
src/content/docs/src/env.d.ts
vendored
2
src/content/docs/src/env.d.ts
vendored
|
|
@ -1 +1 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
||||
/// <reference path="../.astro/types.d.ts" />
|
||||
|
|
|
|||
2
src/env.d.ts
vendored
2
src/env.d.ts
vendored
|
|
@ -1 +1 @@
|
|||
/// <reference path="../.astro/types.d.ts" />
|
||||
/// <reference path="../.astro/types.d.ts" />
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import { getEntry } from "astro:content";
|
||||
|
||||
export async function GET() {
|
||||
const entries = await getEntry("pages-framework-presets", "index");
|
||||
const entries = await getEntry("pages-framework-presets", "index");
|
||||
|
||||
const sorted = Object.fromEntries(Object.entries(entries.data.build_configs).sort())
|
||||
const sorted = Object.fromEntries(
|
||||
Object.entries(entries.data.build_configs).sort(),
|
||||
);
|
||||
|
||||
return Response.json(sorted);
|
||||
}
|
||||
return Response.json(sorted);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,5 +19,5 @@ export async function entryToString(entry: CollectionEntry<"docs">) {
|
|||
params: { slug: entry.slug },
|
||||
});
|
||||
|
||||
return html;
|
||||
return html;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { CollectionEntry } from "astro:content";
|
||||
import { parse } from "node-html-parser";
|
||||
import { entryToString } from "./container"
|
||||
import { entryToString } from "./container";
|
||||
/*
|
||||
1. If there is a `description` property in the frontmatter, return that.
|
||||
2. If there is a `<p>...</p>` element in the HTML, return that.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
export function sortBySidebarOrder(a: any, b: any): number {
|
||||
const collator = new Intl.Collator("en");
|
||||
const collator = new Intl.Collator("en");
|
||||
|
||||
if (a.data.sidebar.order !== b.data.sidebar.order) return a.data.sidebar.order - b.data.sidebar.order;
|
||||
if (a.data.sidebar.order !== b.data.sidebar.order)
|
||||
return a.data.sidebar.order - b.data.sidebar.order;
|
||||
|
||||
return collator.compare(a.data.title, b.data.title);
|
||||
}
|
||||
return collator.compare(a.data.title, b.data.title);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue