Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: afeld/repowatch
base: 814825375c
...
head fork: afeld/repowatch
compare: 64b697c038
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 69 additions and 26 deletions.
  1. +19 −17 models/repo.js
  2. +45 −4 test/user_test.js
  3. +5 −5 worker.js
View
36 models/repo.js
@@ -7,23 +7,25 @@ var RepoSchema = new mongoose.Schema({
url: { type: String, validate: GH_REGEX }
});
-RepoSchema.methods = {
- getGhRepo: function(){
- return this.url.match(GH_REGEX)[1];
- },
-
- getUser: function(){
- return this.url.match(GH_REGEX)[2];
- },
-
- getName: function(){
- return this.url.match(GH_REGEX)[3];
- },
-
- getCloneUrl: function(){
- return 'git://github.com/' + this.getGhRepo() + '.git';
- }
-};
+RepoSchema.virtual('_urlMatch').get(function(){
+ return this.url.match(GH_REGEX);
+});
+
+RepoSchema.virtual('ghRepo').get(function(){
+ return this._urlMatch[1];
+});
+
+RepoSchema.virtual('user').get(function(){
+ return this._urlMatch[2];
+});
+
+RepoSchema.virtual('name').get(function(){
+ return this._urlMatch[3];
+});
+
+RepoSchema.virtual('cloneUrl').get(function(){
+ return 'git://github.com/' + this.ghRepo + '.git';
+});
module.exports = {
View
49 test/user_test.js
@@ -7,7 +7,25 @@ require('../config/db');
// Create a Test Suite
vows.describe('User').addBatch({
- 'with a real Github repo': {
+ 'with an invalid Github URL': {
+ topic: function () {
+ return new User({
+ repos: [
+ { url: 'gobbldy-gook' }
+ ]
+ });
+ },
+
+ 'when saved': {
+ topic: function(user){ user.save(this.callback); },
+
+ 'should give a validation error on the repo url': function(err){
+ assert.ok(err.errors.url, 'repos should have thrown a validation error');
+ }
+ }
+ },
+
+ 'with a real Github URL': {
topic: function () {
return new User({
repos: [
@@ -20,9 +38,32 @@ vows.describe('User').addBatch({
topic: function(user){ user.save(this.callback); },
'should not have any errors': function(err){
- assert.equal(err.errors, null);
+ assert.ok(!err, 'no error should have been thrown');
+ }
+ },
+
+ 'the repo': {
+ topic: function(user){ return user.repos[0]; },
+
+ 'should provide a .ghRepo': function(repo){
+ assert.equal(repo.ghRepo, 'afeld/backbone-nested');
+ },
+
+ 'should provide a .user': function(repo){
+ assert.equal(repo.user, 'afeld');
+ },
+
+ 'should provide a .name': function(repo){
+ assert.equal(repo.name, 'backbone-nested');
+ },
+
+ 'should provide a .cloneUrl': function(repo){
+ assert.equal(repo.cloneUrl, 'git://github.com/afeld/backbone-nested.git');
}
}
-
}
-}).export(module);
+}).export(module, {
+ // handing errors from mongoose is a pain without this flag... see
+ // https://github.com/cloudhead/vows/issues/24
+ error: false
+});
View
10 worker.js
@@ -15,10 +15,10 @@ var mail = require('mail').Mail({
// clone and/or update repo
function cloneRepo(repo, callback){
- var repoName = repo.getName(),
- clonePath = 'tmp/' + repo.getUser();
+ var repoName = repo.name,
+ clonePath = 'tmp/' + repo.user;
- exec('mkdir -p ' + clonePath + ' && cd ' + clonePath + ' && git clone ' + repo.getCloneUrl() + ' && cd ' + repoName + ' && git pull', function(){
+ exec('mkdir -p ' + clonePath + ' && cd ' + clonePath + ' && git clone ' + repo.cloneUrl + ' && cd ' + repoName + ' && git pull', function(){
callback(clonePath + '/' + repoName);
});
}
@@ -49,7 +49,7 @@ function notifyNewVersion(user, repo, version){
mail.message({
from: 'repowatcher@gmail.com',
to: [user.email],
- subject: 'New version of ' + repo.getGhRepo() + ' - ' + version
+ subject: 'New version of ' + repo.ghRepo + ' - ' + version
})
.body("You're welcome!")
.send(function(err) {
@@ -65,7 +65,7 @@ User.find().each(function(err, user){
user.repos.forEach(function(repo){
findMostRecent(repo, function(masterSha, version){
- var ghRepo = repo.getGhRepo();
+ var ghRepo = repo.ghRepo;
if (version){
console.log(ghRepo, version);
notifyNewVersion(user, repo, version);

No commit comments for this range

Something went wrong with that request. Please try again.