1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 18:33:11 +00:00

github: split up commit and push

This commit is contained in:
Steven Hugg 2019-05-12 13:33:21 -04:00
parent c4e03df416
commit efe0e032fb
4 changed files with 25 additions and 12 deletions

View File

@ -365,7 +365,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootbox.all.min.js"></script>
<link rel="stylesheet" href="bootstrap-tourist/bootstrap-tourist.min.css">
<link rel="stylesheet" href="bootstrap-tourist/bootstrap-tourist.css">
<script src="bootstrap-tourist/bootstrap-tourist.js"></script>
<script src="src/codemirror/codemirror.js"></script>

View File

@ -24,6 +24,7 @@ export interface GHSession extends GHRepoMetadata {
repo : any; // [repo object]
tree? : any; // [tree object]
head? : any; // [head ref]
commit?: any; // after commit()
paths? : string[];
}
@ -263,7 +264,7 @@ export class GithubService {
});
}
commitPush( ghurl:string, message:string, files:{path:string,data:FileData}[] ) : Promise<GHSession> {
commit( ghurl:string, message:string, files:{path:string,data:FileData}[] ) : Promise<GHSession> {
var sess : GHSession;
return this.getGithubHEADTree(ghurl).then( (session) => {
sess = session;
@ -303,10 +304,17 @@ export class GithubService {
sess.head.object.sha
]
});
}).then( (commit1) => {
return sess.repo.commits(commit1.sha).fetch();
}).then( (commit) => {
return sess.head.update({
sha: commit.sha
});
sess.commit = commit;
return sess;
});
}
push(sess:GHSession) : Promise<GHSession> {
return sess.head.update({
sha: sess.commit.sha
}).then( (update) => {
return sess;
});

View File

@ -402,7 +402,7 @@ function getGithubService() {
function getBoundGithubURL() : string {
var toks = (repo_id||'').split('/');
if (toks.length != 2) {
alertError("You are not in a GitHub repository. Choose Import or Publish first.");
alertError("You are not in a GitHub repository. Choose one from the pulldown, or Import or Publish one.");
return null;
}
return 'https://github.com/' + toks[0] + '/' + toks[1];
@ -525,7 +525,9 @@ function pushChangesToGithub(message:string) {
setWaitDialog(true);
return getGithubService().login().then( () => {
setWaitProgress(0.5);
return getGithubService().commitPush(ghurl, message, files);
return getGithubService().commit(ghurl, message, files);
}).then( (sess) => {
return getGithubService().push(sess);
}).then( (sess) => {
setWaitDialog(false);
alertInfo("Pushed files to " + ghurl);
@ -777,7 +779,7 @@ function populateRepos(sel) {
}
function populateFiles(sel:JQuery, category:string, prefix:string, callback:() => void) {
store.keys(function(err, keys : string[]) {
store.keys().then( (keys:string[]) => {
var foundSelected = false;
var numFound = 0;
if (!keys) keys = [];
@ -804,10 +806,10 @@ function populateFiles(sel:JQuery, category:string, prefix:string, callback:() =
function updateSelector() {
var sel = $("#preset_select").empty();
if (!repo_id) {
populateRepos(sel);
// normal: populate local and shared files
populateFiles(sel, "Local Files", "local/", () => {
populateFiles(sel, "Shared", "shared/", () => {
populateRepos(sel);
populateExamples(sel);
sel.css('visibility','visible');
});

View File

@ -107,10 +107,13 @@ describe('Store', function() {
for (var i=0; i<256; i++)
binfile[i] = i;
var files = [
{path:'text.txt', data:'hello world'},
{path:'text.txt', data:'hello world ' + Math.random()},
{path:'data.bin', data:binfile}
];
gh.commitPush('https://github.com/pzpinfo/testrepo3', 'test commit', files).then( (sess) => {
gh.commit('https://github.com/pzpinfo/testrepo3', 'test commit', files).then( (sess) => {
return gh.push(sess);
}).then( (sess) => {
console.log(sess.commit);
done();
});
});
@ -122,7 +125,7 @@ describe('Store', function() {
var files = [
{path:'text.txt', data:'hello world'}
];
gh.commitPush('https://github.com/brovador/NESnake/tree/master/src', 'test commit', files)
gh.commit('https://github.com/brovador/NESnake/tree/master/src', 'test commit', files)
.catch( (e) => {
console.log(e);
assert.equal(e, 'Sorry, right now you can only commit files to the root directory of a repository.');