From 3d10a8f86a3d7bff228eb7cfa4cf9d41d0c60186 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Mon, 7 Dec 2020 14:14:02 +0530 Subject: [PATCH 1/6] Initial MVP of GitHub gist support --- .../collections/import-export-collections.vue | 60 +++++++++++++++++++ components/firebase/login.vue | 7 ++- helpers/fb.js | 2 +- lang/en-US.json | 5 +- store/postwoman.js | 5 ++ 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/components/collections/import-export-collections.vue b/components/collections/import-export-collections.vue index 20d583c90..0dccae664 100644 --- a/components/collections/import-export-collections.vue +++ b/components/collections/import-export-collections.vue @@ -6,6 +6,35 @@

{{ $t("import_export") }} {{ $t("collections") }}

+ + + + @@ -97,6 +126,37 @@ export default { }, }, methods: { + async createCollectionGist() { + await this.$axios + .$post( + "https://api.github.com/gists", + { + files: { + "hoppscotch-collections.json": { + content: this.collectionJson, + }, + }, + }, + { + headers: { + Authorization: `token ${this.$store.state.postwoman.providerInfo.accessToken}`, + Accept: "application/vnd.github.v3+json", + }, + } + ) + .then((response) => { + this.$toast.success(this.$t("gist_created"), { + icon: "done", + }) + window.open(response.html_url) + }) + .catch((error) => { + this.$toast.error(this.$t("something_went_wrong"), { + icon: "error", + }) + console.log(error) + }) + }, hideModal() { this.$emit("hide-modal") }, diff --git a/components/firebase/login.vue b/components/firebase/login.vue index 33eb4ad82..c9423ed2a 100644 --- a/components/firebase/login.vue +++ b/components/firebase/login.vue @@ -109,7 +109,12 @@ export default { }, async signInWithGithub() { try { - const { additionalUserInfo } = await fb.signInUserWithGithub() + const { credential, additionalUserInfo } = await fb.signInUserWithGithub() + + this.$store.commit("postwoman/setProviderInfo", { + providerId: "github.com", + accessToken: credential.accessToken, + }) if (additionalUserInfo.isNewUser) { this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, { diff --git a/helpers/fb.js b/helpers/fb.js index 30c3dd7d8..d263ae062 100644 --- a/helpers/fb.js +++ b/helpers/fb.js @@ -131,7 +131,7 @@ export class FirebaseInstance { } async signInUserWithGithub() { - return await this.app.auth().signInWithPopup(this.authProviders.github()) + return await this.app.auth().signInWithPopup(this.authProviders.github().addScope("repo gist")) } async signInWithEmailAndPassword(email, password) { diff --git a/lang/en-US.json b/lang/en-US.json index d992a9378..84056defd 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -294,5 +294,8 @@ "experiments": "Experiments", "experiments_notice": "This is a collection of experiments we're working on that might turn out to be useful, fun, both, or neither. They're not final and may not be stable, so if something overly weird happens, don't panic. Just turn the dang thing off. Jokes aside, ", "use_experimental_url_bar": "Use experimental URL bar with environment highlighting", - "select_environment": "Select environment" + "select_environment": "Select environment", + "login_with_github_to": "Login with GitHub to ", + "create_secret_gist": "Create secret Gist", + "gist_created": "Gist created" } diff --git a/store/postwoman.js b/store/postwoman.js index 4f055bcb2..e21583f97 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -64,6 +64,7 @@ export const state = () => ({ editingEnvironment: {}, selectedRequest: {}, editingRequest: {}, + providerInfo: {}, }) export const mutations = { @@ -335,6 +336,10 @@ export const mutations = { } } }, + + setProviderInfo(state, value) { + state.providerInfo = value + }, } function testValue(myValue) { From 2978c8adfea80ce177a694ef2a6c6978a6253e6b Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Tue, 8 Dec 2020 12:05:10 +0530 Subject: [PATCH 2/6] Allow importing collections from gist --- .../collections/import-export-collections.vue | 26 +++++++++++++++++-- lang/en-US.json | 4 ++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/components/collections/import-export-collections.vue b/components/collections/import-export-collections.vue index c67d3e286..1e33d59cf 100644 --- a/components/collections/import-export-collections.vue +++ b/components/collections/import-export-collections.vue @@ -14,15 +14,17 @@
+