Skip to content

Commit 2268f51

Browse files
committed
Add webhook index describing its configuration
1 parent 17b20ca commit 2268f51

4 files changed

Lines changed: 147 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Github Labelbot
22
Configurable Github bot used for automatic issues labeling
33

4+
Sample webhook is running at https://labelbot-api.herokuapp.com/
5+
46
## Configuration
57
TBA
68

labelbot/templates/custom.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Space out content a bit */
2+
body {
3+
padding-top: 1.5rem;
4+
padding-bottom: 1.5rem;
5+
}
6+
7+
/* Everything but the jumbotron gets side spacing for mobile first views */
8+
.header,
9+
.marketing,
10+
.footer {
11+
padding-right: 1rem;
12+
padding-left: 1rem;
13+
}
14+
15+
/* Custom page header */
16+
.header {
17+
padding-bottom: 1rem;
18+
border-bottom: .05rem solid #e5e5e5;
19+
}
20+
/* Make the masthead heading the same height as the navigation */
21+
.header h3 {
22+
margin-top: 0;
23+
margin-bottom: 0;
24+
line-height: 3rem;
25+
}
26+
27+
/* Custom page footer */
28+
.footer {
29+
padding-top: 1.5rem;
30+
color: #777;
31+
border-top: .05rem solid #e5e5e5;
32+
}
33+
34+
/* Customize container */
35+
@media (min-width: 48em) {
36+
.container {
37+
max-width: 46rem;
38+
}
39+
}
40+
.container-narrow > hr {
41+
margin: 2rem 0;
42+
}
43+
44+
45+
/* Supporting marketing content */
46+
.marketing {
47+
margin: 3rem 0;
48+
}
49+
.marketing p + h4 {
50+
margin-top: 1.5rem;
51+
}
52+
53+
/* Responsive: Portrait tablets and up */
54+
@media screen and (min-width: 48em) {
55+
/* Remove the padding we set earlier */
56+
.header,
57+
.marketing,
58+
.footer {
59+
padding-right: 0;
60+
padding-left: 0;
61+
}
62+
/* Space out the masthead */
63+
.header {
64+
margin-bottom: 2rem;
65+
}
66+
}

labelbot/templates/index.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
8+
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
9+
<meta name="description" content="">
10+
<meta name="author" content="">
11+
<link rel="icon" href="../../favicon.ico">
12+
13+
<title>GitHub Labelbot webhook page</title>
14+
15+
<!-- Bootstrap core CSS -->
16+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" integrity="sha384-2hfp1SzUoho7/TsGGGDaFdsuuDL0LX2hnUp6VkX3CUQ2K4K+xjboZdsXyp4oUHZj" crossorigin="anonymous">
17+
18+
<!-- Custom styles for this template -->
19+
<link href="custom.css" rel="stylesheet">
20+
</head>
21+
22+
<body>
23+
24+
<div class="container">
25+
<div class="header clearfix">
26+
<nav>
27+
<ul class="nav nav-pills pull-xs-right">
28+
</ul>
29+
</nav>
30+
<h3 class="text-muted">GitHub Labelbot sample webhook</h3>
31+
</div>
32+
33+
<div class="row marketing">
34+
<div class="col-lg-12">
35+
<p>This is a GitHub webhook page serving as a sample for GitHub LabelBot project. It allows GitHub to notify LabelBot about new issues or issue comments in real time. The Bot then scans the issues and assigns new labels if necessary according to configured rules. </p>
36+
37+
<h4>Configuration</h4>
38+
<p>To allow LabelBot to label issues in your repository, additional steps are required:</p>
39+
<ul>
40+
<li>Add your GitHub bot user as an collaborator to the project you want to label. </li>
41+
<li>Create a new webhook in your repo with e.g. <strong>https://labelbot-api.herokuapp.com/hook</strong> Payload URL and <strong>issues</strong> and <strong>issue comment</strong> events allowed. </li>
42+
<li>Set WEBHOOK_TOKEN environment variable corresponding to the secret token you used during token_creation. </li>
43+
</ul>
44+
45+
<h4>Configured labeling rules</h4>
46+
<table class="table">
47+
<thead class="thead-default">
48+
<tr>
49+
<th>Regex</th>
50+
<th>Tag</th>
51+
</tr>
52+
</thead>
53+
<tbody>
54+
{% for rule in rules %}
55+
<tr>
56+
<td>{{ rule.pattern }}</td>
57+
<td>{{ rule.label }}</td>
58+
</tr>
59+
{% endfor %}
60+
</tbody>
61+
</table>
62+
63+
</div>
64+
</div>
65+
66+
<footer class="footer">
67+
<p>&copy; David Viktora, 2016</p>
68+
</footer>
69+
70+
</div> <!-- /container -->
71+
</body>
72+
</html>

labelbot/web.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask import abort
22
from flask import Flask
3+
from flask import render_template
34
from flask import request
45
from hashlib import sha1
56
from labelbot import LabelBot
@@ -11,8 +12,9 @@
1112

1213

1314
@app.route('/')
14-
def hello():
15-
return 'MI-PYT je nejlepší předmět na FITu!'
15+
def index():
16+
labelbot = app.config['labelbot']
17+
return render_template('index.html', rules=labelbot.rules)
1618

1719

1820
@app.route('/hook', methods=['POST'])
@@ -28,10 +30,11 @@ def hook():
2830
except:
2931
abort(400)
3032

31-
if not app.config['labelbot'].check_repo_accessible(repo_name):
33+
labelbot = app.config['labelbot']
34+
if not labelbot.check_repo_accessible(repo_name):
3235
abort(401)
3336

34-
app.config['labelbot'].label_issue(repo_name, issue_json)
37+
labelbot.label_issue(repo_name, issue_json)
3538

3639
return ''
3740

0 commit comments

Comments
 (0)