| 149 | } |
| 150 | |
| 151 | pushToGist(code) { |
| 152 | const files = $('.diff-file:checked').toArray().map((elem) => elem.value); |
| 153 | if (files.length === 0) { |
| 154 | showLog('Nothing to do', LEVEL_WARN); |
| 155 | return; |
| 156 | } |
| 157 | const payload = { |
| 158 | files: {} |
| 159 | }; |
| 160 | files.forEach(file => { |
| 161 | payload.files[file] = { |
| 162 | content: code.gas[file] |
| 163 | }; |
| 164 | }); |
| 165 | if (code.scm['init_by_gas_hub.html']) { |
| 166 | payload.files['init_by_gas_hub.html'] = null; |
| 167 | } |
| 168 | if ($('#gist-desc').val() !== '') { |
| 169 | payload.description = $('#gist-desc').val(); |
| 170 | } |
| 171 | return $.ajax({ |
| 172 | url: `${this.baseUrl}/gists/${getBranch()}`, |
| 173 | headers: { |
| 174 | 'Authorization': `token ${this.accessToken}` |
| 175 | }, |
| 176 | method: 'PATCH', |
| 177 | crossDomain: true, |
| 178 | dataType: 'json', |
| 179 | contentType: 'application/json', |
| 180 | data: JSON.stringify(payload) |
| 181 | }) |
| 182 | .then(() => { |
| 183 | showLog(`Successfully update gist: ${getBranch()}`); |
| 184 | }) |
| 185 | .fail(err => { |
| 186 | showLog(`Failed to update: ${err}`, LEVEL_ERROR); |
| 187 | }); |
| 188 | } |
| 189 | |
| 190 | getAllGists() { |
| 191 | return getAllItems( |