Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b3f01c9
deployments api. start
podviaznikov Feb 26, 2015
931ce38
use user accessToken
podviaznikov Feb 26, 2015
548161f
start handling deployment event
podviaznikov Feb 26, 2015
0600efc
changing deployment status
podviaznikov Feb 26, 2015
7e6f02c
get rid of github-notifications
podviaznikov Feb 27, 2015
288f426
remove PR bot code
podviaznikov Feb 27, 2015
d1509ec
remove old code
podviaznikov Feb 27, 2015
a4c1f65
passing target url for the deployment status
podviaznikov Feb 27, 2015
fd5c6e7
trigger deployment for each box
podviaznikov Feb 27, 2015
e852769
fix syntax error
podviaznikov Feb 27, 2015
efcb921
reorganize code. minors
podviaznikov Feb 27, 2015
64da9a6
creating build statuses
podviaznikov Feb 27, 2015
f6f0f27
fix typos
podviaznikov Feb 27, 2015
cf05335
better testing for the statuses
podviaznikov Feb 27, 2015
01f7bf5
playing with text
prafulrana Feb 27, 2015
10e2656
remove old code
podviaznikov Feb 27, 2015
2ac8f3a
better messaging
podviaznikov Feb 27, 2015
4a1dadc
refactor redeploy code
podviaznikov Feb 28, 2015
a6b0a2a
pull statuses code into separate file
podviaznikov Feb 28, 2015
aa51a33
progress with refactoring
podviaznikov Feb 28, 2015
c69b0a9
add debug logs
podviaznikov Feb 28, 2015
1a8d793
remove global try/catch
podviaznikov Feb 28, 2015
29d30f1
use commit instead of branch
podviaznikov Feb 28, 2015
e736c84
disable statuses by default
podviaznikov Feb 28, 2015
a1bd492
code cleanups
podviaznikov Feb 28, 2015
e21336a
fix mw result call
podviaznikov Feb 28, 2015
81c6e15
trigger deploy
podviaznikov Feb 28, 2015
1d41c57
handle error cases
podviaznikov Mar 2, 2015
1e51bd7
remove old hooks handling
podviaznikov Mar 2, 2015
bf7982e
minors
podviaznikov Mar 2, 2015
9fbfcde
fix problem with owner fetch
podviaznikov Mar 3, 2015
37dbc12
change to pull_request: synchronize event
podviaznikov Mar 3, 2015
6f095e1
fix signatures
podviaznikov Mar 3, 2015
4dd9cb1
change status display conditions
podviaznikov Mar 3, 2015
950344a
add additional try catch for build
podviaznikov Mar 3, 2015
a8722ab
minors
podviaznikov Mar 3, 2015
d11f903
add additional try/catch
podviaznikov Mar 3, 2015
907e0cc
fix problem with parsing pr
podviaznikov Mar 4, 2015
4834739
use equalsKeypath mw validation
podviaznikov Mar 4, 2015
9503c76
skip check on status success for deployment
podviaznikov Mar 4, 2015
ccd5e20
update node-github version
podviaznikov Mar 4, 2015
73da95f
fix lint error
podviaznikov Mar 4, 2015
ed817ec
handle case when 2 servers for 1 PR
podviaznikov Mar 4, 2015
6dd329a
add bed and comments cleanup
podviaznikov Mar 4, 2015
b68deda
fix double callback problem in bdd
podviaznikov Mar 4, 2015
03605d8
apply feedback from bryan
podviaznikov Mar 4, 2015
28e21ad
update comment
podviaznikov Mar 4, 2015
6708b70
merge & updates
podviaznikov Mar 4, 2015
0bde653
fixes and cleanups
podviaznikov Mar 5, 2015
9fceb47
implement serverSelection status
podviaznikov Mar 5, 2015
e7b9056
improvements
podviaznikov Mar 5, 2015
fbff7db
fix lint erros & missing require
podviaznikov Mar 5, 2015
7815f4f
fix method params
podviaznikov Mar 5, 2015
b1c2509
encode branch & commit msg
podviaznikov Mar 5, 2015
f3ec9fa
remove obsolete envs
podviaznikov Mar 5, 2015
cdee3dc
update status messages
podviaznikov Mar 5, 2015
ea462ba
work on @bkendall feedback
podviaznikov Mar 5, 2015
6e9ec66
fix + additional test
podviaznikov Mar 5, 2015
9298286
add tests for server selection case
podviaznikov Mar 5, 2015
569a09f
rename method
podviaznikov Mar 5, 2015
3bdcbfb
handle open pr event
podviaznikov Mar 5, 2015
987d527
pass pr number to the server selection link
podviaznikov Mar 5, 2015
7b780b4
use repo short name
podviaznikov Mar 6, 2015
4645350
comment out test
podviaznikov Mar 6, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions configs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ HELLO_RUNNABLE_GITHUB_ID=10224339
SLACK_BOT_IMAGE="https://avatars0.githubusercontent.com/u/2335750?v=3&s=200"
SLACK_BOT_USERNAME="runnabot"
HIPCHAT_BOT_USERNAME="runnabot"
ENABLE_BUILDS_ON_GIT_PUSH=false
ENABLE_GITHUB_HOOKS=false
ENABLE_NOTIFICATIONS_ON_GIT_PUSH=false
ENABLE_NEW_BRANCH_BUILDS_ON_GIT_PUSH=false
ENABLE_GITHUB_PR_COMMENTS=false
ENABLE_GITHUB_PR_STATUSES=false
POLL_MONGO_TIMEOUT="30 minutes"
GITHUB_SCOPE="user:email,repo,repo_deployment,read:repo_hook"
GITHUB_SCOPE="user:email,repo,repo_deployment,read:repo_hook, repo:status"
GITHUB_HOOK_SECRET="3V3RYTHINGisAW3S0ME!"
DOCKER_IMAGE_BUILDER_CACHE="/git-cache"
MONITOR_INTERVAL="1 minute"
RUNNABOT_GITHUB_ACCESS_TOKEN="14ed935a9413a29dbb28774d0521a4fd958571c8"
RUNNABOT_GITHUB_USERNAME="runnabot"
MESSENGER_NAMESPACE="runnable:api:messenger:"
BODY_PARSER_SIZE_LIMIT="600kb"
GRAPH_DATABASE_TYPE="cayley"

GRAPH_DATABASE_TYPE="cayley"
4 changes: 1 addition & 3 deletions configs/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ ROUTE53_HOSTEDZONEID="Z3IHYG8VH3VMIJ"
DNS_IPADDRESS=205.251.195.203
CAYLEY="http://cayley.runnable.io"
DOCKER_IMAGE_BUILDER_CACHE="/git-cache"
ENABLE_BUILDS_ON_GIT_PUSH=true
USER_CONTENT_DOMAIN=true
ENABLE_NOTIFICATIONS_ON_GIT_PUSH=true
ENABLE_NEW_BRANCH_BUILDS_ON_GIT_PUSH=false
ENABLE_GITHUB_PR_COMMENTS=true
GITHUB_DEPLOY_KEYS_POOL_SIZE=100
HEAP_APP_ID=3017229846
DOCKER_IMAGE_BUILDER_LAYER_CACHE="/layer-cache"
Expand Down
50 changes: 50 additions & 0 deletions lib/models/apis/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,56 @@ Github.prototype.getPullRequestHeadCommit = function (shortRepo, number, cb) {
});
};


Github.prototype.createDeployment = function (shortRepo, query, cb) {
debug('createDeployment', formatArgs(arguments));
var split = shortRepo.split('/');
query.user = split[0];
query.repo = split[1];
this.deployments.create(query, function (err, deployment) {
if (err) {
err = (err.code === 404) ?
Boom.notFound('Cannot find repo or ref: ' + shortRepo, { err: err, report: false }) :
Boom.create(502, 'Failed to repo or ref ' + shortRepo, { err: err });
return cb(err);
}
cb(null, deployment);
});
};

Github.prototype.createDeploymentStatus = function (shortRepo, query, cb) {
debug('createDeploymentStatus', formatArgs(arguments));
var split = shortRepo.split('/');
query.user = split[0];
query.repo = split[1];
this.deployments.createStatus(query, function (err, deployment) {
if (err) {
err = (err.code === 404) ?
Boom.notFound('Cannot find repo, ref or deployment: ' + shortRepo,
{ err: err, report: false }) :
Boom.create(502, 'Failed to repo, ref or deployment ' + shortRepo, { err: err });
return cb(err);
}
cb(null, deployment);
});
};

Github.prototype.createBuildStatus = function (shortRepo, query, cb) {
debug('createBuildStatus', formatArgs(arguments));
var split = shortRepo.split('/');
query.user = split[0];
query.repo = split[1];
this.statuses.create(query, function (err, status) {
if (err) {
err = (err.code === 404) ?
Boom.notFound('Cannot find repo or sha: ' + shortRepo, { err: err, report: false }) :
Boom.create(502, 'Failed to repo or sha ' + shortRepo, { err: err });
return cb(err);
}
cb(null, status);
});
};

// Check if user is collaborator for the repo
Github.prototype.isCollaborator = function (shortRepo, username, cb) {
debug('isCollaborator', formatArgs(arguments));
Expand Down
145 changes: 145 additions & 0 deletions lib/models/apis/pullrequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
'use strict';
var Github = require('models/apis/github');
var debug = require('debug')('runnable-api:models:pullrequest');
var formatArgs = require('format-args');

function PullRequest (githubToken) {
this.github = new Github({token: githubToken});
}

PullRequest.prototype.buildStarted = function (pullRequestInfo, targetUrl, cb) {
debug('buildStarted', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to be repeated throughout this module. might be better to add this check into the layer above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe. But in the layer above it would be repeated same amount of times. I'm not sure how to avoid that.

return cb(null);
}
var payload = {
state: 'pending',
description: 'PR-' + pullRequestInfo.number + ' is building on Runnable.',
// we use url to differentiate between several runnable builds
context: targetUrl,
target_url: targetUrl,
sha: pullRequestInfo.commit
};
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
};

PullRequest.prototype.buildSucceeded = function (pullRequestInfo, targetUrl, cb) {
debug('buildSucceeded', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
return cb(null);
}
var payload = {
state: 'success',
description: 'PR-' + pullRequestInfo.number + ' is ready to run on Runnable.',
// we use url to differentiate between several runnable builds
context: targetUrl,
target_url: targetUrl,
sha: pullRequestInfo.commit
};
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
};

PullRequest.prototype.buildErrored = function (pullRequestInfo, targetUrl, cb) {
debug('buildErrored', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
return cb(null);
}
var payload = {
state: 'error',
description: 'PR-' + pullRequestInfo.number + ' has failed to build on Runnable.',
// we use url to differentiate between several runnable builds
context: targetUrl,
target_url: targetUrl,
sha: pullRequestInfo.commit
};
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
};

PullRequest.prototype.serverSelectionStatus = function (pullRequestInfo, targetUrl, cb) {
debug('buildStarted', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
return cb(null);
}
var payload = {
state: 'pending',
description: 'Select a server to build PR-' + pullRequestInfo.number,
// we use url to differentiate between several runnable builds
context: targetUrl,
target_url: targetUrl,
sha: pullRequestInfo.commit
};
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I missed this function before. This is for when a PR comes in and there is no instance that is running with that branch to prompt for a server? This seems like it would be blocking some people's PRs because if they never follow through with this it can never leave the 'pending' state... why isn't this a pending deployment? /cc @prafulrana

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkendall you didn't miss it. I added this yesterday. So I added this function and noServersForPullRequest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Follow up question @podviaznikov: do we ever set the state to completed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This url includes /serverSelection/ in it, so it doesn't look like it is ever resolved to completed - is that something we need to do on the serverSelection side if the reference is from it? (@podviaznikov)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't set status to completed in this case. But I do like your idea.
I think if user selected server from this link - we can set it to the completed.
What do you think @prafulrana?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prafulrana said that we need this feature. But it can be deployed later. Not a blocker for PR. I'll handle this in my next PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkendall do you have more questions/feedback or this looks good to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay - as long as we know that's a thing... 👍



PullRequest.prototype.createDeployment = function (pullRequestInfo, serverName, payload, cb) {
debug('createDeployment', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
return cb(null);
}
var description = 'Deploying PR-' + pullRequestInfo.number + ' to ' +
serverName + ' on Runnable.';
var query = {
auto_merge: false,
environment: 'runnable',
description: description,
ref: pullRequestInfo.commit,
payload: JSON.stringify(payload || {}),
required_contexts: [] // we skip check on all `contexts` since we still can deploy
};
this.github.createDeployment(pullRequestInfo.repo, query, cb);
};


PullRequest.prototype.deploymentStarted =
function (pullRequestInfo, deploymentId, serverName, targetUrl, cb) {
debug('deploymentStarted', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
return cb(null);
}
var description = 'Deploying PR-' + pullRequestInfo.number + ' to ' +
serverName + ' on Runnable.';
var payload = {
id: deploymentId,
state: 'pending',
target_url: targetUrl,
description: description
};
this.github.createDeploymentStatus(pullRequestInfo.repo, payload, cb);
};

PullRequest.prototype.deploymentSucceeded =
function (pullRequestInfo, deploymentId, serverName, targetUrl, cb) {
debug('deploymentSucceeded', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
return cb(null);
}
var description = 'Deployed PR-' + pullRequestInfo.number +
' to ' + serverName + ' on Runnable.';
var payload = {
id: deploymentId,
state: 'success',
target_url: targetUrl,
description: description
};
this.github.createDeploymentStatus(pullRequestInfo.repo, payload, cb);
};

PullRequest.prototype.deploymentErrored =
function (pullRequestInfo, deploymentId, serverName, targetUrl, cb) {
debug('deploymentErrored', formatArgs(arguments));
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
return cb(null);
}
var description = 'Failed to deploy PR-' + pullRequestInfo.number +
' to ' + serverName + ' on Runnable.';
var payload = {
id: deploymentId,
state: 'error',
target_url: targetUrl,
description: description
};
this.github.createDeploymentStatus(pullRequestInfo.repo, payload, cb);
};

module.exports = PullRequest;
Loading