Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/images/builds/canceled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/errored.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/failed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/invalid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/no_tests.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/none.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/passed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/timedout.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/builds/unknown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions public/images/circle-ci-no-builds.svg

This file was deleted.

4 changes: 4 additions & 0 deletions public/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ td, th {
td.left, th.left {
text-align: left;
}

.hide {
display: none;
}
91 changes: 75 additions & 16 deletions src/RepoMatrix.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Promise = require 'bluebird'
Octokat = require 'octokat'
request = require 'request-promise'
{log} = require 'lightsaber'
{flatten, merge, round, sample, size, sortBy} = require 'lodash'
{log, pjson} = require 'lightsaber'
{get, flatten, keys, merge, round, sample, size, sortBy} = require 'lodash'
Wave = require 'loading-wave'
$ = require 'jquery'
require('datatables.net')()
Expand Down Expand Up @@ -69,6 +69,31 @@ class RepoMatrix
CONTRIBUTE = 'CONTRIBUTE.md'
]

CI =
travis:
addProject: (repoFullName) -> "https://travis-ci.org/#{repoFullName}"
urlTemplate: (repoFullName) -> "https://travis-ci.org/#{repoFullName}"
apiTemplate: (repoFullName) -> "https://api.travis-ci.org/repos/#{repoFullName}/branches/master"
apiStatePath: "branch.state"
circle:
addProject: -> "https://circleci.com/add-projects"
urlTemplate: (repoFullName) -> "https://circleci.com/gh/#{repoFullName}"
apiTemplate: (repoFullName) -> "https://circleci.com/api/v1.1/project/github/#{repoFullName}/tree/master"
apiStatePath: "[0].outcome"

# roughly in order of best -> worst states
BUILD_STATES =
passed: 10
success: 10
canceled: 20
unknown: 25
none: 30
no_tests: 35
invalid: 40
timedout: 45
errored: 50
failed: 60

github = new Octokat

@start: ->
Expand Down Expand Up @@ -121,10 +146,14 @@ class RepoMatrix

@showMatrix: (repos) ->
$('#matrix').append @matrix repos
$('table').DataTable
paging: false
searching: false
fixedHeader: true
@loadCiBadges(repos)
.catch (error) =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to catch here any more

console.error error
.then =>
$('table').DataTable
paging: false
searching: false
fixedHeader: true

@getFiles: (repos) ->
repos = sortBy repos, 'fullName'
Expand Down Expand Up @@ -168,8 +197,8 @@ class RepoMatrix
for repo in repos
tr =>
td class: 'left', => a href: "https://github.com/#{repo.fullName}", => repo.fullName # Name
td class: 'left', => @travis repo.fullName # Builds
td class: 'left', => @circle repo.fullName # Builds
td class: 'left', id: "#{@slug(repo.fullName)}-travis" # Builds
td class: 'left', id: "#{@slug(repo.fullName)}-circle" # Builds
td class: 'no-padding', => @check repo.files[README] # README.md
td class: 'no-padding', => @check(repo.files[README]?.length > 500) # README.md
td class: 'no-padding', => @check repo.files[LICENSE] # Files
Expand All @@ -184,20 +213,47 @@ class RepoMatrix
td => repo.stargazersCount.toString()
td => repo.openIssuesCount.toString()

@loadCiBadges: (repos) =>
promises = for ciBrand, ciData of CI
do (ciBrand, ciData) =>
{addProject, apiTemplate, apiStatePath, urlTemplate} = ciData
Promise.map repos, (repo) =>
new Promise (resolve) =>
apiUrl = apiTemplate(repo.fullName)
$.getJSON apiUrl
.fail (err) =>
if err.status is 404
@addCiBadge repo.fullName, ciBrand, 'none', addProject
else
console.error err
resolve()
.done (data) =>
state = get(data, apiStatePath)
if state in keys(BUILD_STATES)
@addCiBadge repo.fullName, ciBrand, state, urlTemplate
else
@addCiBadge repo.fullName, ciBrand, 'unknown', urlTemplate
console.error "Unknown build state `#{state}` -- please add to
BUILD_STATES and add a badge to images/builds/#{state}.svg"
# " -- selector: #{apiStatePath} -- full data:\n#{pjson data}"
resolve()
Promise.all promises

@addCiBadge: (repoFullName, ciBrand, state, urlTemplate) =>
tableCell = $("##{@slug(repoFullName)}-#{ciBrand}")
stateHtml = render -> span class: 'hide', -> BUILD_STATES[state].toString()
badgeHtml = render ->
a href: urlTemplate(repoFullName), _target: '_repos', ->
img src: "images/builds/#{state}.svg"
tableCell.append(stateHtml)
tableCell.append(badgeHtml)

@check: renderable (success) ->
if success
div class: 'success', -> '✓'
else
div class: 'failure', -> '✗'

@travis: renderable (repoFullName) ->
a href: "https://travis-ci.org/#{repoFullName}", ->
img src: "https://travis-ci.org/#{repoFullName}.svg?branch=master"

@circle: renderable (repoFullName) ->
a href: "https://circleci.com/gh/#{repoFullName}", ->
img src: "https://circleci.com/gh/#{repoFullName}.svg?style=svg", onError: "this.parentElement.href = 'https://circleci.com/add-projects'; this.src = 'images/circle-ci-no-builds.svg'"

@loadStats: ->
github.rateLimit.fetch()
.then (info) => $('#stats').append @stats info
Expand All @@ -209,4 +265,7 @@ class RepoMatrix
minutesUntilReset = (reset - now) / 60 # minutes
"Github API calls: #{remaining} remaining of #{limit} limit per hour; clean slate in: #{round minutesUntilReset, 1} minutes"

@slug: (string) ->
string.replace(/\W+/, '-')

module.exports = RepoMatrix