Skip to content

Commit

Permalink
use exec
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Lord committed Jan 22, 2014
1 parent 0bfa328 commit 03000e6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 103 deletions.
2 changes: 1 addition & 1 deletion problems/commit_to_it/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var exec = require('child_process').exec

// check that they've commited changes

exec('git config user.username', function(err, stdout, stdrr) {
exec('git show', function(err, stdout, stdrr) {
var show = stdout.trim()

if (show.match("new file mode") && show.match("commit"))
Expand Down
16 changes: 6 additions & 10 deletions problems/forks_and_clones/verify.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#!/usr/bin/env node

var spawn = require('child_process').spawn
var concat = require('concat-stream')

var remote = spawn('git', ['remote', '-v'])

remote.stdout.pipe(concat(onRemote))
var exec = require('child_process').exec

// check that they've added the remote, that shows
// that they've also then forked and cloned.

function onRemote(output) {
var show = output.toString().trim()
exec('git remote -v', function(err, stdout, stdrr) {
var show = stdout.trim()

if (show.match("upstream") && show.match("github.com/jlord/"))
console.log("Upstream remote set up!")
console.log("Upstream remote set up!")
else return console.log("No upstream remote")
}
})
17 changes: 6 additions & 11 deletions problems/get_git/verify.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env node

var spawn = require('child_process').spawn
var concat = require('concat-stream')
var exec = require('child_process').exec

// check that Git is installed

var git = spawn('git', ['--version'])

git.stdout.pipe(concat(onGit))

function onGit(output) {
var gitOutput = output.toString().trim()
if (gitOutput.match("git version")) {
exec('git --version', function(err, stdout, stdrr) {
var gitOutput = stdout.trim()

if (gitOutput.match("git version"))
console.log("Found Git installed.")
}
else console.log("Found no Git installed.")
}
})
16 changes: 6 additions & 10 deletions problems/its_a_small_world/verify.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
#!/usr/bin/env node

var request = require('request')
var spawn = require('child_process').spawn
var concat = require('concat-stream')
var exec = require('child_process').exec

// var url = "http://localhost:5563/collab?username="
var url = 'http://reporobot.jlord.us/collab?username='
var user = spawn('git', ['config', 'user.username'])

user.stdout.pipe(concat(onUser))

function onUser(output) {
var username = output.toString().trim()
exec('git config user.username', function(err, stdout, stdrr) {
var username = stdout.trim()
collaborating(username)
}
})

// check that they've added RR as a collaborator

function collaborating(username) {
request(url + username, {json: true}, function (error, response, body) {
if (error) console.log(error)
if (!error && response.statusCode == 200) {
if (body.collab = true)
if (body.collab = true) console.log("Reporobot has been added!")
else console.log("Reporobot doesn't have access to the fork")
if (body.error) console.log(body)
}
})
}
}
53 changes: 19 additions & 34 deletions problems/merge_tada/verify.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
#!/usr/bin/env node

var spawn = require('child_process').spawn
var concat = require('concat-stream')

var ref = spawn('git', ['reflog', '-10'])
var username = spawn('git', ['config', 'user.username'])

var user = ""

ref.stdout.pipe(concat(onRef))
username.stdout.pipe(concat(onUser))
var exec = require('child_process').exec

// check that they performed a merge
// check there is not username named branch

function onRef(output) {
var ref = output.toString().trim()
if (ref.match("merge"))
console.log("Branch has been merged!")
else return console.log("No merge in the history.")
}

function onUser(output) {
user = output.toString().trim()
getBranches(onBranch)
}

function getBranches(callback) {
var branches = spawn('git', ['branch'])
branches.stdout.pipe(concat(callback))
}

function onBranch(output) {
var branch = output.toString().trim()
if (branch.match(user)) {
console.log("Uh oh, branch is still there.")
}
else return console.log("Branch deleted!")
}
exec('git reflog -10', function(err, stdout, stdrr) {
var ref = stdout.trim()
var user = ""

if (ref.match("merge")) console.log("Branch has been merged!")
else console.log("No merge in the history.")

exec('git config user.username', function(err, stdout, stdrr) {
user = stdout.trim()

exec('git branch', function(err, stdout, stdrr) {
branches = stdout.trim()

if (branches.match(user)) console.log("Uh oh, branch is still there.")
else return console.log("Branch deleted!")
})
})
})
39 changes: 17 additions & 22 deletions problems/remote_control/verify.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
#!/usr/bin/env node

var child = require('child_process')
var spawn = child.spawn
var concat = require('concat-stream')

var ref = spawn('git', ['reflog', 'show', 'origin/master'])

ref.stdout.pipe(concat(onRef))
var exec = require('child_process').exec

// check that they've made a push

function onRef(output) {
var ref = output.toString().trim()
exec('git reflog show origin/master', function(err, stdout, stderr) {
var ref = stdout.trim()

if (ref.match("update by push")) console.log("Bingo! Detected a push.")
else console.log("No evidence of push.")
}

// verify they set up git config

child.exec('git config user.email', function(err, stdout, stderr) {
var email = stdout.trim()
child.exec('git config user.username', function(err, stdout, stderr) {
var user = stdout.trim()
if (user === "") console.error("No username found.")
else console.log("Username added!")
if (email === "") console.error("No email found.")
else console.log("Email added!")
// verify they set up git config
exec('git config user.email', function(err, stdout, stderr) {
var email = stdout.trim()
exec('git config user.username', function(err, stdout, stderr) {
var user = stdout.trim()
if (user === "") console.error("No username found.")
else console.log("Username added!")
if (email === "") console.error("No email found.")
else console.log("Email added!")
})
})
})
})
5 changes: 1 addition & 4 deletions problems/repository/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ var exec = require('child_process').exec
exec('git status', function(err, stdout, stdrr) {
// if (err) console.log(err)
var status = stdout.trim()
// console.log("Status", status)
if (status.match("On branch")){
console.log("This is a Git repository!")
}
if (status.match("On branch")) console.log("This is a Git repository!")
else console.log("This folder isn't \nbeing tracked by Git.")
})
18 changes: 7 additions & 11 deletions problems/requesting_you_pull_please/verify.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#!/usr/bin/env node

var exec = require('child_process').exec
var request = require('request')
var spawn = require('child_process').spawn
var concat = require('concat-stream')

// var url = "http://localhost:5563/pr?username="
var url = 'http://reporobot.jlord.us/pr?username='
var user = spawn('git', ['config', 'user.username'])

user.stdout.pipe(concat(onUser))

function onUser(output) {
var username = output.toString().trim()
pullrequest(username)
}

// check that they've submitted a pull request
// to the original repository jlord/patchwork

exec('git config user.username', function(err, stdout, stdrr) {
var username = stdout.trim()
pullrequest(username)
})

function pullrequest(username) {
request(url + username, {json: true}, function (error, response, body) {
if (!error && response.statusCode == 200) {
Expand All @@ -26,4 +22,4 @@ function pullrequest(username) {
else console.log("No pull request found for " + username)
}
})
}
}

0 comments on commit 03000e6

Please sign in to comment.