From 69e93472b54d3e7adbaa18069e95a87f34af5577 Mon Sep 17 00:00:00 2001 From: Kartik Singh Date: Thu, 1 Oct 2020 02:56:49 +0530 Subject: [PATCH] github issue route --- app.js | 2 ++ routes/issueRoute.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 routes/issueRoute.js diff --git a/app.js b/app.js index 4e3d141..a8a59d5 100644 --- a/app.js +++ b/app.js @@ -5,6 +5,7 @@ const cors = require('cors'); const elementRouter = require("./routes/elementRoute"); const authRouter = require("./routes/authRoute"); +const issueRoute = require("./routes/issueRoute"); const connectDB = require("./config/db"); @@ -30,6 +31,7 @@ app.use(passport.session()); app.use("/api/elements", elementRouter); app.use("/api/auth", authRouter); +app.use("/api/createIssue", issueRoute); app.listen(port, () => { console.log(`Server is up on port ${port}`); diff --git a/routes/issueRoute.js b/routes/issueRoute.js new file mode 100644 index 0000000..b484edb --- /dev/null +++ b/routes/issueRoute.js @@ -0,0 +1,28 @@ +const express = require("express"); +const fetch = require("node-fetch"); +const router = express.Router(); + +router.post("/", async (req, res) => { + try { + const token = req.body.gitToken; + const url = "https://api.github.com/repos/AasthaGithub/Elemento/issues"; + const headers = { + "Authorization": `Token ${token}`, + }; + const payLoad = { + title: req.body.title, + body: req.body.body, + }; + const response = await fetch(url, { + method: "POST", + headers: headers, + body: JSON.stringify(payLoad), + }); + const result = await response.json(); + res.json({ message: "Issue created." }); + } catch (error) { + console.error(error); + } +}); + +module.exports = router; \ No newline at end of file