Skip to content

Commit

Permalink
Merge pull request #87 from DeadSpoon18/feature/githubIssue
Browse files Browse the repository at this point in the history
Create Issue on this repo using Github API.
  • Loading branch information
AasthaMehtaTech authored Oct 17, 2020
2 parents 0335f5c + 69e9347 commit d277df9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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}`);
Expand Down
28 changes: 28 additions & 0 deletions routes/issueRoute.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit d277df9

Please sign in to comment.