From 395fc9d0e5cd7dfaff9886d5ebee5c9d88f14ba0 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 19 Apr 2018 01:13:54 +0900 Subject: [PATCH 01/26] =?UTF-8?q?feat(#81):=20token=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20scope=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/urlManager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/urlManager.js b/src/utils/urlManager.js index 35221a9..39d61b7 100644 --- a/src/utils/urlManager.js +++ b/src/utils/urlManager.js @@ -61,8 +61,10 @@ export default { * @returns {string} 새 토큰을 생성하는 페이지 URL */ getNewTokenPageUrl: function () { + const scopes = ["repo", "notifications"]; + return `${location.protocol}//${location.host}/settings/tokens/new?` + - `scopes=repo&description=SmartGithub(${location.host})`; + `scopes=${scopes.join(",")}&description=SmartGithub(${location.host})`; }, /** * 현재 페이지에 적용된 템플릿의 이름을 알려주는 함수 From f17296fcefa5b406ce76737c9f23e9ab2bdb2555 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 19 Apr 2018 01:44:10 +0900 Subject: [PATCH 02/26] =?UTF-8?q?feat(#81):=20notifications=20permission?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/manifest.json b/src/manifest.json index 9269d0f..3fbb881 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -40,7 +40,8 @@ "permissions": [ "tabs", "webNavigation", - "storage" + "storage", + "notifications" ], "default_locale": "en", From 90eeaab2a4728b2248e8650dd3f02c510b541144 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 19 Apr 2018 23:24:17 +0900 Subject: [PATCH 03/26] =?UTF-8?q?refact(#81):=20frontend/backend=20?= =?UTF-8?q?=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .babelrc => frontend/.babelrc | 0 .gitignore => frontend/.gitignore | 0 package.json => frontend/package.json | 0 {src => frontend/src}/_locales/en/messages.json | 0 {src => frontend/src}/_locales/ko/messages.json | 0 {src => frontend/src}/background.js | 0 {src => frontend/src}/consts/index.js | 0 {src => frontend/src}/content.css | 0 {src => frontend/src}/content.js | 0 {src => frontend/src}/icons/logo128.png | Bin {src => frontend/src}/icons/logo16.png | Bin {src => frontend/src}/icons/logo24.png | Bin {src => frontend/src}/icons/logo32.png | Bin {src => frontend/src}/icons/logo48.png | Bin {src => frontend/src}/icons/logo64.png | Bin {src => frontend/src}/manifest.json | 0 {src => frontend/src}/popup.css | 0 {src => frontend/src}/popup.html | 0 {src => frontend/src}/popup.js | 0 {src => frontend/src}/utils/dom.js | 0 {src => frontend/src}/utils/fetcher.js | 0 {src => frontend/src}/utils/index.js | 0 {src => frontend/src}/utils/storage.js | 0 {src => frontend/src}/utils/urlManager.js | 0 webpack.config.js => frontend/webpack.config.js | 0 25 files changed, 0 insertions(+), 0 deletions(-) rename .babelrc => frontend/.babelrc (100%) rename .gitignore => frontend/.gitignore (100%) rename package.json => frontend/package.json (100%) rename {src => frontend/src}/_locales/en/messages.json (100%) rename {src => frontend/src}/_locales/ko/messages.json (100%) rename {src => frontend/src}/background.js (100%) rename {src => frontend/src}/consts/index.js (100%) rename {src => frontend/src}/content.css (100%) rename {src => frontend/src}/content.js (100%) rename {src => frontend/src}/icons/logo128.png (100%) rename {src => frontend/src}/icons/logo16.png (100%) rename {src => frontend/src}/icons/logo24.png (100%) rename {src => frontend/src}/icons/logo32.png (100%) rename {src => frontend/src}/icons/logo48.png (100%) rename {src => frontend/src}/icons/logo64.png (100%) rename {src => frontend/src}/manifest.json (100%) rename {src => frontend/src}/popup.css (100%) rename {src => frontend/src}/popup.html (100%) rename {src => frontend/src}/popup.js (100%) rename {src => frontend/src}/utils/dom.js (100%) rename {src => frontend/src}/utils/fetcher.js (100%) rename {src => frontend/src}/utils/index.js (100%) rename {src => frontend/src}/utils/storage.js (100%) rename {src => frontend/src}/utils/urlManager.js (100%) rename webpack.config.js => frontend/webpack.config.js (100%) diff --git a/.babelrc b/frontend/.babelrc similarity index 100% rename from .babelrc rename to frontend/.babelrc diff --git a/.gitignore b/frontend/.gitignore similarity index 100% rename from .gitignore rename to frontend/.gitignore diff --git a/package.json b/frontend/package.json similarity index 100% rename from package.json rename to frontend/package.json diff --git a/src/_locales/en/messages.json b/frontend/src/_locales/en/messages.json similarity index 100% rename from src/_locales/en/messages.json rename to frontend/src/_locales/en/messages.json diff --git a/src/_locales/ko/messages.json b/frontend/src/_locales/ko/messages.json similarity index 100% rename from src/_locales/ko/messages.json rename to frontend/src/_locales/ko/messages.json diff --git a/src/background.js b/frontend/src/background.js similarity index 100% rename from src/background.js rename to frontend/src/background.js diff --git a/src/consts/index.js b/frontend/src/consts/index.js similarity index 100% rename from src/consts/index.js rename to frontend/src/consts/index.js diff --git a/src/content.css b/frontend/src/content.css similarity index 100% rename from src/content.css rename to frontend/src/content.css diff --git a/src/content.js b/frontend/src/content.js similarity index 100% rename from src/content.js rename to frontend/src/content.js diff --git a/src/icons/logo128.png b/frontend/src/icons/logo128.png similarity index 100% rename from src/icons/logo128.png rename to frontend/src/icons/logo128.png diff --git a/src/icons/logo16.png b/frontend/src/icons/logo16.png similarity index 100% rename from src/icons/logo16.png rename to frontend/src/icons/logo16.png diff --git a/src/icons/logo24.png b/frontend/src/icons/logo24.png similarity index 100% rename from src/icons/logo24.png rename to frontend/src/icons/logo24.png diff --git a/src/icons/logo32.png b/frontend/src/icons/logo32.png similarity index 100% rename from src/icons/logo32.png rename to frontend/src/icons/logo32.png diff --git a/src/icons/logo48.png b/frontend/src/icons/logo48.png similarity index 100% rename from src/icons/logo48.png rename to frontend/src/icons/logo48.png diff --git a/src/icons/logo64.png b/frontend/src/icons/logo64.png similarity index 100% rename from src/icons/logo64.png rename to frontend/src/icons/logo64.png diff --git a/src/manifest.json b/frontend/src/manifest.json similarity index 100% rename from src/manifest.json rename to frontend/src/manifest.json diff --git a/src/popup.css b/frontend/src/popup.css similarity index 100% rename from src/popup.css rename to frontend/src/popup.css diff --git a/src/popup.html b/frontend/src/popup.html similarity index 100% rename from src/popup.html rename to frontend/src/popup.html diff --git a/src/popup.js b/frontend/src/popup.js similarity index 100% rename from src/popup.js rename to frontend/src/popup.js diff --git a/src/utils/dom.js b/frontend/src/utils/dom.js similarity index 100% rename from src/utils/dom.js rename to frontend/src/utils/dom.js diff --git a/src/utils/fetcher.js b/frontend/src/utils/fetcher.js similarity index 100% rename from src/utils/fetcher.js rename to frontend/src/utils/fetcher.js diff --git a/src/utils/index.js b/frontend/src/utils/index.js similarity index 100% rename from src/utils/index.js rename to frontend/src/utils/index.js diff --git a/src/utils/storage.js b/frontend/src/utils/storage.js similarity index 100% rename from src/utils/storage.js rename to frontend/src/utils/storage.js diff --git a/src/utils/urlManager.js b/frontend/src/utils/urlManager.js similarity index 100% rename from src/utils/urlManager.js rename to frontend/src/utils/urlManager.js diff --git a/webpack.config.js b/frontend/webpack.config.js similarity index 100% rename from webpack.config.js rename to frontend/webpack.config.js From 86ae85d957d47c688c4001df3b10fb7a86fea21f Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 19 Apr 2018 23:29:43 +0900 Subject: [PATCH 04/26] feat(#81): init backend package.json --- backend/package.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 backend/package.json diff --git a/backend/package.json b/backend/package.json new file mode 100644 index 0000000..8b88266 --- /dev/null +++ b/backend/package.json @@ -0,0 +1,20 @@ +{ + "name": "smart-github", + "version": "1.1.0", + "description": "Chrome extension for github", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ygnoh/smart-github.git" + }, + "keywords": [], + "author": "Yonggoo Noh (https://github.com/ygnoh)", + "license": "AGPL-3.0-only", + "bugs": { + "url": "https://github.com/ygnoh/smart-github/issues" + }, + "homepage": "https://github.com/ygnoh/smart-github#readme" +} From 12712bc0ca6efb2ea364dc1c751a17d41d2de7aa Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 19 Apr 2018 23:34:07 +0900 Subject: [PATCH 05/26] =?UTF-8?q?feat(#81):=20.gitignore=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20express=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.gitignore | 3 +++ backend/package.json | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 backend/.gitignore diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..d5ef3b1 --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,3 @@ +package-lock.json +.vscode/ +node_modules/ \ No newline at end of file diff --git a/backend/package.json b/backend/package.json index 8b88266..50b0b61 100644 --- a/backend/package.json +++ b/backend/package.json @@ -16,5 +16,8 @@ "bugs": { "url": "https://github.com/ygnoh/smart-github/issues" }, - "homepage": "https://github.com/ygnoh/smart-github#readme" + "homepage": "https://github.com/ygnoh/smart-github#readme", + "dependencies": { + "express": "^4.16.3" + } } From 05f99d786e41f0ee7910d3bae5043066b8d519ba Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 19 Apr 2018 23:47:18 +0900 Subject: [PATCH 06/26] =?UTF-8?q?feat(#81):=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EA=B8=B0=EC=B4=88=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/index.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 backend/src/index.js diff --git a/backend/package.json b/backend/package.json index 50b0b61..0b0effd 100644 --- a/backend/package.json +++ b/backend/package.json @@ -2,7 +2,7 @@ "name": "smart-github", "version": "1.1.0", "description": "Chrome extension for github", - "main": "index.js", + "main": "src/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/backend/src/index.js b/backend/src/index.js new file mode 100644 index 0000000..1db351b --- /dev/null +++ b/backend/src/index.js @@ -0,0 +1,6 @@ +const express = require("express"); +const app = express(); + +app.get("/", (req, res) => res.send("hello backend world!")); + +app.listen(3000, () => console.log("Example app listening on port 3000 for YOU")); \ No newline at end of file From 51b16320278fd4a8e60f57bc9c6382765bd536b5 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Fri, 20 Apr 2018 02:43:43 +0900 Subject: [PATCH 07/26] =?UTF-8?q?feat(#81):=20=EA=B8=B0=EC=B4=88=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20webhook=20request=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/index.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/src/index.js b/backend/src/index.js index 1db351b..37d4731 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -1,6 +1,25 @@ const express = require("express"); const app = express(); +const PORT = 3000; -app.get("/", (req, res) => res.send("hello backend world!")); +app.post("/watch", (req, res, next) => { + let payload = ""; -app.listen(3000, () => console.log("Example app listening on port 3000 for YOU")); \ No newline at end of file + req.on("readable", () => { + const read = req.read(); + if (!read) { + return; + } + + payload += read; + }); + + req.on("end", () => { + const {comment} = JSON.parse(payload); + const {html_url, user, body} = comment; + + console.log(`${user.login}가 당신의 글(${html_url})에 댓글을 달았습니다:\n${body}`); + }); +}); + +app.listen(PORT, () => console.log(`\nStart to listen on port ${PORT}.\n`)); \ No newline at end of file From f55390d4304c138631dc8f54485d687a0ffb7bc4 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Wed, 25 Apr 2018 02:52:07 +0900 Subject: [PATCH 08/26] =?UTF-8?q?feat(#81):=20try-catch=20=EB=B0=A9?= =?UTF-8?q?=EC=96=B4=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/index.js b/backend/src/index.js index 37d4731..47ef7ef 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -15,10 +15,14 @@ app.post("/watch", (req, res, next) => { }); req.on("end", () => { - const {comment} = JSON.parse(payload); - const {html_url, user, body} = comment; + try { + const {comment} = JSON.parse(payload); + const {html_url, user, body} = comment; - console.log(`${user.login}가 당신의 글(${html_url})에 댓글을 달았습니다:\n${body}`); + console.log(`${user.login}가 당신의 글(${html_url})에 댓글을 달았습니다:\n${body}`); + } catch (e) { + console.error(e); + } }); }); From a8841c99dd391b8b5af6a5ebbcb8e46c90c71fec Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Wed, 25 Apr 2018 23:20:50 +0900 Subject: [PATCH 09/26] =?UTF-8?q?feat(#81):=20backend=20firebase=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 0b0effd..1baf4a8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,6 +18,7 @@ }, "homepage": "https://github.com/ygnoh/smart-github#readme", "dependencies": { - "express": "^4.16.3" + "express": "^4.16.3", + "firebase": "^4.13.1" } } From 9bc45dbe732e7aa4c819fee5f46af7029c5e2aa5 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Wed, 25 Apr 2018 23:27:40 +0900 Subject: [PATCH 10/26] =?UTF-8?q?feat(#81):=20frontend=20firebase=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/package.json b/frontend/package.json index 465034a..b9760d1 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,8 @@ "description": "Chrome extension for github", "main": "src/background.js", "dependencies": { - "babel-runtime": "^6.26.0" + "babel-runtime": "^6.26.0", + "firebase": "^4.13.1" }, "devDependencies": { "babel-core": "^6.26.0", From 50da988d0bceac0b4041c4ebf1c2a9df6b726a12 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Wed, 25 Apr 2018 23:38:15 +0900 Subject: [PATCH 11/26] =?UTF-8?q?feat(#81):=20backend=20firebase=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=ED=99=94=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/src/index.js b/backend/src/index.js index 47ef7ef..ba5a91a 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -1,4 +1,7 @@ const express = require("express"); +const firebase = require("@firebase/app").default; +require("@firebase/messaging"); + const app = express(); const PORT = 3000; @@ -26,4 +29,15 @@ app.post("/watch", (req, res, next) => { }); }); -app.listen(PORT, () => console.log(`\nStart to listen on port ${PORT}.\n`)); \ No newline at end of file +app.listen(PORT, () => console.log(`\nStart to listen on port ${PORT}.\n`)); + +// init firebase +const config = { + apiKey: "AIzaSyD7maFJ1fc_lGPQev9Jiyse53AgtCybpJg", + authDomain: "smart-github.firebaseapp.com", + databaseURL: "https://smart-github.firebaseio.com", + projectId: "smart-github", + storageBucket: "smart-github.appspot.com", + messagingSenderId: "767779176892" +}; +firebase.initializeApp(config); \ No newline at end of file From 36883868f78ddc5c8566a9d7a4d74030a4cbabdd Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Wed, 25 Apr 2018 23:49:40 +0900 Subject: [PATCH 12/26] =?UTF-8?q?feat(#81):=20gitignore=EC=97=90=20firebas?= =?UTF-8?q?e=20private=20key=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/.gitignore b/backend/.gitignore index d5ef3b1..4100ef2 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,3 +1,4 @@ +firebase-key.json package-lock.json .vscode/ node_modules/ \ No newline at end of file From 620022bdd9d81dbbf09df21cbab70f184efdf62c Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 26 Apr 2018 00:03:01 +0900 Subject: [PATCH 13/26] feat(#81): npm request installed --- backend/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 1baf4a8..3961ad1 100644 --- a/backend/package.json +++ b/backend/package.json @@ -19,6 +19,7 @@ "homepage": "https://github.com/ygnoh/smart-github#readme", "dependencies": { "express": "^4.16.3", - "firebase": "^4.13.1" + "firebase": "^4.13.1", + "request": "^2.85.0" } } From 59adf525302a5b3383434e1578c85b15ec823369 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 26 Apr 2018 00:19:22 +0900 Subject: [PATCH 14/26] =?UTF-8?q?feat(#81):=20backend=20googleapis=20?= =?UTF-8?q?=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/package.json b/backend/package.json index 3961ad1..3fa9fb7 100644 --- a/backend/package.json +++ b/backend/package.json @@ -20,6 +20,7 @@ "dependencies": { "express": "^4.16.3", "firebase": "^4.13.1", + "googleapis": "^29.0.0", "request": "^2.85.0" } } From e1c7f8a3d5ccb4b731b3b1b599f3c7d3755f054c Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 26 Apr 2018 00:52:08 +0900 Subject: [PATCH 15/26] =?UTF-8?q?feat(#81):=20backend=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20firebase=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 3fa9fb7..c5609aa 100644 --- a/backend/package.json +++ b/backend/package.json @@ -19,7 +19,6 @@ "homepage": "https://github.com/ygnoh/smart-github#readme", "dependencies": { "express": "^4.16.3", - "firebase": "^4.13.1", "googleapis": "^29.0.0", "request": "^2.85.0" } From 863df14b165d304e827f7d850b2d504329cd6d32 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 26 Apr 2018 00:53:34 +0900 Subject: [PATCH 16/26] =?UTF-8?q?feat(#81):=20webhook=20=EC=8B=9C,=20fcm?= =?UTF-8?q?=EC=97=90=20request=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/index.js | 57 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/backend/src/index.js b/backend/src/index.js index ba5a91a..cf60d4e 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -1,10 +1,13 @@ const express = require("express"); -const firebase = require("@firebase/app").default; -require("@firebase/messaging"); +const request = require("request"); +const {google} = require("googleapis"); const app = express(); const PORT = 3000; +let accessToken; +getAccessToken().then(token => accessToken = token); + app.post("/watch", (req, res, next) => { let payload = ""; @@ -23,6 +26,26 @@ app.post("/watch", (req, res, next) => { const {html_url, user, body} = comment; console.log(`${user.login}가 당신의 글(${html_url})에 댓글을 달았습니다:\n${body}`); + + request.post({ + url: "https://fcm.googleapis.com/v1/projects/smart-github/messages:send", + json: true, + headers: { + "Content-type": "application/json", + "Authorization": `Bearer ${accessToken}` + }, + body: { + message: { + token: "", // TODO: 타겟 앱 인스턴스 등록 토큰 + notification: { + body: "this is body", + title: "this is title" + } + } + } + }, function(error, incomingMessage, response) { + console.log(error); + }); } catch (e) { console.error(e); } @@ -31,13 +54,23 @@ app.post("/watch", (req, res, next) => { app.listen(PORT, () => console.log(`\nStart to listen on port ${PORT}.\n`)); -// init firebase -const config = { - apiKey: "AIzaSyD7maFJ1fc_lGPQev9Jiyse53AgtCybpJg", - authDomain: "smart-github.firebaseapp.com", - databaseURL: "https://smart-github.firebaseio.com", - projectId: "smart-github", - storageBucket: "smart-github.appspot.com", - messagingSenderId: "767779176892" -}; -firebase.initializeApp(config); \ No newline at end of file +function getAccessToken() { + return new Promise(function (resolve, reject) { + // the private key to get an access token + const key = require('../firebase-key.json'); + const jwtClient = new google.auth.JWT( + key.client_email, + null, + key.private_key, + ["https://www.googleapis.com/auth/firebase.messaging"], + null + ); + jwtClient.authorize(function (err, tokens) { + if (err) { + reject(err); + return; + } + resolve(tokens.access_token); + }); + }); +} \ No newline at end of file From 02a47b35bb658e7ed9aa61c90758ab8ef49b3895 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Thu, 26 Apr 2018 01:14:40 +0900 Subject: [PATCH 17/26] =?UTF-8?q?feat(#81):=20frontend=20firebase=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/background.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frontend/src/background.js b/frontend/src/background.js index 521acec..97606e4 100644 --- a/frontend/src/background.js +++ b/frontend/src/background.js @@ -1,6 +1,19 @@ +import * as firebase from "firebase/app"; +import "firebase/messaging"; import {storage} from "./utils"; import {MESSAGE} from "./consts"; +// init Firebase +const config = { + apiKey: "AIzaSyD7maFJ1fc_lGPQev9Jiyse53AgtCybpJg", + authDomain: "smart-github.firebaseapp.com", + databaseURL: "https://smart-github.firebaseio.com", + projectId: "smart-github", + storageBucket: "smart-github.appspot.com", + messagingSenderId: "767779176892" +}; +firebase.initializeApp(config); + // default regex that will never match anything let rxIssueTab = /(?!)/; let rxPRTab = /(?!)/; From 787238da1234df1d59b433421d1b5632b01988e2 Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Fri, 4 May 2018 01:14:14 +0900 Subject: [PATCH 18/26] =?UTF-8?q?feat(#81):=20popup=20=EB=82=B4=20username?= =?UTF-8?q?=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/popup.css | 17 ++++++++++++---- frontend/src/popup.html | 38 ++++++++++++++++++++++++++--------- frontend/src/popup.js | 35 ++++++++++++++++++++++++++++++-- frontend/src/utils/dom.js | 24 ++++++++++++++++------ frontend/src/utils/storage.js | 36 +++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 21 deletions(-) diff --git a/frontend/src/popup.css b/frontend/src/popup.css index 4d80984..212ff61 100644 --- a/frontend/src/popup.css +++ b/frontend/src/popup.css @@ -58,22 +58,31 @@ a { color: #0645AD; } +/* body container */ +.sg-popup-body-container { + display: none; +} + +.sg-popup-body-container.is-on { + display: block; +} + /* body */ .sg-popup-body { font-size: 14px; padding: 10px; } -.sg-host-list { +.sg-body-list { padding: 10px; margin-left: 10px; } -.sg-host-list li { +.sg-body-list li { margin-bottom: 5px; } -.sg-popup-heading { +.sg-body-header { font-size: 16px; font-weight: 500; } @@ -85,7 +94,7 @@ a { left: 9.375%; } -#sg-host-input { +.sg-footer-input { font-size: 14px; width: 150px; height: 20px; diff --git a/frontend/src/popup.html b/frontend/src/popup.html index 696ac9a..e2bdae7 100644 --- a/frontend/src/popup.html +++ b/frontend/src/popup.html @@ -18,17 +18,37 @@ -
- Your Hosts: -
    + + + + +
    +
    + Your Hosts: +
      +
      +
      - diff --git a/frontend/src/popup.js b/frontend/src/popup.js index a05013f..4450689 100644 --- a/frontend/src/popup.js +++ b/frontend/src/popup.js @@ -11,14 +11,35 @@ storage.getHosts().then(hosts => { }); }); +storage.getUsernames().then(usernames => { + const usernameListContainer = dom.getUsernameList(); + + usernames.forEach(username => { + const item = document.createElement("li"); + item.innerHTML = username; + usernameListContainer.appendChild(item); + }); +}); + +let prevTarget = document.querySelector(".sg-popup-host"); +[].forEach.call(dom.getPopupBtns(), btn => { + btn.addEventListener("change", e => { + prevTarget.classList.remove("is-on"); + const target = document.querySelector(e.target.dataset.target); + target.classList.add("is-on"); + prevTarget = target; + }); +}); dom.getHostSaveBtn().addEventListener("click", saveHost); dom.getHostResetBtn().addEventListener("click", storage.resetHosts.bind(storage)); -dom.getHostForm().addEventListener("submit", e => { +dom.getUsernameSaveBtn().addEventListener("click", saveUsername); +dom.getUsernameResetBtn().addEventListener("click", storage.resetUsernames.bind(storage)); +dom.getFooterForm().addEventListener("submit", e => { e.preventDefault(); }); function saveHost() { - const input = dom.getHostInput(); + const input = dom.getFooterInput(); let newHost = input.value.trim(); // 입력 받은 host에 www. 값이 있다면 제거 newHost = newHost.replace(/^www\./, ""); @@ -27,4 +48,14 @@ function saveHost() { } storage.setHosts(newHost); +} + +function saveUsername() { + const username = dom.getFooterInput().value.trim(); + + if (username === "") { + return; + } + + storage.setUsername(username); } \ No newline at end of file diff --git a/frontend/src/utils/dom.js b/frontend/src/utils/dom.js index 85faf2c..b6f090d 100644 --- a/frontend/src/utils/dom.js +++ b/frontend/src/utils/dom.js @@ -17,17 +17,29 @@ export default { getHostList() { return document.querySelector(".sg-host-list"); }, + getUsernameList() { + return document.querySelector(".sg-username-list"); + }, + getPopupBtns() { + return document.querySelectorAll("input[type=radio][name='sg-popup-buttons']"); + }, getHostSaveBtn() { - return document.getElementById("sg-host-save"); + return document.querySelector(".sg-host-save"); + }, + getUsernameSaveBtn() { + return document.querySelector(".sg-username-save"); }, getHostResetBtn() { - return document.getElementById("sg-host-reset"); + return document.querySelector(".sg-host-reset"); + }, + getUsernameResetBtn() { + return document.querySelector(".sg-username-reset"); }, - getHostInput() { - return document.getElementById("sg-host-input"); + getFooterInput() { + return document.querySelector(".is-on .sg-footer-input"); }, - getHostForm() { - return document.getElementById("sg-host-form"); + getFooterForm() { + return document.querySelector(".is-on .sg-footer-form"); }, removeResetTemplateBtns() { const bottomArea = this.getIssueBottomArea(); diff --git a/frontend/src/utils/storage.js b/frontend/src/utils/storage.js index ffe8de2..414bd9b 100644 --- a/frontend/src/utils/storage.js +++ b/frontend/src/utils/storage.js @@ -19,6 +19,17 @@ export default { }); }); }, + /** + * 등록된 유저 이름들을 가져온다. + * @returns {Array} 등록된 usernames + */ + getUsernames: function () { + return new Promise((resolve, reject) => { + this.get("sg-usernames", result => { + resolve(result["sg-usernames"] || []); + }); + }); + }, /** * 새 host를 추가하고, 페이지를 새로고침한다. * @param {string} newHost 새로 추가할 host @@ -39,6 +50,23 @@ export default { }); }); }, + /** + * 새 username을 추가하고, 페이지를 새로고침한다. + * @param {string} newUsername 새로 추가할 username + */ + setUsername: async function (newUsername) { + const usernames = await this.getUsernames(); + + if (usernames.includes(newUsername)) { + return; + } + + usernames.push(newUsername); + + this.set({ "sg-usernames": usernames }, () => { + location.reload(); + }); + }, /** * 저장된 hosts를 모두 reset하고 페이지를 새로고침한다. */ @@ -49,6 +77,14 @@ export default { }); }); }, + /** + * 저장된 usernames를 모두 reset하고 페이지를 새로고침한다. + */ + resetUsernames: function () { + this.remove("sg-usernames", () => { + location.reload(); + }); + }, /** * 현재 저장소의 token을 얻는다. * @returns {string} 현재 저장소의 token From 9a3c3a44e7c55cc294e98249b6384a53afd9ef6d Mon Sep 17 00:00:00 2001 From: yonggoonoh Date: Fri, 4 May 2018 01:16:11 +0900 Subject: [PATCH 19/26] =?UTF-8?q?fix(#81):=20=EB=88=84=EB=9D=BD=EB=90=9C?= =?UTF-8?q?=20list=20class=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/popup.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/popup.html b/frontend/src/popup.html index e2bdae7..8e49937 100644 --- a/frontend/src/popup.html +++ b/frontend/src/popup.html @@ -25,7 +25,7 @@
      Your Hosts: -
        +