Skip to content

Commit

Permalink
ci_build/: Re-design build-logs webpage
Browse files Browse the repository at this point in the history
The newly created webpage combines the previous
two webpages- info.txt and log/index.html. This
web-page combines the results of both the pages
and shows them in a better UI/UX with additional
features of filtering and searching within the
existing logs. The logs are fetched from a JSON
file which is created from the logs stored in
the log file _site/community.log
  • Loading branch information
KVGarg committed Jun 10, 2019
1 parent c2da5d6 commit 8440f54
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .moban.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages:
- gci
- gsoc
- gamification
- log
- ci_build
- meta_review
- model
- twitter
Expand Down
2 changes: 1 addition & 1 deletion .nocover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nocover_file_globs:
- community/git.py
- gci/*.py
- gsoc/*.py
- log/*.py
- ci_build/*.py
- meta_review/handler.py
- model/*.py
- openhub/*.py
Expand Down
69 changes: 69 additions & 0 deletions ci_build/view_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import re
import json
import os
from django.views.generic import TemplateView

from community.views import get_header_and_footer
from community.git import (get_org_name,
get_owner,
get_deploy_url,
get_upstream_deploy_url)


class BuildLogsView(TemplateView):
template_name = 'build_logs.html'

def get_build_info(self):
data = {
'Org name': get_org_name(),
'Owner': get_owner(),
'Deploy URL': get_deploy_url(),
}
try:
upstream_deploy_url = get_upstream_deploy_url()
data['Upstream deploy URL'] = upstream_deploy_url
except RuntimeError:
data['Upstream deploy URL'] = 'Not found'
return dict(data)

def get_build_logs(self):
log_lines = []
log_level_specific_lines = {
'INFO': [],
'DEBUG': [],
'WARNING': [],
'ERROR': [],
'CRITICAL': []
}
log_file_path = './_site/community.log'
log_file_exists = os.path.isfile(log_file_path)
if log_file_exists:
with open(log_file_path) as log_file:
previous_found_level = None
for line in log_file:
log_lines.append(line)
levels = re.findall(r'\[[A-Z]+]', line)
if levels:
level = levels[0]
level = previous_found_level = level[1:-1]
log_level_specific_lines[level].append(line)
elif previous_found_level:
log_level_specific_lines[previous_found_level].append(
line)
with open('./_site/ci-build-detailed-logs.json',
'w+') as build_logs_file:
data = {
'logs': log_lines,
'logs_level_Specific': log_level_specific_lines
}
json.dump(data, build_logs_file, indent=4)
return True
else:
return False

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
context['build_info'] = self.get_build_info()
context['build_logs_stored'] = self.get_build_logs()
return context
16 changes: 5 additions & 11 deletions community/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from django.conf.urls.static import static
from django.conf import settings

from community.views import HomePageView, info
from community.views import HomePageView
from gci.views import index as gci_index
from gci.feeds import LatestTasksFeed as gci_tasks_rss
from twitter.view_twitter import index as twitter_index
from log.view_log import index as log_index
from ci_build.view_log import BuildLogsView
from data.views import index as contributors_index
from gamification.views import index as gamification_index
from meta_review.views import index as meta_review_index
Expand Down Expand Up @@ -79,12 +79,6 @@ def get_organization():
distill_func=get_index,
distill_file='index.html',
),
distill_url(
'info.txt', info,
name='index',
distill_func=get_index,
distill_file='info.txt',
),
distill_url(
r'gci/tasks/rss.xml', gci_tasks_rss(),
name='gci-tasks-rss',
Expand All @@ -104,10 +98,10 @@ def get_organization():
distill_file='twitter/index.html',
),
distill_url(
r'log/', log_index,
name='log',
r'CI/Build/', BuildLogsView.as_view(),
name='ci_build',
distill_func=get_index,
distill_file='log/index.html',
distill_file='CI/Build/index.html',
),
distill_url(
r'contributors/$', contributors_index,
Expand Down
21 changes: 0 additions & 21 deletions community/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from django.http import HttpResponse
from django.views.generic.base import TemplateView

from trav import Travis

from .git import (
get_deploy_url,
get_org_name,
get_owner,
get_upstream_deploy_url,
get_remote_url
)
from data.models import Team, Contributor
Expand Down Expand Up @@ -110,20 +106,3 @@ def get_context_data(self, **kwargs):
context['top_gamification_users'] = self.get_top_gamification_users(
count=5)
return context


def info(request):
data = {
'Org name': get_org_name(),
'Owner': get_owner(),
'Deploy URL': get_deploy_url(),
}
try:
upstream_deploy_url = get_upstream_deploy_url()
data['Upstream deploy URL'] = upstream_deploy_url
except RuntimeError:
data['Upstream deploy URL'] = 'Not found'

s = '\n'.join(name + ': ' + value
for name, value in data.items())
return HttpResponse(s)
12 changes: 0 additions & 12 deletions log/view_log.py

This file was deleted.

6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ testpaths =
gci
gsoc
gamification
log
ci_build
meta_review
model
twitter
Expand Down Expand Up @@ -70,7 +70,7 @@ source =
gci
gsoc
gamification
log
ci_build
meta_review
model
twitter
Expand All @@ -82,7 +82,7 @@ omit =
community/git.py
gci/*.py
gsoc/*.py
log/*.py
ci_build/*.py
meta_review/handler.py
model/*.py
openhub/*.py
Expand Down
81 changes: 81 additions & 0 deletions static/css/build_logs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
.build-info-section section,
.build-logs-section section {
min-width: 300px;
width: 80%;
}

.build-information,
.build-logs {
background-color: black;
padding-left: 10px;
font-weight: bold;
color: white;
}

.build-information p {
font-size: 1.5em;
margin: 0;
}

.build-logs {
max-height: 900px;
overflow: scroll;
overflow-x: hidden;
}

.build-logs p {
margin: 0;
}

.build-logs-section .log-chooser {
max-width: 200px;
min-width: 150px;
border-radius: 100px;
box-shadow: 0px 0px 25px 2px black;
color: #454343;
background-color: #c7da99;
padding-left: 10px;
}

.build-logs-section .search-field {
max-width: 500px;
min-width: 300px;
border-radius: 100px;
box-shadow: 0px 0px 25px 2px black;
color: #454343;
background-color: #edf5af;
padding: 0px 20px;
flex-flow: row;
}

.build-logs-section input[type='search']:focus:not(.browser-default) {
background-color: #edf5af;
border-radius: 100px;
font-size: medium;
}

.main-content h3 {
color: #37474f;
}

.section-header {
display: flex;
align-items: center;
}

.section-header form {
display: flex;
justify-content: space-around;
flex-direction: row;
flex-grow: 3;
}

@media only screen and (max-width: 768px) {
.build-logs-section .search-field {
display: none;
}
}

.webpage-name {
width: 100%;
}
7 changes: 0 additions & 7 deletions static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@
background-color: #ee8940;
}

.apply-flex-center {
display: flex;
justify-content: center;
flex-flow: row wrap;
align-items: center;
}

.organization_map {
text-align: center;
padding: 2% 0%;
Expand Down
7 changes: 7 additions & 0 deletions static/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.apply-flex-center {
display: flex;
justify-content: center;
flex-flow: row wrap;
align-items: center;
}

body {
font-family: 'Ubuntu Mono', monospace;
background-color: #edf5af;
Expand Down
88 changes: 88 additions & 0 deletions static/js/build_logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
$(document).ready(function(){
$('select').formSelect();

var log_chooser_input = $('#log-chooser-input');
var search_input = $('#search');
var log_type = null;
var logs_data = null;
var searched_keyword = '';

function addLogsHTML(info){
var info_el = $('<p></p>').text(info);
$('.build-logs').append(info_el);
}

function updateBuildLogsHTML(){
$('.build-logs p').remove();
if (logs_data.length < 37){
$('.build-logs').css('overflow-y', 'hidden');
}
if(logs_data.length > 0) {
for(var entry in logs_data){
if(logs_data[entry]){
addLogsHTML(logs_data[entry]);
}
}
}
else {
var info = 'There are no log entries for tag ' + log_type + '.';
addLogsHTML(info);
}
}

function updateBuildLogs(type){
$.getJSON("/static/ci-build-detailed-logs.json", function(data) {
log_type = type;
if(log_type === 'logs') {
logs_data = data[log_type];
}
else {
logs_data = data.logs_level_Specific[log_type];
}
updateBuildLogsHTML();
})
.fail(function(data, textStatus, error) {
var err = "Request Failed: " + textStatus + ", " + error;
console.error( err);
});
}

function searchBuildLogs(){
var found = false;
var info = '';
for(var entry in logs_data){
if(logs_data[entry]){
info = logs_data[entry];
if(info.includes(searched_keyword)){
found = true;
addLogsHTML(info);
}
}
}
if(!found){
if(log_type === 'logs'){
info = searched_keyword + ' not found in logs!';
}
else {
info = searched_keyword + ' not found in ' + log_type +
' level logs!';
}
addLogsHTML(info);
}
}

updateBuildLogs('logs');

log_chooser_input.on('change', function(){
updateBuildLogs(log_chooser_input.val());
});

search_input.on('keypress', function(key){
if(key.which === 13){
searched_keyword = search_input.val();
$('.build-logs p').remove();
searchBuildLogs();
}
});

});
Loading

0 comments on commit 8440f54

Please sign in to comment.