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

Move website #5792

Merged
merged 452 commits into from
Mar 2, 2024
Merged

Move website #5792

merged 452 commits into from
Mar 2, 2024

Conversation

rluvaton
Copy link
Member

@rluvaton rluvaton commented Jan 21, 2024

TODO

  • run git subtree add -P docs https://github.com/knex/documentation.git HEAD to move the website into a subfolder
  • Update .github folder to include the website
  • deploy the website only on changes in the docs folder
    • test that it only happens in those changes that are pushed to main (we will see this after this pr is merged) - fix docs deployment #5870
    • test that docs-deploy workflow run under docs folder (we will see this when the pr is merged)
  • Try to avoid having 2 package.json (will be in next pr that will move to either npm or yarn workspaces)
  • don't include the website in the published lib (it's not in the lib value in package.json so all good)
  • Migrate issues from the docs repo (after this pr is merged - there is a script to do that in the scripts section below)
  • Mark the website repo archived (after this pr is merged)
  • add in the docs repo README explanation that it moved to knex (after this pr is merged) - Add note that the documentation has been moved documentation#577
  • Add to the https://github.com/knex/documentation repo issues the website label before moving to this repo
  • Add comment to every PR in the website if they can create it in this repo instead (after this pr is merged, the script for this is at the script section below)
  • Add issue template to make the developer check (did you update the docs, did you update the types) in the next pr
  • Update GitHub link and edit this page in website to point to this repo
  • Change the knex version that the docs used to be the latest released one (in the next pr)

Notes

  1. Had to run format on the website folder as well as it failed
  2. The legacy type lint is failing and seems to also fail on master, so we should look at it, but it should not block this pr.
Run npm run lint:types:legacy

> [email protected] lint:types:legacy
> dtslint types

TypeError: (0 , utils_1.installAllTypeScriptVersions) is not a function

Scripts

The script used to add the labels to the docs repo
import {Octokit} from "@octokit/core";
const token = "<token>";

// Octokit.js
// https://github.com/octokit/core.js#readme
const octokit = new Octokit({
  auth: token,
});

async function addLabelsToIssue(issueNumber) {
  await octokit.request("POST /repos/{owner}/{repo}/issues/{issue_number}/labels", {
    owner: "knex",
    repo: "documentation",
    issue_number: issueNumber,
    labels: ["website"],
  });
}

async function removeLabelsFromIssue(issueNumber) {
  // Remove the website label
  await octokit.request(
    "DELETE /repos/{owner}/{repo}/issues/{issue_number}/labels/{name}",
    {
      owner: "knex",
      repo: "documentation",
      issue_number: issueNumber,
      name: "website",
      headers: {
        "X-GitHub-Api-Version": "2022-11-28",
      },
    }
  );
}


async function getAllIssues(pageNumber = 1) {
  const {status, data} = await octokit.request("GET /repos/{owner}/{repo}/issues", {
    owner: "knex",
    repo: "documentation",
    state: "all",
    // max is 100
    per_page: 100,
    page: pageNumber,
    headers: {
      "X-GitHub-Api-Version": "2022-11-28",
    },
  });

  if(status > 299) {
    console.error("Error getting issues", status, data);
    throw new Error("Error getting issues");
  }

  const onlyIssues = filterOutPrs(data)

  // Reached the end of the issues
  if(data.length < 100) {
    return onlyIssues;
  }

  return onlyIssues.concat(await getAllIssues(pageNumber + 1));
}

function filterOutPrs(issuesAndPrs) {
  return issuesAndPrs.filter(issue => !issue.pull_request);
}

console.log("Getting all issues...");

// Sort from oldest to newest
const issues = (await getAllIssues()).sort((a, b) => a.number - b.number);

console.log(issues.length);

console.log("Adding labels to issues...");

let i = 0;
// Update issues from oldest to newest so the ending update time is the latest issue
for(const issue of issues) {
  console.log(`${i}/${issues.length} Adding label`)
  await addLabelsToIssue(issue.number);
  console.log(`${i}/${issues.length} Label added`);
  i++;
}

console.log('Added labels to all issues');
Transfer all docs issues to this repo
import {Octokit} from "@octokit/core";
const token = "<token>";

// Octokit.js
// https://github.com/octokit/core.js#readme
const octokit = new Octokit({
  auth: token,
});

async function getAllIssues(pageNumber = 1) {
  const {status, data} = await octokit.request("GET /repos/{owner}/{repo}/issues", {
    owner: "knex",
    repo: "documentation",
    state: "all",
    // max is 100
    per_page: 100,
    page: pageNumber,
    headers: {
      "X-GitHub-Api-Version": "2022-11-28",
    },
  });

  if(status > 299) {
    console.error("Error getting issues", status, data);
    throw new Error("Error getting issues");
  }

  const onlyIssues = filterOutPrs(data)

  // Reached the end of the issues
  if(data.length < 100) {
    return onlyIssues;
  }

  return onlyIssues.concat(await getAllIssues(pageNumber + 1));
}

function filterOutPrs(issuesAndPrs) {
  return issuesAndPrs.filter(issue => !issue.pull_request);
}

console.log("Getting all issues...");

// Sort from oldest to newest
const issues = (await getAllIssues()).sort((a, b) => a.number - b.number);

console.log(issues.length);

const command = issues
  .map((issue) => `gh issue transfer ${issue.number} knex/knex`)
  .join("\n");

console.log(
  "Run the following command in the knex/documentation repo to transfer all issues to the knex/knex repo"
);
console.log(command);
Add comment to every open pr to notify the repo moved
import { Octokit } from "@octokit/core";
const token = "token";

// Octokit.js
// https://github.com/octokit/core.js#readme
const octokit = new Octokit({
  auth: token,
});

async function getAllPrs(pageNumber = 1) {
  const { status, data } = await octokit.request(
    "GET /repos/{owner}/{repo}/issues",
    {
      owner: "knex",
      repo: "documentation",
      state: "open",
      // max is 100
      per_page: 100,
      page: pageNumber,
      headers: {
        "X-GitHub-Api-Version": "2022-11-28",
      },
    }
  );

  if (status > 299) {
    console.error("Error getting prs", status, data);
    throw new Error("Error getting prs");
  }

  const onlyPrs = filterOutIssues(data);

  // Reached the end of the prs
  if (data.length < 100) {
    return onlyPrs;
  }

  return onlyPrs.concat(await getAllPrs(pageNumber + 1));
}

function filterOutIssues(issuesAndPrs) {
  return issuesAndPrs.filter((issue) => issue.pull_request);
}

async function addCommentToPr(prNumber) {
  await octokit.request(
    "POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
    {
      owner: "knex",
      repo: "documentation",
      issue_number: prNumber,
      body: "The website repo has been moved inside the https://github.com/knex/knex repo. Please open a PR there instead: (the website will be under the `docs` folder)",
      headers: {
        "X-GitHub-Api-Version": "2022-11-28",
      },
    }
  );
}

console.log("Getting all prs...");

// Sort from oldest to newest
const prs = (await getAllPrs()).sort((a, b) => a.number - b.number);

console.log(`Adding comment to ${prs.length} open prs`);
let i = 0;
for(const pr of prs) {
  console.log(`${i}/${prs.length} comment added to pr ${pr.number}`);
  await addCommentToPr(pr.number);
  console.log(`${i}/${prs.length} comment added to pr ${pr.number}`);
  i++;
}

console.log('Added comments to all open prs');

kibertoad and others added 30 commits May 30, 2019 14:32
Add notes around usage with typescript
* Mark generated files as binary so they don't clobber the diff

* Tweak build scripts

- Replace child-process-promise with execa which already handles SIGINT propagation & PATHEXT normalization
- Read CHANGELOG from node_modules/knex so that it works well with npm/yarn link and nodemon can pickup changes
- Tweak nodemon to auto restart when CHANGELOG changes
- Remove misleading log that rs will restart nodemon which doesn't work with spawn
Remove unnecessary parentheses
* noted that aliasing uses a suffix, not a prefix
* added an example
@coveralls
Copy link

coveralls commented Jan 21, 2024

Coverage Status

coverage: 92.842%. remained the same
when pulling 10bd5cd on move-website
into 3764ded on master.

@rluvaton rluvaton marked this pull request as ready for review January 31, 2024 10:31
CONTRIBUTING.md Outdated Show resolved Hide resolved
@rluvaton rluvaton merged commit a58208c into master Mar 2, 2024
37 of 38 checks passed
@rluvaton rluvaton deleted the move-website branch March 2, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.