Skip to content

Commit e278f20

Browse files
author
Hans Kristian Flaatten
committed
Load incidents log directly from GitHub Issues
1 parent c47096f commit e278f20

2 files changed

Lines changed: 65 additions & 28 deletions

File tree

assets/js/script.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,66 @@ $(document).ready(function() {
3838

3939
$here.append('<li>' + name + ' <span class="status ' + clas + '">' + text + '</span></li>') });
4040
};
41+
42+
$.getJSON('https://api.github.com/repos/Turistforeningen/status/issues?state=all').done(message);
43+
44+
var $incidents = $('#incidents');
45+
46+
function message(issues) {
47+
issues.forEach(function(issue) {
48+
var status_text = {
49+
operational: 'løst',
50+
investigating: 'undersøker',
51+
'major outage': 'driftsavbrudd',
52+
'degraded performance': 'degradert ytelse',
53+
};
54+
55+
var status = issue.labels.reduce(function(status, label) {
56+
if (/^status:/.test(label.name)) {
57+
return label.name.replace('status:', '');
58+
} else {
59+
return status;
60+
}
61+
}, 'operational');
62+
63+
var systems = issue.labels.filter(function(label) {
64+
return /^system:/.test(label.name);
65+
}).map(function(label) {
66+
return label.name.replace('system:', '')
67+
});
68+
69+
console.log(status);
70+
console.log(systems);
71+
72+
var html = '<div class="incident">\n';
73+
html += '<span class="date">' + issue.created_at + '</span>\n';
74+
75+
// status
76+
if (issue.state == 'closed') {
77+
html += '<span class="label operational float-right">løst</span>';
78+
} else {
79+
html += '<span class="label ' + status + ' float-right">';
80+
html += status_text[status];
81+
html += '</span>\n';
82+
}
83+
84+
// systems
85+
for (var i = 0; i < systems.length; i++) {
86+
html += '<span class="label system float-right">' + systems[i] + '</span>';
87+
}
88+
89+
html += '<hr>\n';
90+
html += '<span class="title">' + issue.title + '</span>\n';
91+
html += '<p>' + issue.body + '</p>\n';
92+
93+
if (issue.state == 'closed') {
94+
html += '<p><em>Oppdatert ' + issue.closed_at + '<br/>';
95+
html += 'Systemet er tilbake i normal drift.</p>';
96+
}
97+
98+
html += '</div>';
99+
100+
$incidents.append(html);
101+
});
102+
};
41103
});

index.html

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,10 @@ <h4>Tjenester</h4>
2828
<ul id="services" class="systems"></ul>
2929

3030
<h4>Hendelser</h4>
31-
<em>Ingen hendelser de siste dagene.</em>
3231

33-
<!--{% if incidents %}
34-
{% for incident in incidents %}
35-
<div class="incident">
36-
<span class="date">{{ incident.created }}</span>
37-
38-
{% if incident.closed %}
39-
<span class="label operational float-right">resolved</span>
40-
{% else %}
41-
<span class="label {{ incident.severity }} float-right">{{ incident.severity }}</span>
42-
{% endif %}
43-
{% for system in incident.systems %}
44-
<span class="label system float-right">{{ system }}</span>
45-
{% endfor %}
46-
<hr/>
47-
48-
<span class="title">{{ incident.title }}</span>
49-
<p>{{ incident.body }}</p>
50-
{% for update in incident.updates %}
51-
<p><em>Update {{ update.created }}</em><br/>
52-
{{ update.body }}
53-
</p>
54-
{% endfor %}
55-
</div>
56-
{% endfor %}
57-
{% else %}
58-
{% endif %}-->
59-
</section>
32+
<div id="incidents">
33+
<div class="incident"></div>
34+
</div>
6035

6136
<footer class="footer">
6237
<section class="container">

0 commit comments

Comments
 (0)