Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
Created November 15, 2019 14:04
Show Gist options
  • Save RyanNutt/0776832fc36f0384d7a715fb5bbe5e86 to your computer and use it in GitHub Desktop.
Save RyanNutt/0776832fc36f0384d7a715fb5bbe5e86 to your computer and use it in GitHub Desktop.
Tapermonkey script to add Travis CI badges to GitHub Classroom
// ==UserScript==
// @name GitHub Classroom Badges
// @namespace https://compsci.rocks/
// @version 0.1
// @description Add Travis build badges to repos in GitHub Classroom
// @author Ryan Nutt
// @website https://compsci.rocks/
// @include /^https?://classroom\.github\.com/classrooms/(.*)?/(group-)?assignments/(.*)?
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==
function addBadge(node) {
var token = 'YOUR_TRAVIS_TOKEN';
var btn = node.find('a.btn[role="button"]');
if (btn.length) {
var href = btn.attr('href');
var src = href.replace('github.com', 'api.travis-ci.com') + '.svg?token=' + token + '&branch=master';
$('<div><a href="' + href.replace('github.com', 'travis-ci.com') + '/builds" target="_blank"><img class="travis-badge" src="' + src + '"></a></div>').insertAfter(btn);
}
}
waitForKeyElements('div.assignment-container .assignment-repo-list-item', addBadge);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment