Skip to content

Commit 5ad5d7e

Browse files
iradulknownasilya
authored andcommitted
Make status descriptions and status context configurable (#11)
* Make status descriptions and status context configurable This commit adds configuration page for the plugin where user can configure: * context of a status message * description of each status message * Use [ci/strider] as a default context * Improve config page HTML
1 parent 7736a40 commit 5ad5d7e

File tree

7 files changed

+114
-20
lines changed

7 files changed

+114
-20
lines changed

config/config.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<h2>
2+
Github Status
3+
<button ng-click="save()" class="btn btn-primary pull-right">Save</button>
4+
</h2>
5+
6+
<div class="form-group">
7+
<h4>Context for status message</h4>
8+
9+
<input id="github-status-context" type="text" ng-model="config.context">
10+
<p class="help-text">
11+
Status message context. Default it "ci/strider".
12+
</p>
13+
</div>
14+
15+
<div class="form-group">
16+
<h4>Description of status</h4>
17+
18+
<label for="github-status-messages-pending" class="bold-label">Pending:</label>
19+
<input id="github-status-messages-pending" type="text" ng-model="config.messages.pending">
20+
<p class="help-text">
21+
Description for "pending" status. Default it "Strider test in progress".
22+
</p>
23+
24+
<label for="github-status-messages-success" class="bold-label">Success:</label>
25+
<input id="github-status-messages-success" type="text" ng-model="config.messages.success">
26+
<p class="help-text">
27+
Description for "success" status. Default it "Strider tests succeeded".
28+
</p>
29+
30+
<label for="github-status-messages-failure" class="bold-label">Failure:</label>
31+
<input id="github-status-messages-failure" type="text" ng-model="config.messages.failure">
32+
<p class="help-text">
33+
Description for "failure" status. Default it "Strider tests failed".
34+
</p>
35+
36+
<label for="github-status-messages-error" class="bold-label">Error:</label>
37+
<input id="github-status-messages-error" type="text" ng-model="config.messages.error">
38+
<p class="help-text">
39+
Description for "error" status. Default it "Strider tests errored".
40+
</p>
41+
</div>
42+
<button ng-click="save()" class="btn btn-primary pull-right">Save</button>

config/config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var app = window.app;
2+
3+
app.controller('GithubStatusCtrl', ['$scope', function ($scope) {
4+
$scope.config = {
5+
messages: {
6+
pending: 'Strider test in progress',
7+
success: 'Strider tests succeeded',
8+
failure: 'Strider tests failed',
9+
error: 'Strider tests errored',
10+
},
11+
context: 'ci/strider',
12+
};
13+
$scope.saving = false;
14+
15+
$scope.$watch('configs[branch.name]["github-status"].config', function (value) {
16+
for (var p in value) {
17+
if (value.hasOwnProperty(p)) {
18+
$scope.config = value;
19+
break;
20+
}
21+
}
22+
});
23+
24+
$scope.save = function () {
25+
$scope.saving = true;
26+
$scope.pluginConfig('github-status', $scope.config, function () {
27+
$scope.saving = false;
28+
});
29+
};
30+
31+
}]);

config/config.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#plugin-github-status .bold-label {
2+
font-weight: bold;
3+
}
4+
#plugin-github-status .form-group {
5+
margin-bottom: 20px;
6+
}

lib/handler.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (GITHUB_API_ENDPOINT) {
1717
config.pathPrefix = url.parse(GITHUB_API_ENDPOINT).path;
1818
}
1919

20-
module.exports = function (token, url, data, status, description) {
20+
module.exports = function (token, url, data, status, description, context) {
2121
debug('Setting status', token, url, data, status, description);
2222
var github = new GithubApi(config);
2323
github.authenticate({
@@ -30,7 +30,8 @@ module.exports = function (token, url, data, status, description) {
3030
repo: data.repo,
3131
state: status,
3232
sha: data.sha,
33-
description: description
33+
description: description,
34+
context: context
3435
}, function (err) {
3536
if (err) console.error('failed to set github status', url, data, err.message);
3637
});

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"homepage": "https://github.com/Strider-CD/strider-github-status",
2626
"dependencies": {
27-
"github": "~0.1.12",
27+
"github": "~0.2.4",
2828
"debug": "~0.7.4"
2929
},
3030
"publishConfig": {
@@ -44,7 +44,10 @@
4444
"title": "Github Status",
4545
"webapp": "webapp.js",
4646
"worker": "worker.js",
47-
"icon": "icon.png"
47+
"icon": "icon.png",
48+
"config": {
49+
"controller": "GithubStatusCtrl"
50+
}
4851
},
4952
"devDependencies": {
5053
"eslint": "^3.1.1",

webapp.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,47 @@
11
var debug = require('debug')('strider-github-status');
22
var setStatus = require('./lib/handler');
33

4-
function jobStatus(job) {
5-
if (job.errored) return 'error';
6-
return job.test_exitcode === 0 ? 'success' : 'failure';
7-
}
8-
94
// TODO: give information here as to why it errored/failed?
10-
function jobDescription(job) {
11-
if (job.errored) return 'Strider tests errored';
12-
return 'Strider tests ' + (job.test_exitcode === 0 ? 'succeeded' : 'failed');
5+
function jobInfo(job, config) {
6+
var info = {};
7+
8+
if (job.errored) info.status = 'error';
9+
else if (job.test_exitcode === 0) info.status = 'success';
10+
else info.status = 'failure';
11+
12+
info.description = config.messages[info.status];
13+
info.context = config.context;
14+
15+
return info;
1316
}
1417

1518
module.exports = {
19+
config: {
20+
messages: {
21+
pending: {type: String, default: 'Strider test in progress'},
22+
success: {type: String, default: 'Strider tests succeeded'},
23+
failure: {type: String, default: 'Strider tests failed'},
24+
error: {type: String, default: 'Strider tests errored'},
25+
},
26+
context: {type: String, default: 'ci/strider'},
27+
},
1628
// global events
1729
listen: function (io, context) {
18-
io.on('plugin.github-status.started', function (jobId, projectName, token, data) {
30+
io.on('plugin.github-status.started', function (jobId, projectName, token, data, config) {
1931
debug('got', jobId, projectName, token, data);
2032
var url = context.config.server_name + '/' + projectName + '/job/' + jobId;
21-
setStatus(token, url, data, 'pending', 'Strider test in progress');
33+
setStatus(token, url, data, 'pending', config.messages.pending, config.context);
2234
});
2335

24-
io.on('plugin.github-status.done', function (jobId, projectName, token, data) {
36+
io.on('plugin.github-status.done', function (jobId, projectName, token, data, config) {
2537
function onDoneAndSaved(job) {
2638
if (job._id.toString() !== jobId.toString()) return;
2739
debug('plugin done', jobId, projectName, token, data);
2840

2941
io.removeListener('job.doneAndSaved', onDoneAndSaved);
3042
var url = context.config.server_name + '/' + projectName + '/job/' + jobId
31-
, status = jobStatus(job)
32-
, description = jobDescription(job);
33-
setStatus(token, url, data, status, description);
43+
, info = jobInfo(job, config);
44+
setStatus(token, url, data, info.status, info.description, info.context);
3445
}
3546
io.on('job.doneAndSaved', onDoneAndSaved);
3647
});

worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ module.exports = {
3030
repo: job.project.provider.config.repo,
3131
sha: job.plugin_data.github.pull_request.sha
3232
};
33-
emitter.emit('plugin.github-status.started', job._id, projectName, token, github_repo_data);
33+
emitter.emit('plugin.github-status.started', job._id, projectName, token, github_repo_data, config);
3434
emitter.once('job.status.tested', function (jobId) {
3535
debug('job was tested', jobId);
36-
emitter.emit('plugin.github-status.done', jobId, projectName, token, github_repo_data);
36+
emitter.emit('plugin.github-status.done', jobId, projectName, token, github_repo_data, config);
3737
});
3838
}
3939
});

0 commit comments

Comments
 (0)