diff --git a/app.js b/app.js index faf0b46..253f521 100755 --- a/app.js +++ b/app.js @@ -73,6 +73,11 @@ passport.deserializeUser(function(user, done) { done(null, user); }); +app.use(function(req, res, next) { + console.log(req.user.accessToken); + next(); +}); + app.get('/', function(req, res) { if (req.user) { res.redirect('/home'); diff --git a/data/issue.md b/data/issue.md new file mode 100644 index 0000000..0d4ad69 --- /dev/null +++ b/data/issue.md @@ -0,0 +1,12 @@ +Dear @{{developer}}, + +@{{user}} matched you on [GitMatch](http://barcelonajs.2015.nodeknockout.com)! + +With GitMatch we analysed your code style and NPM module usage and you have a great match score with this repository. + +This repository is open source and meets all the requirements to be [contribution-friendly](https://github.com/{{user}}/{{repo}}/blob/master/CONTRIBUTING.md). + +Please have a look at the open [issues](https://github.com/{{user}}/{{repo}}/issues) to see if there's something you could help with, @{{user}} would greatly appreciate your contribution. + +Regards, +GitMatch diff --git a/lib/repository.js b/lib/repository.js index 0041410..adb8a64 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -21,6 +21,37 @@ if (process.env.NODE_ENV === 'development') { github.debug = true; } +repository.matchMade = function(user, repo, developer, accessToken) { + return new Promise(function(resolve, reject) { + var file = fs.readFileSync(path.join(process.env.PWD, 'data', 'issue.md')); + + var fileContent = file.toString('utf8'); + fileContent = fileContent.replace(/{{repo}}/g, repo); + fileContent = fileContent.replace(/{{user}}/g, user); + fileContent = fileContent.replace(/{{developer}}/g, developer); + + if (accessToken) { + github.authenticate({ + type: 'oauth', + token: accessToken + }); + } + github.issues.create({ + user: user, + repo: repo, + title: 'Contributor wanted!', + body: fileContent, + labels: ['help wanted', 'gitmatch'] + }, function(error, result) { + if (error) { + reject(error); + } else { + resolve('ok'); + } + }); + }); +}; + repository.getUserRepos = function(accessToken) { return new Promise(function(resolve, reject) { if (accessToken) { diff --git a/package.json b/package.json index b7c086d..1e77841 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "github": "^0.2.4", "jade": "^1.11.0", "morgan": "^1.6.1", + "octodex": "^1.0.0", "passport": "^0.3.0", "passport-github": "^1.0.0", "redis": "^2.3.0", diff --git a/routes/index.js b/routes/index.js index b0ae2eb..cf115d6 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,6 +3,7 @@ var express = require('express'); var repository = require('../lib/repository'); var search = require('../lib/search'); +var cat = require('octodex'); var router = express.Router(); @@ -45,7 +46,7 @@ router.get('/check/:name/:repo', function(req, res) { } req.session.currentRepo = repoName; if (result.hasPackageJson && result.hasIssues && result.hasContribuingMd) { - res.redirect('/match/'+repoName); + res.redirect('/match/' + repoName); } else { res.render('summary', context); } @@ -76,16 +77,20 @@ router.get('/match/:repo', function(req, res) { console.log(req.user); // TODO // Search for users this is only a fake - var match_users = [req.user, req.user, req.user, req.user]; - match_users[0].octodex = "https://octodex.github.com/images/gracehoppertocat.jpg"; - match_users[1].octodex = "https://octodex.github.com/images/gracehoppertocat.jpg"; - match_users[2].octodex = "https://octodex.github.com/images/gracehoppertocat.jpg"; - match_users[3].octodex = "https://octodex.github.com/images/gracehoppertocat.jpg"; - var context = { - user: req.user, - match: match_users - }; - res.render('match', context); + var matchUsers = [req.user, req.user, req.user, req.user]; + cat.img(function(error, url) { + if (!error) { + matchUsers[0].octodex = url; + matchUsers[1].octodex = url; + matchUsers[2].octodex = url; + matchUsers[3].octodex = url; + var context = { + user: req.user, + match: matchUsers + }; + res.render('match', context); + } + }); }); module.exports = router; diff --git a/tests/repository.js b/tests/repository.js index 7e6bda0..2d010d6 100644 --- a/tests/repository.js +++ b/tests/repository.js @@ -32,7 +32,13 @@ nock('https://api.github.com:443') .reply(404, { 'message': 'Not Found', 'documentation_url': 'https://developer.github.com/v3' - }); + }) + .post('/repos/PatrickHeneise/gitup-testing/issues', { + 'title': 'Contributor wanted!', + 'body': 'Dear @Moezalez,\n\n@PatrickHeneise matched you on [GitMatch](http://barcelonajs.2015.nodeknockout.com)!\n\nWith GitMatch we analysed your code style and NPM module usage and you have a great match score with this repository.\n\nThis repository is open source and meets all the requirements to be [contribution-friendly](https://github.com/PatrickHeneise/gitup-testing/blob/master/CONTRIBUTING.md).\n\nPlease have a look at the open [issues](https://github.com/PatrickHeneise/gitup-testing/issues) to see if there\'s something you could help with, @PatrickHeneise would greatly appreciate your contribution.\n\nRegards,\nGitMatch', + 'labels': ['help wanted', 'gitmatch'] + }) + .reply(201); test('getUserRepos', function(t) { t.plan(1); @@ -134,3 +140,14 @@ test('Repo Check #3: Missing package.json', function(t) { t.equal(resolved.hasPackageJson, false); }); }); + +test('matchMade', function(t) { + t.plan(1); + + repository.matchMade('PatrickHeneise', 'gitup-testing', 'Moezalez') + .then(function(resolved) { + t.equal(resolved, 'ok'); + }, function(rejected) { + t.end(rejected); + }); +});