1
1
import db from '@/datastore-notes' ;
2
2
import converter from '@/converter' ;
3
+ import Octokit from '@octokit/rest' ;
3
4
import path from 'path' ;
4
5
// eslint-disable-next-line import/no-extraneous-dependencies
5
6
import { remote } from 'electron' ;
6
7
import packageJson from '../../../../package' ;
7
8
8
- const Octokit = require ( '@octokit/rest' ) ;
9
- let octokit = Octokit ( {
9
+ const getOctokit = ( { githubPersonalAccessToken , githubEnterpriseUrl } ) => new Octokit ( {
10
+ auth : githubPersonalAccessToken ,
10
11
userAgent : 'code-notes' . concat ( packageJson . version ) ,
11
12
mediaType : {
12
13
format : 'application/vnd.github.v3+json' ,
13
14
} ,
15
+ ...( githubEnterpriseUrl && { baseUrl : githubEnterpriseUrl } ) ,
14
16
} ) ;
15
17
16
18
const state = {
@@ -55,16 +57,8 @@ const actions = {
55
57
store . commit ( 'SELECT_LOADING' , true ) ;
56
58
store . commit ( 'LOAD_NOTES' , [ ] ) ;
57
59
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
+
68
62
octokit . gists . list ( ) . then ( ( res ) => {
69
63
const promises = [ ] ;
70
64
@@ -99,6 +93,9 @@ const actions = {
99
93
} ,
100
94
addNote ( store , note ) {
101
95
store . commit ( 'SELECT_LOADING' , true ) ;
96
+
97
+ const octokit = getOctokit ( store . rootState . Settings . settings ) ;
98
+
102
99
if ( store . state . gistsSelected ) {
103
100
octokit . gists . create ( note ) . then ( ( ) => {
104
101
store . dispatch ( 'loadNotes' ) ;
@@ -115,6 +112,8 @@ const actions = {
115
112
} ,
116
113
updateNote ( store , note ) {
117
114
if ( store . state . gistsSelected ) {
115
+ const octokit = getOctokit ( store . rootState . Settings . settings ) ;
116
+
118
117
octokit . gists
119
118
. update ( {
120
119
gist_id : note . id ,
@@ -133,6 +132,9 @@ const actions = {
133
132
} ,
134
133
deleteNote ( store , note ) {
135
134
store . commit ( 'SELECT_LOADING' , true ) ;
135
+
136
+ const octokit = getOctokit ( store . rootState . Settings . settings ) ;
137
+
136
138
if ( store . state . gistsSelected ) {
137
139
octokit . gists . delete ( { gist_id : note . id } ) . then ( ( ) => {
138
140
store . commit ( 'DELETE_NOTE' , note ) ;
0 commit comments