@@ -22,6 +22,7 @@ import {
2222import { IpcEvents } from '../../ipc-events' ;
2323import { ensureRequiredFiles } from '../../utils/editor-utils' ;
2424import { getOctokit } from '../../utils/octokit' ;
25+ import { getTemplate } from '../content' ;
2526import { ipcRendererManager } from '../ipc' ;
2627import { AppState } from '../state' ;
2728
@@ -120,18 +121,32 @@ export const GistActionButton = observer(
120121 const octo = await getOctokit ( appState ) ;
121122 const { gitHubPublishAsPublic } = appState ;
122123 const options = { includeDependencies : true , includeElectron : true } ;
123- const values = await window . ElectronFiddle . app . getEditorValues ( options ) ;
124+ const defaultGistValues = await getTemplate ( appState . version ) ;
125+ const currentEditorValues = await window . ElectronFiddle . app . getEditorValues (
126+ options ,
127+ ) ;
128+
129+ defaultGistValues [ 'package.json' ] = currentEditorValues [ 'package.json' ] ;
124130
125131 try {
132+ const gistFilesList = appState . isPublishingGistAsRevision
133+ ? this . gistFilesList ( defaultGistValues )
134+ : this . gistFilesList ( currentEditorValues ) ;
135+
136+ // TODO: remove as any when octo is fixed
126137 const gist = await octo . gists . create ( {
127138 public : ! ! gitHubPublishAsPublic ,
128139 description,
129- files : this . gistFilesList ( values ) as any , // Note: GitHub messed up, GistsCreateParamsFiles is an incorrect interface
140+ files : gistFilesList as any , // Note: GitHub messed up, GistsCreateParamsFiles is an incorrect interface
130141 } ) ;
131142
132143 appState . gistId = gist . data . id ;
133144 appState . localPath = undefined ;
134145
146+ if ( appState . isPublishingGistAsRevision ) {
147+ await this . handleUpdate ( appState . isPublishingGistAsRevision ) ;
148+ }
149+
135150 console . log ( `Publish Button: Publishing complete` , { gist } ) ;
136151 this . renderToast ( {
137152 message : 'Successfully published gist!' ,
@@ -179,8 +194,9 @@ export const GistActionButton = observer(
179194
180195 /**
181196 * Update an existing GitHub gist.
197+ * silently updates the gist when publishing as a revision
182198 */
183- public async handleUpdate ( ) {
199+ public async handleUpdate ( silent = false ) {
184200 const { appState } = this . props ;
185201 const octo = await getOctokit ( this . props . appState ) ;
186202 const options = { includeDependencies : true , includeElectron : true } ;
@@ -206,14 +222,17 @@ export const GistActionButton = observer(
206222
207223 appState . editorMosaic . isEdited = false ;
208224 console . log ( 'Updating: Updating done' , { gist } ) ;
209- this . renderToast ( {
210- message : 'Successfully updated gist!' ,
211- action : {
212- text : 'Copy link' ,
213- icon : 'clipboard' ,
214- onClick : ( ) => clipboard . writeText ( gist . data . html_url ) ,
215- } ,
216- } ) ;
225+
226+ if ( ! silent ) {
227+ this . renderToast ( {
228+ message : 'Successfully updated gist!' ,
229+ action : {
230+ text : 'Copy link' ,
231+ icon : 'clipboard' ,
232+ onClick : ( ) => clipboard . writeText ( gist . data . html_url ) ,
233+ } ,
234+ } ) ;
235+ }
217236 } catch ( error ) {
218237 console . warn ( `Could not update gist` , { error } ) ;
219238
0 commit comments