Using Typescript implement a function getGithubIssue(owner:string, repo:string,…
- User
Using Typescript implement a function
getGithubIssue(owner:string, repo:string, number:number):GithubIssue | null.It only needs to return the fields number, title, body.
The values passed in may be unsanitized
We should return
nullon a 404. A valid value on 200 throw on anything else - Assistant
To implement the
getGithubIssuefunction, you'll need to use a library that can interact with the GitHub API. I recommend using thegithub-apipackage. First, you'll need to install it:npm install github-apiNow you can implement the
getGithubIssuefunction using TypeScript:import { GitHubClient } from 'github-api'; type GithubIssue = { number: number; title: string; body: string; }; function getGithubIssue(owner: string, repo: string, number: number): GithubIssue | null { const githubClient = new GitHubClient({ auth: 'YOUR_GITHUB_ACCESS_TOKEN', // Replace with your GitHub access token }); try { const response = githubClient.issues.get({ owner, repo, number, }); if (response.status === 200) { const issue = response.data; return { number: issue.number, title: issue.title, body: issue.body, }; } else if (response.status === 404) { return null; } else { throw new Error(`Failed to get GitHub issue: ${response.status}`); } } catch (error) { throw new Error(`Error fetching GitHub issue: ${error.message}`); } } // Example usage: const owner = 'your-repo-owner'; const repo = 'your-repo-name'; const issueNumber = 123; // Replace with a valid issue number const issue = getGithubIssue(owner, repo, issueNumber); if (issue) { console.log('Issue details:', issue); } else { console.log('Issue not found'); }Replace
'YOUR_GITHUB_ACCESS_TOKEN'with your GitHub access token and the other placeholders with the appropriate values for your use case.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.