Skip to content

Instantly share code, notes, and snippets.

View DanPurdy's full-sized avatar

Dan Purdy DanPurdy

View GitHub Profile
@DanPurdy
DanPurdy / Git Branch Highlighting
Created October 9, 2014 08:56
Add this to your bash profile to have git branches and current directory highlighted in your terminal
function git-branch-name {
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
}
function git-branch-prompt {
local branch=`git-branch-name`
if [ $branch ]; then printf " [%s]" $branch; fi
}
PS1="\u@\h \[\033[0;36m\]\W\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "
@DanPurdy
DanPurdy / slack-notify.sh
Last active August 27, 2016 16:31
Bamboo slack notification script
curl -X POST --data-urlencode \
'payload={
"channel": "#SLACK-CHANNEL",
"username": "Bamboo Bot",
"text": "New Build Started",
"icon_emoji": ":octocat:",
"attachments": [
{
"color":"#CFA700",
"title": "${bamboo.repository.name} build #${bamboo.buildNumber}",
@DanPurdy
DanPurdy / github-status-update.sh
Created April 6, 2016 18:34
Updates your github branch status from bamboo based on if your test phase was reached after building your app
cd ${bamboo.build.working.directory}
if [ -d "test-reports" ] 1> /dev/null 2>&1; then
curl -H "Authorization: token <YOUR-GITHUB-TOKEN-HERE>" \
--request POST \
--data \
'{
"state": "success",
"context": "Build",
"description": "Branch was tested successfully",
"target_url": "${bamboo.buildResultsUrl}"
@DanPurdy
DanPurdy / bamboo-eslint-result.sh
Created April 6, 2016 18:46
Checks your eslint output (checkstyle formatted) for errors and reports the status back to github via the status API
## check for eslint errors.
if (grep -c 'severity=\"error\"' test-reports/*.xml 1> /dev/null 2>&1) then
curl -H "Authorization: token <YOUR-GITHUB-TOKEN-HERE>" \
--request POST \
--data \
'{
"state": "failure",
"context": "ESLint",
"description": "Lint errors present",
"target_url": "${bamboo.buildResultsUrl}"
@DanPurdy
DanPurdy / bamboo-karma-result.sh
Created April 6, 2016 19:03
Checks your Karma output (karma-mocha-reporter format) for errors and reports the status back to github via the status API
## Check for Karma errors
if [ -e "test-reports/karma.mocha.json" ]; then
if (grep -c '\"failures\": 0,' "./test-reports/karma.mocha.json" 1> /dev/null 2>&1); then
curl -H "Authorization: token <YOUR-GITHUB-TOKEN-HERE>" \
--request POST \
--data \
'{
"state": "success",
"context": "Karma - Unit tests",
"description": "The unit tests were successful",
@DanPurdy
DanPurdy / bamboo-github-pending-build.sh
Created April 7, 2016 00:05
Sets a pending status in Github from Bamboo
## Pending ESLint tests
curl -H "Authorization: token <YOUR-GITHUB-TOKEN-HERE>" \
--request POST \
--data \
'{
"state": "pending",
"context": "Eslint",
"description": "Preparing to lint code",
"target_url": "${bamboo.buildResultsUrl}"
}' \
@DanPurdy
DanPurdy / slack-status-update.sh
Last active September 4, 2017 17:30
Notify a slack channel about eslint and karma tests passing
cd ${bamboo.build.working.directory}
if [ -d "test-reports" ] 1> /dev/null 2>&1; then
curl -X POST --data-urlencode \
'payload={
"channel": "#SLACK-CHANNEL",
"username": "Bamboo Bot",
"text": "Built succesfully",
"icon_emoji": ":octocat:",
"attachments": [
{
@DanPurdy
DanPurdy / bamboo-remove-test-folder.sh
Created April 7, 2016 01:26
Checks to see if our test reports directory exists, if it does it removes it.
cd ${bamboo.build.working.directory}
if [ -d "test-reports" ]
then
echo "Test Directory exists - Deleting"
rm -r test-reports
echo "Done"
fi
@DanPurdy
DanPurdy / git_branch_purge.sh
Last active September 2, 2016 09:14
Removes all merged branches excluding master/develop
alias gbpurge='git branch --merged | grep -Ev "(\*|master|develop)" | xargs -n 1 git branch -d'
const express = require('express');
const app = express();
const cheerio = require('cheerio');
const request = require('request');
app.get('/', (req, res, next) => {
const url = 'URL HERE';
request(url, (err, resp, body) => {
const $ = cheerio.load(body);
$('.CLASS_HERE').each(function() {