Skip to content

Commit

Permalink
Broke strider config out of package.json and into strider.json
Browse files Browse the repository at this point in the history
Moved parseRepo out of codeplex.js and into webapp.js
Removed some logging from passport-codeplex.js
Added mongoose templates to webapp.js
Added method stubs that strider docs say are required.
  • Loading branch information
abe545 committed Mar 16, 2014
1 parent 7c04782 commit 8db71d8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 55 deletions.
23 changes: 2 additions & 21 deletions lib/codeplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@ var https = require('https');
module.exports = {
getRepos: function(account, callback) {
getCodeplex(account, '/api/user/projects', callback);
},
parseRepo: function(account, repo) {
return {
id: account.name + '/' + repo.Name,
name: repo.Name,
display_name: repo.Title,
display_url: repo.Url,
group: account.name,
'private': !repo.IsPublished,
config: {
auth: { type: 'ssh' },
scm: repo.SourceControl.ServerType,
url: repo.SourceControl.Url
}
}
}
}

Expand Down Expand Up @@ -46,12 +31,8 @@ function getCodeplex(account, resourcePath, callback) {
var fin = JSON.parse(json);

// this is an error message
if (fin.Message) {
callback(fin.Message, null);
}
else {
callback(null, fin);
}
if (fin.Message) { callback(fin.Message, null); }
else { callback(null, fin); }
});
});

Expand Down
1 change: 0 additions & 1 deletion lib/passport-codeplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Strategy.prototype.userProfile = function(accessToken, done) {
return done(new Error('Failed to parse user profile'));
}

console.log(json);
done(null, json);
});
}
Expand Down
15 changes: 0 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
},
"license": "GPL-2.0",
"readmeFilename": "Readme.md",
"strider": {
"id": "codeplex",
"title": "Codeplex",
"type": "provider",
"hosted": true,
"config": {
"controller": "CodeplexController"
},
"accountConfig": {
"setupLink": "/ext/codeplex/oauth"
},
"webapp": "webapp.js",
"worker": "worker.js",
"inline_icon": "windows"
},
"dependencies": {
"passport-oauth2": "1.x.x"
},
Expand Down
15 changes: 15 additions & 0 deletions strider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "codeplex",
"title": "Codeplex",
"type": "provider",
"hosted": true,
"config": {
"controller": "CodeplexController"
},
"accountConfig": {
"setupLink": "/ext/codeplex/oauth"
},
"webapp": "webapp.js",
"worker": "worker.js",
"inline_icon": "windows"
}
74 changes: 56 additions & 18 deletions webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ module.exports = {
clientId: 'feecb876f9044bca8a86ab9089fba8b0',
clientSecret: 'efc1e8c120c24b59b12ad0f4f7d32d02'
},

accountConfig: {
accessToken: String,
name: String,
avatar: String
},

config: {
sourceType: String,
sourceUrl: String,
role: String
},

// oauth global routes
globalRoutes: function (app, context) {
Expand All @@ -19,30 +31,43 @@ module.exports = {
res.redirect('/projects');
});
},

listRepos: function (account, next) {
codeplex.getRepos(account, function(err, data) {
if (err) return next(err)
next(null, data.map(function(repo) { return codeplex.parseRepo(account, repo); }).filter(function (repo) {
return repo.config.scm === 'Git' ||
repo.config.scm === 'Mercurial';
}))
});

// namespaced to /org/repo/api/codeplex/
routes: function (app, context) {
},

// register the passport auth strategy
auth: function (passport, context) {
var config = this.appConfig
passport.use(new CodeplexStrategy({
clientID: this.appConfig.clientId,
clientSecret: this.appConfig.clientSecret,
callbackURL: this.appConfig.hostname + '/ext/codeplex/oauth/callback',
passReqToCallback: true
}, validateAuth));
},

listRepos: function (account, callback) {
codeplex.getRepos(account, function(err, data) {
if (err) return callback(err)
callback(null, data.map(function(repo) { return parseRepo(account, repo); }))
});
},

isSetup: function (account) {},

setupRepo: function (account, config, project, done) {
},

teardownRepo: function (account, config, project, done) {
},

getBranches: function (account, config, project, done) {
},

getFile: function (filename, ref, account, config, project, done) {
}
}

function validateAuth(req, token, tokenSecret, profile, done) {
function validateAuth(req, accessToken, parms, profile, done) {
if (!req.user) {
console.warn('Codeplex OAuth but no logged-in user')
req.flash('account', "Cannot link a codeplex account if you aren't logged in")
Expand All @@ -55,25 +80,38 @@ function validateAuth(req, token, tokenSecret, profile, done) {
return done(null, req.user)
}

req.user.accounts.push(makeAccount(token, tokenSecret, profile))
req.user.accounts.push(makeAccount(accessToken, profile))
req.user.save(function (err) {
done(err, req.user);
})
}

function makeAccount(token, tokenSecret, profile) {
function makeAccount(accessToken, profile) {
var username = profile.UserName;
return {
provider: 'codeplex',
id: username,
display_url: 'https://www.codeplex.com/site/users/view/' + username,
title: username,
config: {
accessToken: token,
tokenSecret: tokenSecret,
login: username,
accessToken: accessToken,
name: username,
avatar: profile.Avatar,
avatar: profile.Avatar
}
}
}

function parseRepo(account, repo) {
return {
name: account.name + '/' + repo.Name,
display_name: repo.Title,
display_url: repo.Url,
group: account.name,
'private': !repo.IsPublished,
config: {
sourceType: repo.SourceControl.ServerType,
sourceUrl: repo.SourceControl.Url,
role: repo.Role
}
}
}

0 comments on commit 8db71d8

Please sign in to comment.