<commit_before>require 'json'
require 'time'
require 'dashing'
require 'net/https'
require 'cgi'
require File.expand_path('../../lib/travis_backend', __FILE__)

$lastTravisItems = []

SCHEDULER.every '2m', :first_in => '1s' do |job|
	backend = TravisBackend.new
	repo_slugs = []
	builds = []
	# Only look at release branches (x.y) and master, not at tags (x.y.z)
	branch_whitelist = /^(\d+\.\d+$|master)/
	branch_blacklist_by_repo = JSON.parse(ENV['TRAVIS_BRANCH_BLACKLIST']) || {}
	repo_slug_replacements = [/(silverstripe-labs\/|silverstripe\/|silverstripe-)/,'']

	if ENV['ORGAS']
		ENV['ORGAS'].split(',').each do |orga|
			repo_slugs = repo_slugs.concat(backend.get_repos_by_orga(orga).collect{|repo|repo['slug']})
		end
	end
	
	if ENV['REPOS']
		repo_slugs.concat(ENV['REPOS'].split(','))
	end

	repo_slugs.sort!

	items = repo_slugs.map do |repo_slug|
		repo_branches = backend.get_branches_by_repo(repo_slug)
		label = repo_slug
		label = repo_slug.gsub(repo_slug_replacements[0],repo_slug_replacements[1]) if repo_slug_replacements
		if repo_branches and repo_branches['branches'].length > 0
			# Latest builds are listed under "branches", but their corresponding branch name
			# is stored through the "commits" association
			items = repo_branches['branches']
				.select do |branch|
					commit = repo_branches['commits'].find{|commit|commit['id'] == branch['commit_id']}
					branch_name = commit['branch']

					# Ignore branches not in whitelist
					if not branch_whitelist.match(branch_name) 
						false
					# Ignore branches specifically blacklisted
					elsif branch_blacklist_by_repo.has_key?(repo_slug) and branch_blacklist_by_repo[repo_slug].include?(branch_name)
						false
					else
						true
					end
				end
				.map do |branch|
					commit = repo_branches['commits'].find{|commit|commit['id'] == branch['commit_id']}
					branch_name = commit['branch']
					{
						'class'=>(["passed","started"].include?(branch['state'])) ? 'good' : 'bad', # POSIX return code
						'label'=>branch_name,
						'title'=>branch['finished_at'],
						'result'=>branch['state'],
						'url'=> 'https://travis-ci.org/%s/builds/%d' % [repo_slug,branch['id']]
					} 
				end
			{
				'label'=>label,
				'class'=> (items.find{|b|b['result'] != 'passed'}) ? 'bad' : 'good', # POSIX return code
				'url' => items.count ? 'https://travis-ci.org/%s' % repo_slug : '',
				'items' => items
			}
		else
			{
				'label'=>label,
				'class'=> 'none',<commit_msg>Fixed travis build status for "started" builds<commit_after>require 'json'
require 'time'
require 'dashing'
require 'net/https'
require 'cgi'
require File.expand_path('../../lib/travis_backend', __FILE__)

$lastTravisItems = []

SCHEDULER.every '2m', :first_in => '1s' do |job|
	backend = TravisBackend.new
	repo_slugs = []
	builds = []
	# Only look at release branches (x.y) and master, not at tags (x.y.z)
	branch_whitelist = /^(\d+\.\d+$|master)/
	branch_blacklist_by_repo = JSON.parse(ENV['TRAVIS_BRANCH_BLACKLIST']) || {}
	repo_slug_replacements = [/(silverstripe-labs\/|silverstripe\/|silverstripe-)/,'']

	if ENV['ORGAS']
		ENV['ORGAS'].split(',').each do |orga|
			repo_slugs = repo_slugs.concat(backend.get_repos_by_orga(orga).collect{|repo|repo['slug']})
		end
	end
	
	if ENV['REPOS']
		repo_slugs.concat(ENV['REPOS'].split(','))
	end

	repo_slugs.sort!

	items = repo_slugs.map do |repo_slug|
		repo_branches = backend.get_branches_by_repo(repo_slug)
		label = repo_slug
		label = repo_slug.gsub(repo_slug_replacements[0],repo_slug_replacements[1]) if repo_slug_replacements
		if repo_branches and repo_branches['branches'].length > 0
			# Latest builds are listed under "branches", but their corresponding branch name
			# is stored through the "commits" association
			items = repo_branches['branches']
				.select do |branch|
					commit = repo_branches['commits'].find{|commit|commit['id'] == branch['commit_id']}
					branch_name = commit['branch']

					# Ignore branches not in whitelist
					if not branch_whitelist.match(branch_name) 
						false
					# Ignore branches specifically blacklisted
					elsif branch_blacklist_by_repo.has_key?(repo_slug) and branch_blacklist_by_repo[repo_slug].include?(branch_name)
						false
					else
						true
					end
				end
				.map do |branch|
					commit = repo_branches['commits'].find{|commit|commit['id'] == branch['commit_id']}
					branch_name = commit['branch']
					{
						'class'=>(["passed","started"].include?(branch['state'])) ? 'good' : 'bad', # POSIX return code
						'label'=>branch_name,
						'title'=>branch['finished_at'],
						'result'=>branch['state'],
						'url'=> 'https://travis-ci.org/%s/builds/%d' % [repo_slug,branch['id']]
					} 
				end
			{
				'label'=>label,
				'class'=> (items.find{|b|["passed","started"].include?(b['result'])}) ? 'bad' : 'good', # POSIX return code
				'url' => items.count ? 'https://travis-ci.org/%s' % repo_slug : '',
				'items' => items
			}
		else
			{
				'label'=>label,
				'class'=> 'none',
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.0020056157240272766, 'mean_word_length': 4.141237113402062, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2303605', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1793, 'n_words': 328}