load default cla url from json file; close #44
This commit is contained in:
Родитель
0cbff48f1a
Коммит
58e69a5eb1
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"default-cla": [
|
||||
{
|
||||
"name": "SAP individual CLA",
|
||||
"url": "https://gist.github.com/CLAassistant/bd1ea8ec8aa0357414e8"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -21,6 +21,9 @@ module.controller('HomeCtrl', ['$rootScope', '$scope', '$document', '$HUB', '$RP
|
|||
$scope.user = {};
|
||||
$scope.nextstep = {step1: true};
|
||||
$scope.active = 0;
|
||||
$scope.defaultClas = [];
|
||||
var githubGists = 'https://api.github.com/gists?per_page=100';
|
||||
var githubUserRepos = 'https://api.github.com/user/repos?per_page=100';
|
||||
|
||||
|
||||
$scope.logAdminIn = function(){
|
||||
|
@ -93,7 +96,7 @@ module.controller('HomeCtrl', ['$rootScope', '$scope', '$document', '$HUB', '$RP
|
|||
// };
|
||||
|
||||
if ($scope.user && $scope.user.value && $scope.user.value.admin) {
|
||||
$HUBService.direct_call('https://api.github.com/user/repos?per_page=100').then(function(data){
|
||||
$HUBService.direct_call(githubUserRepos).then(function(data){
|
||||
data.value.forEach(function(orgRepo){
|
||||
$scope.repos.push(orgRepo);
|
||||
});
|
||||
|
@ -103,8 +106,15 @@ module.controller('HomeCtrl', ['$rootScope', '$scope', '$document', '$HUB', '$RP
|
|||
};
|
||||
|
||||
var getGists = function(){
|
||||
$scope.gists = [{name: 'SAP individual CLA', url: 'https://gist.github.com/CLAassistant/bd1ea8ec8aa0357414e8'}];
|
||||
$HUBService.direct_call('https://api.github.com/gists?per_page=100').then(function(data){
|
||||
$scope.gists = [];
|
||||
if (!$scope.defaultClas.length) {
|
||||
$scope.getDefaultClaFiles().then(function(data){
|
||||
$scope.gists = $scope.gists.concat($scope.defaultClas);
|
||||
});
|
||||
}
|
||||
$scope.gists = $scope.defaultClas.concat([]);
|
||||
|
||||
$HUBService.direct_call(githubGists).then(function(data){
|
||||
if (data && data.value) {
|
||||
data.value.forEach(function(gist){
|
||||
var gistFile = {};
|
||||
|
@ -222,6 +232,12 @@ module.controller('HomeCtrl', ['$rootScope', '$scope', '$document', '$HUB', '$RP
|
|||
});
|
||||
};
|
||||
|
||||
$scope.getDefaultClaFiles = function(){
|
||||
return $RAW.get('/static/cla-assistant.json').then(function(data){
|
||||
$scope.defaultClas = data['default-cla'];
|
||||
});
|
||||
};
|
||||
|
||||
getUser().then(function(){
|
||||
getRepos();
|
||||
getGists();
|
||||
|
@ -344,11 +360,16 @@ module.controller('HomeCtrl', ['$rootScope', '$scope', '$document', '$HUB', '$RP
|
|||
};
|
||||
|
||||
$scope.groupDefaultCla = function(gist){
|
||||
if (gist.url === 'https://gist.github.com/CLAassistant/bd1ea8ec8aa0357414e8') {
|
||||
return 'Default CLAs';
|
||||
}
|
||||
var found = false;
|
||||
|
||||
return 'My Gist Files';
|
||||
$scope.defaultClas.some(function(defCla){
|
||||
if (gist.url === defCla.url) {
|
||||
found = true;
|
||||
return found;
|
||||
}
|
||||
});
|
||||
|
||||
return found ? 'Default CLAs' : 'My Gist Files';
|
||||
};
|
||||
}
|
||||
])
|
||||
|
|
|
@ -78,22 +78,26 @@ module.exports = {
|
|||
});
|
||||
},
|
||||
|
||||
sign: function(req, done) {
|
||||
getAll: function(req, done){
|
||||
cla.getAll(req.args, done);
|
||||
},
|
||||
|
||||
sign: function(req, done) {
|
||||
var args = {repo: req.args.repo, owner: req.args.owner, user: req.user.login, user_id: req.user.id};
|
||||
|
||||
cla.sign(args, function(err, signed){
|
||||
if (err) {log.error(err);}
|
||||
if (err) {log.error(err); }
|
||||
repoService.get({repo: args.repo, owner: args.owner}, function(e, repo){
|
||||
if (e) {log.error(e);}
|
||||
if (e) {log.error(e); }
|
||||
github.direct_call({url: url.githubPullRequests(args.owner, args.repo, 'open'), token: repo.token}, function(error, res){
|
||||
if (error) {log.error(error);}
|
||||
if (error) {log.error(error); }
|
||||
|
||||
if(res && res.data && !error){
|
||||
res.data.forEach(function(pullRequest){
|
||||
var status_args = {repo: args.repo, owner: args.owner};
|
||||
status_args.number = pullRequest.number;
|
||||
cla.check(status_args, function(cla_err, all_signed){
|
||||
if (cla_err) {log.error(cla_err);}
|
||||
if (cla_err) {log.error(cla_err); }
|
||||
status_args.signed = all_signed;
|
||||
status.update(status_args);
|
||||
prService.editComment({repo: args.repo, owner: args.owner, number: status_args.number, signed: all_signed});
|
||||
|
@ -104,15 +108,11 @@ module.exports = {
|
|||
});
|
||||
done(err, signed);
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
getAll: function(req, done){
|
||||
cla.getAll(req.args, done);
|
||||
},
|
||||
|
||||
check: function(req, done){
|
||||
check: function(req, done){
|
||||
var args = {repo: req.args.repo, owner: req.args.owner, user: req.user.login};
|
||||
|
||||
cla.check(args, done);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,6 +26,20 @@ router.use('/accept/:owner/:repo', function(req, res) {
|
|||
}
|
||||
});
|
||||
|
||||
router.all('/static/*', function(req, res) {
|
||||
var filePath;
|
||||
if (req.user && req.path === '/static/cla-assistant.json') {
|
||||
filePath = path.join(__dirname, '..', '..', '..', 'cla-assistant.json');
|
||||
}
|
||||
else {
|
||||
filePath = path.join(__dirname, '..', '..', 'client', 'login.html');
|
||||
}
|
||||
// res.setHeader('Cache-Control', 'must-revalidate, private');
|
||||
// res.setHeader('Expires', '-1');
|
||||
res.setHeader('Last-Modified', (new Date()).toUTCString());
|
||||
res.status(200).sendFile(filePath);
|
||||
});
|
||||
|
||||
router.all('/*', function(req, res) {
|
||||
var filePath;
|
||||
if (req.user || req.path !== '/') {
|
||||
|
|
|
@ -30,6 +30,10 @@ describe('Home Controller', function() {
|
|||
files: {'file.txt': {filename: 'file1'}}
|
||||
}]));
|
||||
httpBackend.when('POST', '/api/repo/getAll', {set: [{owner: 'octocat', repo: 'Hello-World'}, {owner: 'orgOwner'}]}).respond([{repo: 'Hello-World', owner: 'octocat', gist: 1234}]);
|
||||
httpBackend.when('GET', '/static/cla-assistant.json').respond({ 'default-cla': [{
|
||||
'name': 'first default cla',
|
||||
'url': 'https://gist.github.com/gistId'
|
||||
}]});
|
||||
|
||||
}));
|
||||
|
||||
|
@ -136,7 +140,7 @@ describe('Home Controller', function() {
|
|||
|
||||
homeCtrl.scope.selectedGist.gist = {url: 'https://gist.github.com/gistId'};
|
||||
homeCtrl.scope.selectedRepo.repo = {id: 123, name: 'myRepo', full_name: 'login/myRepo', owner: {login: 'login'}};
|
||||
|
||||
|
||||
httpBackend.expect('POST', '/api/repo/create', { repo: 'myRepo', owner: 'login', gist: homeCtrl.scope.selectedGist.gist.url}).respond(500, {err: 'nsertDocument :: caused by :: 11000 E11000 duplicate key error index: cla-staging.repos.$repo_1_owner_1 dup key: { : "myRepo", : "login" }'});
|
||||
httpBackend.expect('POST', '/api/webhook/create', { repo: 'myRepo', owner: 'login' }).respond(null, {active: true});
|
||||
httpBackend.expect('POST', '/api/webhook/remove', { repo: 'myRepo', user: 'login' }).respond({});
|
||||
|
@ -244,7 +248,7 @@ describe('Home Controller', function() {
|
|||
httpBackend.flush();
|
||||
|
||||
(homeCtrl.scope.gists.length).should.be.equal(3);
|
||||
(homeCtrl.scope.gists[0].name).should.be.equal('SAP individual CLA');
|
||||
(homeCtrl.scope.gists[0].name).should.be.equal('first default cla');
|
||||
(homeCtrl.scope.gists[1].name).should.be.equal('ring.erl');
|
||||
(homeCtrl.scope.gists[2].name).should.be.equal('file1');
|
||||
});
|
||||
|
@ -261,14 +265,18 @@ describe('Home Controller', function() {
|
|||
it('should identify default gist url from all gists', function(){
|
||||
httpBackend.flush();
|
||||
|
||||
var sapClaGist = {name: 'SAP individual CLA', url: 'https://gist.github.com/CLAassistant/bd1ea8ec8aa0357414e8'};
|
||||
var sapClaGist = {name: 'first default cla', url: 'https://gist.github.com/gistId'};
|
||||
(homeCtrl.scope.groupDefaultCla(sapClaGist)).should.be.equal('Default CLAs');
|
||||
|
||||
var anyOtherGist = {name: 'any name', url: 'https://gist.github.com/gitID'};
|
||||
(homeCtrl.scope.groupDefaultCla(anyOtherGist)).should.not.be.equal('Default CLAs');
|
||||
});
|
||||
|
||||
xit('should handle multiple error messages', function(){
|
||||
it('should load default cla files', function(){
|
||||
httpBackend.flush();
|
||||
|
||||
homeCtrl.scope.defaultClas.length.should.be.equal(1);
|
||||
homeCtrl.scope.defaultClas[0].name.should.be.equal('first default cla');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче