Skip to content

Commit

Permalink
Merge pull request #14 from xebialabs-community/dashboard-tiles
Browse files Browse the repository at this point in the history
Add a contributions pie chart tile and a contributions timeline tile
  • Loading branch information
ndebuhr authored Sep 5, 2019
2 parents 839030b + 8ca41f3 commit c3c4db2
Show file tree
Hide file tree
Showing 12 changed files with 547 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: java
jdk: openjdk8
notifications:
slack:
secure: jvryCN0GB0mH8KuyFhip3rR4SKSlZwDL0vNLrtS8V3O/+LeEgFlUgmFAilmmAmJPDYd3ZGjiIZkZk0brFElaM84RM8QN0B3ku0egokz+L1vY4rI1qBkIkS0rsaT+Rhin1GMiCrX8KoskeRw+PJCTfTIaGZMShzO/aiJkaFo5yQK/H2SI0SUpvkiexkCQrpq0uSN3miHKv9vdUVxU26g/lay3hO713l4K3y457m1692YV4X4ZZgoHK3xTpN0NjXNI0x2vVY4HmaEfApNdkNWSDgvza9L35lrcGbj1eRDlsL6+Zmn+Cy7hx+WPlySMvK8mw0hA4+O0fF1VNQVK6TVwBvQBpAHcYYfPOieQD1BaDlNSAbgJLstQfNYQJUgk6gQnnmbdn6dVfOmaUft2mmK6w4DnF8HZL1whkJKW0Z+84pm1V5qmoA6rUtI1iHTHR+Yqi4+tq1wr/ntTv+ug6oHex9FhtRa6szv9/hO6v7o0jYUnV1/car/VDLw8yoTQ1l6opBalLdt8g9lA6Sw92jXEZlh/oeG2vbw00q8vsUwRmvGTOcbh982YeDrClgywDML6T3pS2sFkitUAfSlMmWP47N4Y4EAr5AQQvfsBiUZwQ7NxsWdVrUFylPeQw1GG9I6IlPb4h7HhD5Gl1ic8zlKb/1BYLvel/Xw3cV5FSxDgi8g=
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ if (!project.hasProperty('release.useLastTag')) {

license {
header rootProject.file('License.md')
strictCheck true
strictCheck false
ext.year = Calendar.getInstance().get(Calendar.YEAR)
ext.name = 'XEBIALABS'
excludes(["**/*.min.js"])
}
53 changes: 53 additions & 0 deletions src/main/resources/stash/ContributionsTile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Copyright 2019 XEBIALABS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

from stash.Stash import StashClient
import datetime

def convertMillisEpoch(millis):
return datetime.datetime.fromtimestamp(float(millis)/1000).strftime('%Y-%m-%d %H:%M:%S %Z')

stash = StashClient.get_client(server, username, password)
method = "stash_querycommits"
call = getattr(stash, method)
response = call(locals())

commits = response["output"]

# Compile data for detail and summary views
authors = {}
committers = {}
people = []
for commit in commits:
if commit["author"]["name"] in authors.keys():
authors[commit["author"]["name"]] += 1
else:
authors[commit["author"]["name"]] = 1
if commit["author"]["name"] not in people:
people.append(commit["author"]["name"])

if commit["committer"]["name"] in committers.keys():
committers[commit["committer"]["name"]] += 1
else:
committers[commit["committer"]["name"]] = 1
if commit["committer"]["name"] not in people:
people.append(commit["committer"]["name"])

# Convert timestamps to a user-friendly format
for i in range(len(commits)):
commits[i]["authorTimestamp"] = convertMillisEpoch(commits[i]["authorTimestamp"])
commits[i]["committerTimestamp"] = convertMillisEpoch(commits[i]["committerTimestamp"])

data = {
"commits": commits,
"authors": [{"name":author,"value":authors[author]} for author in authors.keys()],
"committers": [{"name":committer,"value":committers[committer]} for committer in committers.keys()],
"people": people
}
23 changes: 23 additions & 0 deletions src/main/resources/stash/Stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,26 @@ def stash_approvepullrequest(self, variables):
data = json.loads(response.getResponse())
print "Pull Request %s approved sucessfully with STATE : %s" % (str(variables['prid']), data['status'])
return {'output': data}

def stash_querycommits(self, variables):
# Calculate page sizes using max 100 results per page and the user-specified results_limit
result_set_sizes = [min(variables['results_limit'] - i, 100) for i in range(0, variables['results_limit'], 100)]
endpoint = "/rest/api/1.0/projects/%s/repos/%s/commits?" % (variables['project'], variables['repository'])
if variables["branch"] is not None:
endpoint += "until=%s" % variables["branch"]
commits = []
nextPageStart = 0
# Calculate page sizes using max 100 results per page (GitLab limit) and the user-specified results_limit
result_set_sizes = [min(variables['results_limit'] - i, 100) for i in range(0, variables['results_limit'], 100)]
for page_num, result_set_size in enumerate(result_set_sizes, 1):
endpoint_page = "%s&limit=100&start=%s" % (endpoint, nextPageStart)
response = self.api_call('GET', endpoint_page, body='{}', contentType="application/json")
data = json.loads(response.getResponse())
if data["values"] == []: # no more commits to pull
break
else: # pull commits based on expected results_limit count for that page
commits += data["values"][0:result_set_size]
nextPageStart = data["nextPageStart"]
if nextPageStart is None: # no more commits to pull
break
return {'output': commits}
63 changes: 63 additions & 0 deletions src/main/resources/stash/TimelineTile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Copyright 2019 XEBIALABS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

from stash.Stash import StashClient
import datetime
from java.time import LocalDate

def convertMillisEpochDateComponents(millis):
isodate = datetime.datetime.fromtimestamp(float(millis)/1000).strftime('%Y-%m-%d').split('-')
isodate = [int(dateComponent) for dateComponent in isodate]
return LocalDate.of(isodate[0], isodate[1], isodate[2])

def convertMillisEpoch(millis):
return datetime.datetime.fromtimestamp(float(millis)/1000).strftime('%Y-%m-%d %H:%M:%S %Z')

stash = StashClient.get_client(server, username, password)
method = "stash_querycommits"
call = getattr(stash, method)
response = call(locals())

commits = response["output"]

# Compile data for summary view
commitsByDay = {}
for commit in commits:
commitDate = convertMillisEpochDateComponents(commit["committerTimestamp"])
if commitDate in commitsByDay.keys():
commitsByDay[commitDate] += 1
else:
commitsByDay[commitDate] = 1

dates = [date for date in commitsByDay.keys()]
dates.sort()
startDate = dates[0]
endDate = dates[-1]
days = []
commitsEachDay = []
daysWithCommits = [dayCommits.toString() for dayCommits in commitsByDay.keys()]
while startDate.isBefore(endDate.plusDays(1)):
days.append(startDate.toString())
if startDate.toString() in daysWithCommits:
commitsEachDay.append(commitsByDay[startDate])
else:
commitsEachDay.append(0)
startDate = startDate.plusDays(1)

# Convert timestamps to a user-friendly format for the detail view
for i in range(len(commits)):
commits[i]["authorTimestamp"] = convertMillisEpoch(commits[i]["authorTimestamp"])
commits[i]["committerTimestamp"] = convertMillisEpoch(commits[i]["committerTimestamp"])

data = {
"dates": days,
"commitsEachDay": commitsEachDay,
"commits": commits
}
42 changes: 42 additions & 0 deletions src/main/resources/synthetic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,46 @@
<type type="stash.ApprovePullRequest" extends="stash.Task">
<property name="prid" category="input" description="Pull Request Id" label="Pull Request Id"/>
</type>
<type type="stash.QueryCommits" extends="stash.Task" virtual="true">
<property name="branch" category="input" required="false" label="Branch Name" description="If not provided, the default branch will be used"/>
<property name="results_limit" category="input" kind="integer" required="true" label="Results Limit" default="100" description="Upper limit on the number of pull requests to return from the query."/>
</type>
<!-- Tile Configuration -->
<type type="stash.ContributionsTile" label="Stash Contributions Tile" extends="xlrelease.Tile" description="Display authors and committers for the latest commits">
<property default="release,folder,global" hidden="true" name="supportedScopes" kind="list_of_string"/>
<property name="uri" hidden="true" default="stash/ContributionsTile/stash-contributions-tile-summary-view.html"/>
<property name="detailsUri" hidden="true" default="stash/ContributionsTile/stash-contributions-tile-details-view.html" />
<property name="width" kind="integer" default="2"/>
<property name="height" kind="integer" default="2"/>
<property name="title" description="Tile title." default="Bitbucket Contributions Summary"/>
<property name="server" category="input" label="Stash Authentication" referenced-type="stash.Server" kind="ci"
required="true" description="Stash Authentication."/>
<property name="username" category="input" default="" required="false"
description="Optional username to override global server configuration"/>
<property name="password" category="input" default="" required="false" password="true"
description="Optional password to override global server configuration"/>
<property name="project" category="input" description="Project key" label="Project Key"/>
<property name="repository" category="input" description="Repository Name" label="Repository Name"/>
<property name="branch" category="input" required="false" label="Branch Name" description="If not provided, the master branch will be used"/>
<property name="results_limit" category="input" kind="integer" required="true" label="Results Limit" default="100" description="Upper limit on the number of pull requests to return from the query."/>
</type>
<!-- Tile Configuration -->
<type type="stash.TimelineTile" label="Stash Timeline Tile" extends="xlrelease.Tile" description="Display a timeline of commits">
<property default="release,folder,global" hidden="true" name="supportedScopes" kind="list_of_string"/>
<property name="uri" hidden="true" default="stash/TimelineTile/stash-timeline-tile-summary-view.html"/>
<property name="detailsUri" hidden="true" default="stash/TimelineTile/stash-timeline-tile-details-view.html" />
<property name="width" kind="integer" default="2"/>
<property name="height" kind="integer" default="2"/>
<property name="title" description="Tile title." default="Bitbucket Commits Timeline"/>
<property name="server" category="input" label="Stash Authentication" referenced-type="stash.Server" kind="ci"
required="true" description="Stash Authentication."/>
<property name="username" category="input" default="" required="false"
description="Optional username to override global server configuration"/>
<property name="password" category="input" default="" required="false" password="true"
description="Optional password to override global server configuration"/>
<property name="project" category="input" description="Project key" label="Project Key"/>
<property name="repository" category="input" description="Repository Name" label="Repository Name"/>
<property name="branch" category="input" required="false" label="Branch Name" description="If not provided, the master branch will be used"/>
<property name="results_limit" category="input" kind="integer" required="true" label="Results Limit" default="100" description="Upper limit on the number of pull requests to return from the query."/>
</type>
</synthetic>
22 changes: 22 additions & 0 deletions src/main/resources/web/stash/ContributionsTile/echarts.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!--
Copyright 2019 XEBIALABS
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!DOCTYPE html>
<html>
<head>
<!-- Bootstrap CSS dependency -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
</head>
<script>
window.addEventListener("xlrelease.load", function () {
window.xlrelease.queryTileData(function (response) {
var commits = response.data.data.commits;
commits.forEach(function (commit) {
if(commit.message.length > 64) {
var message = commit.message.substring(0, 61).concat('...');
} else {
var message = commit.message;
}
$("#commits").append(
'<tr>' +
'<td>' + commit.displayId + '</td>' +
'<td>' + commit.authorTimestamp + '</td>' +
'<td>' + commit.author.name +
' (<a href="mailto:' + commit.author.emailAddress + '">' + commit.author.emailAddress + '</a>)</td>' +
'<td>' + commit.committerTimestamp + '</td>' +
'<td>' + commit.committer.name +
' (<a href="mailto:' + commit.committer.emailAddress + '">' + commit.committer.emailAddress + '</a>)</td>' +
'<td>' + message + '</td>' +
'</tr>'
);
})
});
});
</script>
<body>
<table class="table table-rounded table-striped">
<thead>
<tr>
<th>Commit ID</th>
<th>Authored Date</th>
<th>Author</th>
<th>Committed Date</th>
<th>Committer</th>
<th>Message</th>
</tr>
</thead>
<tbody id="commits">
</tbody>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!--
Copyright 2019 XEBIALABS
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!DOCTYPE html>
<html>
<head>
<script src="echarts.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
</head>
<script>
window.addEventListener("xlrelease.load", function () {
window.xlrelease.queryTileData(function (response) {
var authors = response.data.data.authors;
var committers = response.data.data.committers;
var people = response.data.data.people;
var dom = document.getElementById("main");
var myChart = echarts.init(dom);
var app = {};
option = null;
app.title = 'Authors and Committers';
option = {
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} Commit(s) ({d}%)"
},
legend: {
orient: 'vertical',
type: 'scroll',
x: 'left',
data: people
},
series: [
{
name:'Authors',
type:'pie',
selectedMode: 'single',
radius: [0, '45%'],
label: {
normal: {
show: false
}
},
data: authors
},
{
name:'Committers',
type:'pie',
radius: ['60%', '82.5%'],
label: {
normal: {
show: false
}
},
data: committers
}
]
};;
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
});
});
</script>
<body>
<div id="main" style="width:100%;height:calc(100vh - 16px);"></div>
</body>
</html>
Loading

0 comments on commit c3c4db2

Please sign in to comment.