Skip to content

Commit

Permalink
chore: add pending_presubmits.sh
Browse files Browse the repository at this point in the history
Script that shows pending presubmit branches that need attention
such as manual merge.
  • Loading branch information
vojtajina committed Jul 17, 2014
1 parent 05ed78f commit 51f1b88
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
13 changes: 13 additions & 0 deletions scripts/pending_presubmits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Shows a list of pending presubmit branches that have not been merged.
# These branches need manual attention.

# Fetch all the upstream branches.
git fetch upstream

# List all upstream/presubmit-* branches that have not been merged into upstream/master neither upstream/canary yet.
BRANCHES=$(comm -12 <(git branch -r --no-merged upstream/master) <(git branch -r --no-merged upstream/canary) | egrep "^\s*upstream/presubmit-" | sed "s# upstream/##")

# Print Travis status of all these branches.
./scripts/print_travis_status.js "karma-runner/karma" "$BRANCHES" "$@"
80 changes: 80 additions & 0 deletions scripts/print_travis_status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env node
'use strict';

var http = require('https');

var COLORS = {
green : ['\x1B[32m', '\x1B[39m'],
red : ['\x1B[31m', '\x1B[39m']
};

var repo = process.argv[2];
var branches = process.argv[3];

if (!branches) {
console.log('No pending branches.');
process.exit(0);
}

branches = branches.split('\n');

var options = {
hostname: 'api.travis-ci.org',
headers: {
'User-Agent': 'Vojta/0.0.1',
'Accept': 'application/vnd.travis-ci.2+json'
}
};

function red(str) {
return COLORS.red[0] + str + COLORS.red[1];
}

function green(str) {
return COLORS.green[0] + str + COLORS.green[1];
}

function bufferJsonStream(stream, done) {
var buffer = '';

stream.on('data', function(data) {
buffer += data.toString();
});

stream.on('end', function() {
done(JSON.parse(buffer));
});
}

branches.forEach(function(branch) {
options.path = '/repos/' + repo + '/branches/' + branch;

http.get(options, function(response) {
bufferJsonStream(response, function(resp) {

console.log('Branch: ' + branch);
console.log(' https://github.com/' + repo + '/tree/' + branch);

if (response.headers.status === '404 Not Found') {
console.log(red('Travis: NOT FOUND'));
} else {
switch (resp.branch.state) {
case 'passed':
console.log(green('Travis: ' + resp.branch.state + ' (' + resp.branch.finished_at + ')'));
break;
case 'failed':
console.log(red('Travis: ' + resp.branch.state + ' (' + resp.branch.finished_at + ')'));
break;
case 'started':
console.log('Travis: ' + resp.branch.state + ' (' + resp.branch.started_at + ')');
break;
default:
console.log('Travis: ' + resp.branch.state);
}
console.log(' https://travis-ci.org/' + repo + '/builds/' + resp.branch.id);
}

console.log('');
});
});
});

0 comments on commit 51f1b88

Please sign in to comment.