-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd09611
commit 9b2523d
Showing
12 changed files
with
84 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
apps/discord-to-github-bot/src/controllers/issue-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { gaurdAgainstInvalidGetIssueParams, getAllGitHubIssues } from '../services/get-issue-templates.js' | ||
import { gaurdAgainstInvalidGetIssueParams, getAllGitHubIssues, getIssueTemplateNames } from '../services/get-issue-templates.js' | ||
import { getAccessToken } from '../services/auth.js' | ||
|
||
export async function getAllIssues(req: Record<string, any>) { | ||
const params = req.query | ||
if (!gaurdAgainstInvalidGetIssueParams(params)) { | ||
return | ||
return // SEND AN ERROR HERE --> TODO effective error handling!! | ||
} | ||
|
||
const { discordID } = params | ||
const accessToken = getAccessToken(discordID) | ||
const allIssues = getAllGitHubIssues(accessToken) | ||
return allIssues | ||
const accessToken = await getAccessToken(discordID) | ||
// ADD LOGIC HERE TO GET A SINGLE ISSUE | ||
const allIssues = await getAllGitHubIssues(accessToken) | ||
if (!allIssues) // TODO Better error handling | ||
return | ||
// Get all the issue template names | ||
const formatedIssues = getIssueTemplateNames(allIssues) | ||
return formatedIssues | ||
} |
12 changes: 12 additions & 0 deletions
12
apps/discord-to-github-bot/src/middleware/error-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { NextFunction, Request, Response } from 'express' | ||
import type { HttpException } from '../exceptions/exception' | ||
import { APP_ERROR_MESSAGE } from '../constants/constant' | ||
|
||
function errorMiddleware(error: HttpException, request: Request, response: Response, _next: NextFunction) { | ||
const status = error.status ? error.status : 500 | ||
const message = status === 500 ? APP_ERROR_MESSAGE.serverError : error.message | ||
const errors = error.error | ||
response.status(status).send({ status, message, error: errors }) | ||
} | ||
|
||
export default errorMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { Router } from 'express' | ||
import { getAllIssues } from '../controllers/issue-controller.js' | ||
import { getAllIssues } from '../controllers/issue-controller' | ||
|
||
const issueRouter = Router() | ||
|
||
issueRouter.get('/issues', (req, res) => { | ||
res.send(getAllIssues(req)) | ||
issueRouter.get('/issues', async (req, res) => { | ||
const response = await getAllIssues(req) | ||
res.status(200).send(response) | ||
}) | ||
|
||
export default issueRouter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
export interface GitHubIssue { | ||
title: string | ||
labels: string[] | ||
body: string | ||
milestone: number | ||
assignees: string[] | ||
} | ||
import type { Endpoints } from '@octokit/types' | ||
|
||
export type OctokitRepoContentResponse = Endpoints['GET /repos/{owner}/{repo}/contents/{path}']['response'] |
17 changes: 13 additions & 4 deletions
17
apps/discord-to-github-bot/tests/integration/issue.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import request from 'supertest' | ||
import app from '@src/server' | ||
import { describe, expect, it } from 'vitest' | ||
import { URLS } from '../../config' | ||
|
||
describe('get-issue template integration tests', () => { | ||
it('should send an object back of all issues', async () => { | ||
const res = await request(app).get('/api/issues') | ||
const url = res.headers.location | ||
expect(url).toBe(``) | ||
const res = await request(app).get('/api/issues?discordID=123') | ||
expect(res.body).toStrictEqual([ | ||
'architectural-design-record--adr-.md', | ||
'bug_report.md', | ||
'feature-improvement.md', | ||
'task.md', | ||
]) | ||
}) | ||
it ('should return the content of a bug issue', async () => { | ||
const res = await request(app).get('/api/issue?discordID=123&issueName=bug_report.md') | ||
expect(res.body).toEqual( | ||
'EXAMPLE OF A BUG REPORT CONTENT, INCOMPLETE FOR THE DEMO', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters