Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/screens/repo/screens/build/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ section.sticky {
margin-bottom: 10px;
padding: 20px;
}
section {
input {
border: 1px solid @gray-light;
font-size: 15px;
padding: 5px 10px;
margin-left: 10px;
}
}
74 changes: 73 additions & 1 deletion src/screens/repo/screens/build/menu.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React, { Component } from "react";
import RepoMenu from "../builds/menu";
import { RefreshIcon, CloseIcon } from "shared/components/icons";
import { RefreshIcon, CloseIcon, DeployIcon } from "shared/components/icons";

import {
cancelBuild,
restartBuild,
promoteBuild,
assertBuildMatrix,
} from "shared/utils/build";
import { findChildProcess } from "shared/utils/proc";
import { repositorySlug } from "shared/utils/repository";

import { branch } from "baobab-react/higher-order";
import { inject } from "config/client/inject";
import PlayIcon from "shared/components/icons/play";
import { STATUS_SUCCESS } from "shared/constants/status";

const binding = (props, context) => {
const { owner, repo, build } = props.match.params;
Expand All @@ -31,13 +34,39 @@ export default class BuildMenu extends Component {

this.handleCancel = this.handleCancel.bind(this);
this.handleRestart = this.handleRestart.bind(this);
this.handlePromote = this.handlePromote.bind(this);
this.togglePromote = this.togglePromote.bind(this);
}

getInitialState() {
return {
togglePromote: false,
customEnv: "",
};
}

handleRestart() {
const { dispatch, drone, repo, build } = this.props;
dispatch(restartBuild, drone, repo.owner, repo.name, build.number);
}

handlePromote(env) {
const { dispatch, drone, repo, build } = this.props;
dispatch(promoteBuild, drone, repo.owner, repo.name, build.number, env);
}

togglePromote() {
var state = this.state;
state.togglePromote = !this.state.togglePromote;
this.setState(state);
}

updateCustomEnv(evt) {
var state = this.state;
state.customEnv = evt.target.value;
this.setState(state);
}

handleCancel() {
const { dispatch, drone, repo, build, match } = this.props;
const proc = findChildProcess(build.procs, match.params.proc || 2);
Expand All @@ -57,6 +86,13 @@ export default class BuildMenu extends Component {
const { proc } = match.params;

const hideCancel = assertBuildMatrix(build) && !proc;
var handlePromote = this.handlePromote;
var envs = [];
if (build !== undefined && build.deploy_envs !== undefined) {
envs = build.deploy_envs.map(function(env) {
return env.name;
});
}

return (
<div>
Expand All @@ -79,6 +115,42 @@ export default class BuildMenu extends Component {
</button>
)}
</li>
<li>
Copy link

Choose a reason for hiding this comment

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

This <li> item will be empty when status =! success, maybe we should move in condition?

Copy link
Author

Choose a reason for hiding this comment

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

yes, you are right

{build.status === STATUS_SUCCESS ? (
<button onClick={this.togglePromote}>
<DeployIcon />
<span>Promote Build</span>
</button>
) : null}
{build.status === STATUS_SUCCESS && this.state.togglePromote ? (
<ul className="sub">
{envs.map(function(env, i) {
return (
<li key={i}>
<button onClick={handlePromote.bind(this, env)}>
<PlayIcon />
<span>{env}</span>
</button>
</li>
);
})}
<li>
<button
onClick={handlePromote.bind(this, this.state.customEnv)}
>
<PlayIcon />
<input
type="text"
value={this.state.customEnv}
onClick={event => event.stopPropagation()}
onChange={this.updateCustomEnv.bind(this)}
placeholder="Deployment target (eg: test)"
/>
</button>
</li>
</ul>
) : null}
</li>
</ul>
</section>
)}
Expand Down
25 changes: 25 additions & 0 deletions src/shared/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ export const restartBuild = (tree, client, owner, repo, build) => {
});
};

/**
* Promote build.
*
* @param {Object} tree - The drone state tree.
* @param {Object} client - The drone client.
* @param {string} owner - The repository owner.
* @param {string} name - The repository name.
* @param {number} build - The build number.
* @param {string} env - The environment deploy to.
*/
export const promoteBuild = (tree, client, owner, repo, build, env) => {
client
.restartBuild(owner, repo, build, {
fork: true,
event: "deployment",
deploy_to: env,
})
.then(result => {
displayMessage(tree, "Successfully promote your build");
})
.catch(() => {
displayMessage(tree, "Failed to promote your build");
Copy link

Choose a reason for hiding this comment

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

Same as before

});
};

/**
* Approves the blocked build.
*
Expand Down