MCPcopy
hub / github.com/leonhartX/gas-github / pushToRepo

Method pushToRepo

src/scm/github.js:25–149  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

23 }
24
25 pushToRepo(code) {
26 const changed = $('.diff-file:checked').toArray().map(elem => elem.value);
27 const promises = changed.filter(f => code.gas[f]).map((file) => {
28 const payload = {
29 content: code.gas[file],
30 encoding: 'utf-8'
31 };
32 return $.ajax({
33 url: `${this.baseUrl}/repos/${getRepo().fullName}/git/blobs`,
34 headers: {
35 'Authorization': `token ${this.accessToken}`
36 },
37 method: 'POST',
38 crossDomain: true,
39 dataType: 'json',
40 contentType: 'application/json',
41 data: JSON.stringify(payload)
42 })
43 .then(response => {
44 return {
45 file: file,
46 blob: response
47 };
48 })
49 });
50 if (changed.length === 0) {
51 showLog('Nothing to do', LEVEL_WARN);
52 return;
53 }
54
55 Promise.all([
56 Promise.all(promises),
57 getGitHubJSON(
58 `${this.baseUrl}/repos/${getRepo().fullName}/branches/${getBranch()}`,
59 this.accessToken)
60 ])
61 .then(responses => {
62 return getGitHubJSON(
63 responses[1].commit.commit.tree.url,
64 this.accessToken, {
65 recursive: 1
66 }
67 )
68 .then(baseTree => {
69 const tree = responses[0].map((data) => {
70 return {
71 path: data.file,
72 mode: '100644',
73 type: 'blob',
74 sha: data.blob.sha
75 }
76 })
77 .concat(baseTree.tree.filter((t) => {
78 return (t.type != 'tree') && (changed.indexOf(t.path) < 0);
79 }));
80 return {
81 tree: tree
82 };

Callers 1

pushMethod · 0.95

Calls 4

getRepoFunction · 0.85
showLogFunction · 0.85
getGitHubJSONFunction · 0.85
getBranchFunction · 0.85

Tested by

no test coverage detected