Skip to content

Commit fd1c0c5

Browse files
author
Ilya Radchenko
committed
Update passport-github
1 parent f0ac2d5 commit fd1c0c5

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

config/config.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ <h4>Caching</h4>
66
<input ng-model="config.cache" type="checkbox" ng-change="save()"> Cache the project data between runs
77
</label>
88
</div>
9+
10+
<div>
11+
<h4>Test On Releases</h4>
12+
<label class="checkbox">
13+
<input ng-model="config.release" type="checkbox" ng-change="save()"> Create a job when a release is created on Github
14+
</label>
15+
</div>
16+
917
<h4>Pull Requests</h4>
1018
<p>If you have the service hooks installed, you can also choose to test pull requests.</p>
1119
<div class="btn-group">

lib/webapp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = {
4343
owner: String,
4444
repo: String,
4545
cache: Boolean,
46+
release: Boolean,
4647
pull_requests: {type: String, enum: ['all', 'none', 'whitelist']},
4748
whitelist: [{
4849
name: String,

lib/webhooks.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ function startFromPullRequest(account, config, project, payload, send) {
9898
return user.name === payload.pull_request.user.login;
9999
});
100100
if (!user) {
101-
if (payload.action !== 'opened') return;
102101
if (config.askToPR) askToTestPr(account, payload.pull_request);
103102
return;
104103
}
@@ -108,6 +107,13 @@ function startFromPullRequest(account, config, project, payload, send) {
108107
send(job);
109108
}
110109

110+
function startFromRelease(account, config, project, payload, send) {
111+
if (payload.action !== 'published' || payload.release.draft) return;
112+
var job = makeJob(project, releaseJob(payload.release));
113+
if (!job) return false;
114+
send(job);
115+
}
116+
111117
function pullRequestJob(pr) {
112118
var trigger = {
113119
type: 'pull-request',
@@ -145,6 +151,42 @@ function pullRequestJob(pr) {
145151
};
146152
}
147153

154+
function releaseJob(release) {
155+
var trigger = {
156+
type: 'release',
157+
author: {
158+
username: release.author.login,
159+
image: release.author.avatar_url
160+
},
161+
url: release.html_url,
162+
message: release.name,
163+
timestamp: release.published_at,
164+
source: {
165+
type: 'plugin',
166+
plugin: 'github'
167+
}
168+
};
169+
var branch = release.target_commitish;
170+
return {
171+
branch: branch,
172+
trigger: trigger,
173+
deploy: false,
174+
ref: {
175+
fetch: `refs/tags/${release.tag_name}`,
176+
branch: branch
177+
},
178+
plugin_data: {
179+
github: {
180+
release: {
181+
user: trigger.author.username,
182+
tag: release.tag_name,
183+
body: release.body
184+
}
185+
}
186+
}
187+
};
188+
}
189+
148190
/**
149191
*
150192
* @param payload
@@ -253,8 +295,16 @@ function receiveWebhook(emitter, req, res) {
253295
if (payload.zen) return res.sendStatus(200);
254296

255297
res.sendStatus(204);
256-
// a new pull request was created
257298

299+
// a release was published
300+
if (payload.release) {
301+
if (!config.release) {
302+
return debug('Got a release, but testing releases is disabled');
303+
}
304+
return startFromRelease(account, config, req.project, payload, sendJob);
305+
}
306+
307+
// a new pull request was created
258308
if (payload.pull_request) {
259309
if (config.pull_requests === 'none') {
260310
return debug('Got pull request, but testing pull requests is disabled');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"debug": "~2.2.0",
4949
"gravatar": "~1.0.6",
5050
"lodash": "^2.2.1",
51-
"passport-github": "^1.0.0",
51+
"passport-github": "^1.1.0",
5252
"scmp": "0.0.2",
5353
"ssh-keypair": "~1.0.0",
5454
"step": "0.0.5",

0 commit comments

Comments
 (0)