Skip to content

Commit

Permalink
Merge pull request #27 from kunai-consulting/linear-soc2
Browse files Browse the repository at this point in the history
feat: replace existing logic with changesets read package
  • Loading branch information
thejackshelton-kunaico authored Aug 22, 2024
2 parents 4fe8671 + 14a52ad commit 97c6e77
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 40 deletions.
73 changes: 34 additions & 39 deletions .github/scripts/update-linear.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LinearClient } from "@linear/sdk";
import path from "node:path";
import fs from "node:fs";
import read from "@changesets/read";

const linearClient = new LinearClient({ apiKey: process.env.LINEAR_API_KEY });

Expand All @@ -11,41 +10,45 @@ const prTitle = process.env.PR_TITLE || "No PR Title";
let prDescription: string;

// Read contents of .changeset directory
function readChangesetFiles() {
async function readChangesetFiles() {
try {
const changesetDir = path.join(process.cwd(), ".changeset");
console.log("Changeset directory:", changesetDir);

if (!fs.existsSync(changesetDir)) {
console.log(".changeset directory does not exist");
return;
const changesets = await read(process.cwd());
const packageChanges: Record<
string,
Array<{ type: string; summary: string }>
> = {};

for (const changeset of changesets) {
for (const release of changeset.releases) {
if (!packageChanges[release.name]) {
packageChanges[release.name] = [];
}
packageChanges[release.name].push({
type: release.type,
summary: changeset.summary,
});
}
}

const files = fs.readdirSync(changesetDir);
console.log("Files in .changeset directory:", files);
prDescription = `
## Release Summary
if (files.length === 0) {
console.log("No files found in .changeset directory");
return;
}
This issue tracks the changes for the upcoming release of the Qwik Design System.
for (const file of files) {
if (path.extname(file) === ".md") {
try {
const filePath = path.join(changesetDir, file);
console.log("Reading file:", filePath);
const content = fs.readFileSync(filePath, "utf-8");
prDescription += `\n\nChangeset ${file}:\n${content}`;
console.log(`Successfully read ${file}`);
} catch (fileError) {
console.error(`Error reading file ${file}:`, fileError);
}
Project: https://github.com/kunai-consulting/qwik-design-system
`;

for (const [packageName, changes] of Object.entries(packageChanges)) {
prDescription += `### ${packageName}\n\n`;
for (const change of changes) {
prDescription += `- **${change.type}**:\n ${change.summary}\n`;
}
prDescription += "\n";
}

console.log("Final prDescription length:", prDescription.length);
} catch (error) {
console.error("Error in readChangesetFiles:", error);
console.error("Error reading changesets:", error);
process.exit(1);
}
}

Expand Down Expand Up @@ -74,11 +77,7 @@ async function createLinearReleaseIssue() {
const issue = await linearClient.createIssue({
teamId: team.id,
title: prTitle,
description: `
project: https://github.com/kunai-consulting/kunai-design-system
${prDescription}
`,
description: prDescription,
projectId: project.id,
});

Expand All @@ -88,11 +87,7 @@ async function createLinearReleaseIssue() {
// when we add new changesets before the release
async function updateLinearReleaseIssue() {
const updatedIssue = await linearClient.updateIssue(existingIssue.id, {
description: `
project: https://github.com/kunai-consulting/kunai-design-system
${prDescription}
`,
description: prDescription,
});

return updatedIssue;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"changeset": "changeset",
"publish:packages": "changeset publish",
"version:packages": "changeset version",
"create-linear-issue": "vite-node .github/scripts/create-linear-issue.ts"
"create-linear-issue": "vite-node .github/scripts/update-linear.ts"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@changesets/cli": "^2.27.7",
"@changesets/read": "^0.6.0",
"@linear/sdk": "^27.0.0",
"@playwright/test": "^1.46.0",
"@types/node": "20.14.11",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 97c6e77

Please sign in to comment.