MCPcopy Index your code
hub / github.com/witheve/Eve / writeToGist

Function writeToGist

src/util.ts:182–205  ·  view source on GitHub ↗
(name:string, content:string, callback:(error:Error, url?:string) => void)

Source from the content-addressed store, hash-verified

180}
181
182export function writeToGist(name:string, content:string, callback:(error:Error, url?:string) => void) {
183 name = dasherize(name);
184 let request = new XMLHttpRequest();
185 request.onreadystatechange = function() {
186 if(request.readyState === 4) {
187 if(request.status !== 201) {
188 return callback(new Error(`HTTP Response: ${request.status}`));
189 }
190 let response:any = JSON.parse(request.responseText);
191 let file = response.files[name];
192 let url = file.raw_url.split("/raw/")[0];
193 let err = (file.truncated) ? new Error("File to large: Maximum gist size is 10mb") : undefined;
194 callback(err, url);
195 }
196 };
197 let payload = {
198 public: true,
199 description: "",
200 files: {}
201 }
202 payload.files[name] = {content: content};
203 request.open("POST", "https://api.github.com/gists");
204 request.send(JSON.stringify(payload));
205}
206
207interface GistResponse {id: string, url: string, files: {[name:string]: {content: string}}}
208

Callers 1

saveToGistMethod · 0.90

Calls 2

dasherizeFunction · 0.85
sendMethod · 0.65

Tested by

no test coverage detected