Skip to content

Commit

Permalink
Progress toward github api hooked up.
Browse files Browse the repository at this point in the history
  • Loading branch information
leobenkel committed May 27, 2017
1 parent c54d8c4 commit b3a2ec5
Show file tree
Hide file tree
Showing 12 changed files with 1,406 additions and 18 deletions.
92 changes: 80 additions & 12 deletions scripts/githubAPI/githubConnector.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,87 @@
define(['jquery', 'lodash'], function($) {
define(['jquery', 'lodash', 'gh3'], function($, _, Gh3) {
var Github = function() {
var rootURL = 'https://api.github.com';
var organizationName = 'The-Brains';
var myself = this;
};

Github.master = null;
Github.repo = null;
Github.directory = null;
var rootURL = 'https://api.github.com';
var organizationName = 'The-Brains';
var databaseStorageRepoName = 'database-storage';

Github.getRepos = function() {
return $.getJSON(`${rootURL}/orgs/${organizationName}/repos`);
};

Github.getReposNames = function() {
return Github.getRepos().then(function(data) {
return _.map(data, function(repo) {
return _.replace(repo.full_name, `${organizationName}/`, '');
});
})
};

Github.getDatabaseRepo = function() {
return new Promise(function(resolve, reject) {
if (Github.repo) {
resolve(Github.repo);
return;
}

var k33g = new Gh3.User(organizationName);
var k33gRepo = new Gh3.Repository(databaseStorageRepoName, k33g);
k33gRepo.fetch(function (err, res) {
if(err) {
reject(err);
}

Github.repo = k33gRepo;
resolve(Github.repo);
});
});
};

Github.getMasterBranch = function() {
return new Promise(function(resolve, reject) {
if (Github.master) {
resolve(Github.master);
return;
}

return Github.getDatabaseRepo()
.then(function(repo) {
repo.fetchBranches(function (err, res) {
if(err) {
reject(err);
}

Github.master = repo.getBranchByName("master");
resolve(Github.master);
});
});
});
};

Github.getDataFolder = function() {
return new Promise(function(resolve, reject) {
if (Github.directory) {
resolve(Github.directory);
return;
}

this.getRepos = function() {
return $.getJSON(`${rootURL}/orgs/The-Brains/repos`);
};
return Github.getMasterBranch()
.then(function(master) {
master.fetchContents(function (err, res) {
if(err) {
reject(err);
}

this.getReposNames = function() {
return this.getRepos().then(function(data) {
return _.map(data, function(repo) {
return _.replace(repo.full_name, `${organizationName}/`, '');
Github.directory = master.getDirByName('data');
resolve(Github.directory);
});
})
}
});
});
};

return Github;
Expand Down
Loading

0 comments on commit b3a2ec5

Please sign in to comment.