Skip to content

Commit

Permalink
added issue
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickHeneise committed Nov 8, 2015
1 parent 0c4a5a5 commit ff854cb
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 12 deletions.
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions data/issue.md
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 16 additions & 11 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
19 changes: 18 additions & 1 deletion tests/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});

0 comments on commit ff854cb

Please sign in to comment.