Last active
August 29, 2015 14:01
-
-
Save MathRivest/d5c67827af22203f8b6f to your computer and use it in GitHub Desktop.
Dashing - Gitlab Latest Commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GITLAB_BASE_URL = "" | |
GITLAB_TOKEN = "" | |
# Retrieve the repositories and commits in gitlab | |
SCHEDULER.every '5m', :first_in => 0 do |job| | |
uri = URI("#{GITLAB_BASE_URL}projects?private_token=#{GITLAB_TOKEN}") | |
response = Net::HTTP.get(uri) | |
data = JSON.parse(response) | |
commits = Array.new | |
# Loop thru all the repos | |
data.each do |repo| | |
repoId = repo["id"] | |
repoCommitsUri = URI("#{GITLAB_BASE_URL}projects/#{repoId}/repository/commits?private_token=#{GITLAB_TOKEN}") | |
repoCommitsResponse = Net::HTTP.get(repoCommitsUri) | |
repoCommitsData = JSON.parse(repoCommitsResponse) | |
# Loop thru all the commits and fill my array | |
repoCommitsData.each do |commit| | |
commits.push({ | |
label: repo["name"] + " - " + commit["title"], | |
value: commit["author_name"], | |
created_at: commit["created_at"], | |
project: repo["name"] | |
}) | |
end | |
end | |
sortedCommits = commits.sort_by {|obj| obj[:created_at]} | |
sortedCommits = sortedCommits.reverse[0..4] | |
#puts sortedCommits | |
# Send the event to the list of latest commits | |
send_event('gitlab_latest_commits', { items: sortedCommits}) | |
text = sortedCommits.at(0)[:label] + " by " + sortedCommits.at(0)[:value] + " on " + sortedCommits.at(0)[:project] | |
#puts text | |
# Send the event to the text widget | |
send_event('gitlab_latest_commit', { | |
text: text | |
}) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li data-row="1" data-col="1" data-sizex="2" data-sizey="1"> | |
<div data-id="gitlab_latest_commits" data-view="List" data-title="Latest Commits" style="background-color:#00a060;"></div> | |
<i class="icon-code icon-background"></i> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment