mirror of
https://github.com/usetrmnl/plugins.git
synced 2026-08-13 14:26:58 -07:00
begin oss lib of plugins
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
module Plugins
|
||||
class GithubCommitGraph < Base
|
||||
def locals
|
||||
{ username:, contributions: }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def username = settings['username']
|
||||
|
||||
def contributions
|
||||
query = "query($userName:String!) {
|
||||
user(login: $userName){
|
||||
contributionsCollection {
|
||||
contributionCalendar {
|
||||
totalContributions
|
||||
weeks {
|
||||
contributionDays {
|
||||
contributionCount
|
||||
date
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}"
|
||||
body = {
|
||||
query: query,
|
||||
variables: { userName: settings['username'] }
|
||||
}
|
||||
|
||||
url = 'https://api.github.com/graphql'
|
||||
resp = HTTParty.post(url, body: body.to_json, headers: headers)
|
||||
data = resp.dig('data', 'user', 'contributionsCollection', 'contributionCalendar')
|
||||
|
||||
{ total: data['totalContributions'], commits: data['weeks'] }
|
||||
end
|
||||
|
||||
def headers
|
||||
{ 'authorization' => "Bearer #{Rails.application.credentials.plugins.github_commit_graph_token}" }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,70 @@
|
||||
<div class="screen">
|
||||
<div class="layout">
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<div class="metrics">
|
||||
<div class="metric">
|
||||
<span class="value days_passed"><%= contributions[:total] %></span>
|
||||
<span class="label label--underline">Contributions in last year</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="github_commit_graph">
|
||||
<% contributions[:commits].each do |week_of_commits| %>
|
||||
<% week_of_commits['contributionDays'].each do |day| %>
|
||||
<span class="day <%= git_commit_grayscale(day['contributionCount']) %>"></span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="title_bar">
|
||||
<img class="image" src="<%= Rails.application.credentials.base_url %>/images/plugins/github--render.svg" />
|
||||
<span class="title">GitHub</span>
|
||||
<span class="instance"><%= instance_name %></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#github_commit_graph {
|
||||
width: 758px;
|
||||
height: 148px;
|
||||
overflow: hidden;
|
||||
|
||||
padding-left: 17px;
|
||||
margin-top: 19px;
|
||||
|
||||
column-count: auto;
|
||||
column-fill: auto;
|
||||
column-width: 13px;
|
||||
column-gap: 0px;
|
||||
}
|
||||
|
||||
#github_commit_graph .day {
|
||||
width: 11px;
|
||||
height: 19px;
|
||||
float: left;
|
||||
border-radius: 4px;
|
||||
margin: 2px 2px 0 2px;
|
||||
|
||||
break-inside: avoid-column;
|
||||
}
|
||||
|
||||
#github_commit_graph.widget {
|
||||
width: 318px;
|
||||
/* height: 133px; */
|
||||
height: 63px;
|
||||
column-width: 6px;
|
||||
margin-top: 0;
|
||||
padding-left: 0;
|
||||
margin-left: 14px;
|
||||
}
|
||||
|
||||
#github_commit_graph.widget .day {
|
||||
width: 6px;
|
||||
height: 9px;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user