Skip to content

Commit

Permalink
feat: add @linear/sdk dependency and integrate Linear API client
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheem4 committed Jan 19, 2025
1 parent aa4af34 commit 7e5442f
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 42 deletions.
92 changes: 92 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@clerk/clerk-sdk-node": "5.1.6",
"@linear/sdk": "37.0.0",
"@modelcontextprotocol/sdk": "0.6.0",
"@octokit/auth-token": "5.1.1",
"@octokit/rest": "21.1.0",
Expand Down
77 changes: 35 additions & 42 deletions src/api/routes/pullRequests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import express from "express";
import { Octokit } from "@octokit/rest";
import { config } from "../../config/index.js";
import { LinearClient } from "@linear/sdk";

const linearClient = new LinearClient({
apiKey: config.linear.apiKey,
});

export const router = express.Router();

Expand All @@ -20,36 +25,6 @@ interface CreatePRBody {
issueIds?: string[];
}

const getDiffContent = async (
owner: string,
repo: string,
pullNumber: number
) => {
const octokit = new Octokit({
auth: config.github.privateKey,
});

const { data: comparison } = await octokit.repos.compareCommits({
owner,
repo,
base: "main",
head: "dev",
});

return (
comparison.files?.map((file) => ({
file: file.filename,
additions: file.additions,
deletions: file.deletions,
changes:
file.patch
?.split("\n")
.filter((line) => line.startsWith("+") && !line.startsWith("+++"))
.map((line) => line.substring(1)) || [],
})) || []
);
};

const formatPRDescription = async (
owner: string,
repo: string,
Expand All @@ -58,40 +33,58 @@ const formatPRDescription = async (
): Promise<string> => {
const template = `## Overview
Provide a high-level summary of the purpose of this PR. Mention the problem it solves or the feature it introduces.
${
data.overview ||
"Provide a high-level summary of the purpose of this PR. What problem does it solve or what feature does it add?"
}
## Key Changes
${
data.keyChanges?.map((change) => `- ${change}`).join("\n") ||
"Summarize the important changes made in this PR. Use bullet points for clarity."
"List the specific changes made in this PR:"
}
_Example:_
- Implemented new authentication flow
- Added form validation
- Updated API endpoints
## Code Highlights
${
data.codeHighlights?.map((highlight) => `- ${highlight}`).join("\n") ||
"Mention specific code changes or configurations that are worth noting. This helps reviewers focus on critical areas."
"Highlight important code changes that reviewers should focus on:"
}
_Example:_
- New middleware implementation in \`auth.ts\`
- Updated database schema in \`models/user.ts\`
- Added validation logic in \`utils/validate.ts\`
## Testing
${
data.testing?.map((test) => `- ${test}`).join("\n") ||
"Describe how the changes were tested and any relevant test results. Ensure the PR includes all necessary tests and indicate the environment where tests were performed."
"Describe how these changes were tested:"
}
_Example:_
- Added unit tests for auth flow
- Tested form validation with various inputs
- Verified API responses in staging environment
## Checklist
- [ ] Code follows project standards
- [ ] All tests passing
- [ ] Documentation updated (if applicable)
- [ ] Tested in staging environment
- [ ] Includes relevant screenshots, diagrams, or videos demonstrating the change
- [ ] Screenshots/recordings added for UI changes
## Links
- [Staging Environment preview](https://app-staging.getarchitecthealth.com/)${
- [Staging Environment](https://app-staging.getarchitecthealth.com/)${
data.links?.length
? "\n" +
data.links.map((link) => `- [${link.title}](${link.url})`).join("\n")
Expand All @@ -100,23 +93,23 @@ ${
## Attachments
<!-- Screenshots will be added during review if needed -->
<!-- Add screenshots, videos, or diagrams that help explain the changes -->
## Additional Notes
${
data.additionalNotes ||
"Add any additional information that the reviewer might need to know. Mention pending tasks or technical debt, if any."
"Include any additional context, technical debt notes, or follow-up tasks."
}
---
### Linear Issue Tagging
${
data.issueIds?.length
? data.issueIds.map((id) => `fixes ${id}`).join("\n")
: "**Format:** Use `fixes {LINEAR_ISSUE_ID}` or `closes {LINEAR_ISSUE_ID}` to automatically link and close issues on Linear when the PR is merged."
? `## Linear Tickets
${data.issueIds.map((id) => `- fixes ${id}`).join("\n")}`
: ""
}`;

return template;
Expand Down
6 changes: 6 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ interface Config {
privateKey: string;
webhookSecret: string;
};
linear: {
apiKey: string;
};
}

// In production, these would be loaded from environment variables
Expand Down Expand Up @@ -49,4 +52,7 @@ export const config: Config = {
privateKey: process.env.GITHUB_PRIVATE_KEY || "",
webhookSecret: process.env.GITHUB_WEBHOOK_SECRET || "",
},
linear: {
apiKey: process.env.LINEAR_API_KEY || "",
},
};

0 comments on commit 7e5442f

Please sign in to comment.