11import db from '@/datastore-notes' ;
22import converter from '@/converter' ;
3+ import Octokit from '@octokit/rest' ;
34import path from 'path' ;
45// eslint-disable-next-line import/no-extraneous-dependencies
56import { remote } from 'electron' ;
67import packageJson from '../../../../package' ;
78
8- const Octokit = require ( '@octokit/rest' ) ;
9- let octokit = Octokit ( {
9+ const getOctokit = ( { githubPersonalAccessToken , githubEnterpriseUrl } ) => new Octokit ( {
10+ auth : githubPersonalAccessToken ,
1011 userAgent : 'code-notes' . concat ( packageJson . version ) ,
1112 mediaType : {
1213 format : 'application/vnd.github.v3+json' ,
1314 } ,
15+ ...( githubEnterpriseUrl && { baseUrl : githubEnterpriseUrl } ) ,
1416} ) ;
1517
1618const state = {
@@ -55,16 +57,8 @@ const actions = {
5557 store . commit ( 'SELECT_LOADING' , true ) ;
5658 store . commit ( 'LOAD_NOTES' , [ ] ) ;
5759
58- if ( store . rootState . Settings . settings . githubEnterpriseUrl ) {
59- octokit = new Octokit ( {
60- baseUrl : store . rootState . Settings . settings . githubEnterpriseUrl ,
61- auth : store . rootState . Settings . settings . githubPersonalAccessToken ,
62- } ) ;
63- } else {
64- octokit = new Octokit ( {
65- auth : store . rootState . Settings . settings . githubPersonalAccessToken ,
66- } ) ;
67- }
60+ const octokit = getOctokit ( store . rootState . Settings . settings ) ;
61+
6862 octokit . gists . list ( ) . then ( ( res ) => {
6963 const promises = [ ] ;
7064
@@ -99,6 +93,9 @@ const actions = {
9993 } ,
10094 addNote ( store , note ) {
10195 store . commit ( 'SELECT_LOADING' , true ) ;
96+
97+ const octokit = getOctokit ( store . rootState . Settings . settings ) ;
98+
10299 if ( store . state . gistsSelected ) {
103100 octokit . gists . create ( note ) . then ( ( ) => {
104101 store . dispatch ( 'loadNotes' ) ;
@@ -115,6 +112,8 @@ const actions = {
115112 } ,
116113 updateNote ( store , note ) {
117114 if ( store . state . gistsSelected ) {
115+ const octokit = getOctokit ( store . rootState . Settings . settings ) ;
116+
118117 octokit . gists
119118 . update ( {
120119 gist_id : note . id ,
@@ -133,6 +132,9 @@ const actions = {
133132 } ,
134133 deleteNote ( store , note ) {
135134 store . commit ( 'SELECT_LOADING' , true ) ;
135+
136+ const octokit = getOctokit ( store . rootState . Settings . settings ) ;
137+
136138 if ( store . state . gistsSelected ) {
137139 octokit . gists . delete ( { gist_id : note . id } ) . then ( ( ) => {
138140 store . commit ( 'DELETE_NOTE' , note ) ;
0 commit comments