-
Notifications
You must be signed in to change notification settings - Fork 1
Deployments api #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deployments api #569
Changes from all commits
b3f01c9
931ce38
548161f
0600efc
7e6f02c
288f426
d1509ec
a4c1f65
fd5c6e7
e852769
efcb921
64da9a6
f6f0f27
cf05335
01f7bf5
10e2656
2ac8f3a
4a1dadc
a6b0a2a
aa51a33
c69b0a9
1a8d793
29d30f1
e736c84
a1bd492
e21336a
81c6e15
1d41c57
1e51bd7
bf7982e
9fbfcde
37dbc12
6f095e1
4dd9cb1
950344a
a8722ab
d11f903
907e0cc
4834739
9503c76
ccd5e20
73da95f
ed817ec
6dd329a
b68deda
03605d8
28e21ad
6708b70
0bde653
9fceb47
e7b9056
fbff7db
7815f4f
b1c2509
f3ec9fa
cdee3dc
ea462ba
6e9ec66
9298286
569a09f
3bdcbfb
987d527
7b780b4
4645350
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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') { | ||
| 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); | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was intended.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. Follow up question @podviaznikov: do we ever set the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This url includes
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we don't set status to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.