Skip to content

Commit

Permalink
Merge pull request #2 from cloudcompass/master
Browse files Browse the repository at this point in the history
pulling in ng2 stuff
  • Loading branch information
LayCraft authored Apr 23, 2017
2 parents 14fa885 + 8c2ba37 commit ee35340
Show file tree
Hide file tree
Showing 41 changed files with 2,502 additions and 55 deletions.
55 changes: 33 additions & 22 deletions api/models/Module.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
Copyright 2016, Cloud Compass Computing, Inc.
Copyright 2016, Cloud Compass Computing, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
*/
/**
* Module.js
*
Expand Down Expand Up @@ -47,40 +47,51 @@ module.exports = {
},

//todo icon is a client-side concern and should be refactored.
getIcon: function() {
getIcon: function () {
console.log("Looking up icon for", this);
//<i class="material-icons">face</i>
var iconMap = {
'repo': 'archive',
'issues':'bug report' ,
'issues': 'bug report',
'wiki': 'description'
};

return iconMap[this.type];
},

// Override the default toJSON method so the derived icon is included
toJSON: function() {
toJSON: function () {
var obj = this.toObject();
obj.icon = this.getIcon();
return obj;
}
},

beforeCreate: function (module, next) {
var admin = module.config.permissions.admin;
module.config = _.pick(module.config, ['full_name']);
sails.log.info('Project.beforeCreate.createWebhook', module);

var serviceId = _.has(module.service, 'id') ? module.service.id : module.service;

Service.findOne({id: serviceId})
.exec(function (err, service) {
if (service.platform == 'github') {
if (admin) {
GithubService.createWebhook(module, next);
} else {
next();
}
var moduleConfig = _.isArray(module.config) ? module.config : module.config != undefined && module.config != null ? [module.config] : [];

_.each(moduleConfig, function (config) {
var admin = config.permissions.admin;

sails.log.info('Project.beforeCreate.createWebhook', config);

//todo this is probably broken if the module has some repos with admin and some with not. prob will end up with webhook for some, but missing for others, depending on ordering.
if (admin) {
GithubService.createWebhook(config, function () {
sails.log.debug("created webhook");
});
}
});
// fallthrough and/or default
next();
}

});
},

Expand Down
105 changes: 92 additions & 13 deletions api/services/GithubService.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ module.exports = {
var issues = [];
var client = github.client();

var getDataPage = function (client, nextPage, pager) {
sails.log.debug("Retrieving repo page ", nextPage);
var ghme = client.me();
ghme.repos({
page: nextPage,
per_page: 100
}, pager);
};

var pager = function (err, data, headers) {
// TODO: If the github access token is revoked, this crashes due to a undefined header (I believe)
// Info is captured through err as "invalid credentials", handle this appropriately
Expand All @@ -144,28 +153,41 @@ module.exports = {
// Parse the next page from the link header and retrieve the next repo page
// Format is like: https://api.github.com/user/repos?page=50&per_page=100
var nextPageNumber = querystring.parse(url.parse(linkHeaders.next).query).page;
getDataPage(client, nextPageNumber, pager)
} else {
sails.log.debug("Returning repos to caller...");
cb(err, issues, headers);
getRepoPage(client, nextPageNumber, pager)

}
}

// Return the repos using the provided callback
cb(err, issues, headers);
};

function getRepoPage(client, page, pager) {
sails.log.debug("Retrieving repo page ", page);
var ghme = client.me();
ghme.repos({
page: page,
per_page: 100
}, pager);
}
//attempt at currying
var aggregate = function(howMany, cb) {
var callCount = 0;
var issues = [];
return function (err, data, headers) {
callCount++;
if (!err) {
if (data) {
issues = issues.concat(data);
}
}
if (callCount == howMany) {
cb(err,issues, headers);
}
}
};

Service.findOne({id: serviceID})
.exec(function (err, service) {
if (service) {
client = github.client(service.token);
getRepoPage(client, 1, pager);
getDataPage(client, 1, pager);
} else {
sails.log.error('could not retrieve repos', err);
}
Expand All @@ -180,10 +202,39 @@ module.exports = {
// sails.log.debug('finding first module:', widget.modules[0].id);
Module.findOne({id: widget.module.id}).populate('service')
.exec(function (err, module) {
//todo handle multi-repo modules, and implement paging
if (module) {

//coerce config into array for preliminary support of multi-repo modules
var moduleConfig = _.isArray(module.config) ? module.config : module.config != undefined && module.config != null ? [module.config] : [];

var client = github.client(module.service.token);
var ghrepo = client.repo(module.config.full_name);
ghrepo.commits(cb);

var commits = [];

//eww
var callCount = 0;

var aggregate = function (err, data, headers) {
callCount++;
if (!err) {
if (data) {
commits = commits.concat(data);
}
}
if (callCount == moduleConfig.length) {
cb(err,commits, headers);
}
};

//initial multi-repo module support
_.each(moduleConfig, function (config) {
var ghrepo = client.repo(config.full_name);
//todo implement paging using same pattern as with getRepos or mapreduce, or determine a new promise style
// currently, this is just getting the first page for each repo
ghrepo.commits(aggregate);
}
);
} else {
sails.log.error('could not retrieve module', err);
}
Expand All @@ -203,9 +254,37 @@ module.exports = {
Module.findOne({id: widget.module.id}).populate('service')
.exec(function (err, module) {
if (module) {

//coerce config into array for preliminary support of multi-repo modules
var moduleConfig = _.isArray(module.config) ? module.config : module.config != undefined && module.config != null ? [module.config] : [];

var client = github.client(module.service.token);
var ghrepo = client.repo(module.config.full_name);
ghrepo.issues(cb);

var issues = [];

//eww
var callCount = 0;

var aggregate = function (err, data, headers) {
callCount++;
if (!err) {
if (data) {
issues = issues.concat(data);
}
}
if (callCount == moduleConfig.length) {
cb(err,issues, headers);
}
};

//initial multi-repo module support
_.each(moduleConfig, function (config) {
var ghrepo = client.repo(config.full_name);
//todo implement paging using same pattern as with getRepos or mapreduce, or determine a new promise style
// currently, this is just getting the first page for each repo
ghrepo.issues(aggregate);
}
);
} else {
sails.log.error('could not retrieve module', err);
}
Expand Down
11 changes: 9 additions & 2 deletions assets/app/controllers/ModuleAddController.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ function ModuleAddController($scope, $state, $stateParams, ToolService, ProjectS
// data = object to pull properties from
// properties = optional array of property names to extract (default: *)
function configureModule(data) {
vm.module.config = data;
console.log(vm.module);
if (!vm.module.config || vm.module.config == undefined || vm.module.config == null) {
vm.module.config = [];

}

console.log("adding ", data, vm.module);
vm.module.config = vm.module.config.concat(data);

console.log("...to module ", vm.module);
}

function addModule(newModule) {
Expand Down
1 change: 1 addition & 0 deletions assets/app/controllers/ToolController.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function ToolController($scope, ToolService, ProjectService) {
// data = object to pull properties from
// properties = optional array of property names to extract (default: *)
function configureModule(data, properties) {
console.log("configModule:",data,properties);
if (typeof properties == 'undefined') {
vm.currentModule.config = data;
} else {
Expand Down
8 changes: 8 additions & 0 deletions assets/app/views/module-add.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ <h2 class="md-subhead">Configuration :</h2>
<md-tooltip>You do not have administrator rights to this repository. This module will not post to the activity feed.</md-tooltip>
</span>
</div>

<md-select ng-model="ctrl.userState">
<md-option ng-repeat="repo in vm.repos" value="{{repo.full_name}}" ng-disabled="$index === 1">
{{repo.full_name}}
</md-option>
</md-select>


</div>

<!--Buttons-->
Expand Down
3 changes: 3 additions & 0 deletions assets/app/views/widget/commits.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<div layout layout-padding>
<img style="height: 3em; width: 3em;" ng-src="{{commit.author.avatar_url}}">
<span layout="column" layout-align="start start">
<b>
Commit <a href="{{commit.html_url}}">{{commit.sha | limitTo : 8}}</a>
</b>
<b>By:
<span class="dash-widget-font">{{commit.author ? commit.author.login : commit.commit.committer.name}}</span>
</b>
Expand Down
10 changes: 7 additions & 3 deletions config/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ module.exports.connections = {
* *
***************************************************************************/
localDiskDb: {
adapter: 'sails-disk'
},
adapter: 'sails-disk'},

stackbuttonMongo: {
adapter: 'sails-mongo'
adapter: 'sails-mongo',
host: process.env.MONGODB_SERVICE_HOST || 'localhost',
port: process.env.MONGODB_SERVICE_PORT || 27017 ,
user: process.env.MONGODB_USER || '',
password: process.env.MONGODB_PASSWORD || '',
database: process.env.MONGODB_DATABASE || 'stackbutton'
}

/***************************************************************************
Expand Down
36 changes: 21 additions & 15 deletions config/env/production.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
Copyright 2016, Cloud Compass Computing, Inc.
Copyright 2016, Cloud Compass Computing, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
*/
/**
* Production environment settings
*
Expand All @@ -33,15 +33,21 @@ module.exports = {

models: {
migrate: 'safe'
}
},
/***************************************************************************
* Set the default database connection for models in the production *
* environment (see config/connections.js and config/models.js ) *
***************************************************************************/

// models: {
// connection: 'someMysqlServer'
// },
models: {
connection: 'stackbuttonMongo'
},

url: {
hooks: process.env.WEBHOOK_URL
}



/***************************************************************************
* Set the port in the production environment to 80 *
Expand Down
Loading

0 comments on commit ee35340

Please sign in to comment.