Ran npx prettier --write "**/*.js" "*.js"

This commit is contained in:
Laszlo Fogas 2019-11-15 10:46:33 +01:00
parent a5733075d6
commit 12279686e8
85 changed files with 3428 additions and 3318 deletions

View file

@ -1,37 +1,33 @@
module.exports = { module.exports = {
"extends": [ extends: [
"standard", "standard",
"plugin:jest/recommended", "plugin:jest/recommended",
"plugin:react/recommended", "plugin:react/recommended",
"prettier", "prettier",
"prettier/react" "prettier/react"
], ],
"plugins": [ plugins: ["react", "jest", "prettier"],
"react", parser: "babel-eslint",
"jest", parserOptions: {
"prettier" ecmaVersion: 2016,
], sourceType: "module",
"parser": "babel-eslint", ecmaFeatures: {
"parserOptions": { jsx: true
"ecmaVersion": 2016,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
} }
}, },
"env": { env: {
"es6": true, es6: true,
"browser": true, browser: true,
"node": true, node: true,
"jest/globals": true "jest/globals": true
}, },
"rules": { rules: {
"react/prop-types": 1, "react/prop-types": 1,
"prettier/prettier": [ "prettier/prettier": [
"error", "error",
{ {
"trailingComma": "all", trailingComma: "all",
"useTabs": true useTabs: true
} }
] ]
} }

View file

@ -6,7 +6,7 @@ export const drone = (client, Component) => {
const component = class extends React.Component { const component = class extends React.Component {
getChildContext() { getChildContext() {
return { return {
drone: client, drone: client
}; };
} }
@ -16,7 +16,7 @@ export const drone = (client, Component) => {
}; };
component.childContextTypes = { component.childContextTypes = {
drone: (props, propName) => {}, drone: (props, propName) => {}
}; };
return component; return component;

View file

@ -11,62 +11,62 @@ const state = {
data: user, data: user,
error: undefined, error: undefined,
loaded: true, loaded: true,
syncing: sync, syncing: sync
}, },
feed: { feed: {
loaded: false, loaded: false,
error: undefined, error: undefined,
data: {}, data: {}
}, },
repos: { repos: {
loaded: false, loaded: false,
error: undefined, error: undefined,
data: {}, data: {}
}, },
secrets: { secrets: {
loaded: false, loaded: false,
error: undefined, error: undefined,
data: {}, data: {}
}, },
registry: { registry: {
error: undefined, error: undefined,
loaded: false, loaded: false,
data: {}, data: {}
}, },
builds: { builds: {
loaded: false, loaded: false,
error: undefined, error: undefined,
data: {}, data: {}
}, },
logs: { logs: {
follow: false, follow: false,
loading: true, loading: true,
error: false, error: false,
data: {}, data: {}
}, },
token: { token: {
value: undefined, value: undefined,
error: undefined, error: undefined,
loading: false, loading: false
}, },
message: { message: {
show: false, show: false,
text: undefined, text: undefined,
error: false, error: false
}, },
location: { location: {
protocol: window.location.protocol, protocol: window.location.protocol,
host: window.location.host, host: window.location.host
}, }
}; };
const tree = new Baobab(state); const tree = new Baobab(state);

View file

@ -26,7 +26,7 @@ export default class Sidebar extends Component {
this.setState({ this.setState({
starred: JSON.parse(localStorage.getItem("starred") || "[]"), starred: JSON.parse(localStorage.getItem("starred") || "[]"),
starredOpen: (localStorage.getItem("starredOpen") || "true") === "true", starredOpen: (localStorage.getItem("starredOpen") || "true") === "true",
reposOpen: (localStorage.getItem("reposOpen") || "true") === "true", reposOpen: (localStorage.getItem("reposOpen") || "true") === "true"
}); });
this.handleFilter = this.handleFilter.bind(this); this.handleFilter = this.handleFilter.bind(this);
@ -44,7 +44,7 @@ export default class Sidebar extends Component {
handleFilter(e) { handleFilter(e) {
this.setState({ this.setState({
filter: e.target.value, filter: e.target.value
}); });
} }
@ -122,15 +122,13 @@ export default class Sidebar extends Component {
triggerOpenedClassName={style.Collapsible__trigger} triggerOpenedClassName={style.Collapsible__trigger}
triggerClassName={style.Collapsible__trigger} triggerClassName={style.Collapsible__trigger}
> >
{feed.loaded === false ? ( {feed.loaded === false
LOADING ? LOADING
) : feed.error ? ( : feed.error
ERROR ? ERROR
) : list.length === 0 ? ( : list.length === 0
EMPTY ? EMPTY
) : ( : this.renderFeed(list, true)}
this.renderFeed(list, true)
)}
</Collapsible> </Collapsible>
<Collapsible <Collapsible
trigger="Repos" trigger="Repos"
@ -147,17 +145,15 @@ export default class Sidebar extends Component {
placeholder="Search …" placeholder="Search …"
onChange={this.handleFilter} onChange={this.handleFilter}
/> />
{feed.loaded === false ? ( {feed.loaded === false
LOADING ? LOADING
) : feed.error ? ( : feed.error
ERROR ? ERROR
) : list.length === 0 ? ( : list.length === 0
EMPTY ? EMPTY
) : filtered.length > 0 ? ( : filtered.length > 0
this.renderFeed(filtered.sort(compareFeedItem), false) ? this.renderFeed(filtered.sort(compareFeedItem), false)
) : ( : NO_MATCHES}
NO_MATCHES
)}
</Collapsible> </Collapsible>
</div> </div>
); );

View file

@ -34,7 +34,7 @@ const binding = (props, context) => {
user: ["user"], user: ["user"],
message: ["message"], message: ["message"],
sidebar: ["sidebar"], sidebar: ["sidebar"],
menu: ["menu"], menu: ["menu"]
}; };
}; };
@ -42,7 +42,7 @@ const mapScreenSizeToProps = screenSize => {
return { return {
isTablet: screenSize["small"], isTablet: screenSize["small"],
isMobile: screenSize["mobile"], isMobile: screenSize["mobile"],
isDesktop: screenSize["> small"], isDesktop: screenSize["> small"]
}; };
}; };
@ -54,7 +54,7 @@ export default class Default extends Component {
super(props, context); super(props, context);
this.state = { this.state = {
menu: false, menu: false,
feed: false, feed: false
}; };
this.openMenu = this.openMenu.bind(this); this.openMenu = this.openMenu.bind(this);
@ -140,11 +140,8 @@ export default class Default extends Component {
exact={true} exact={true}
component={UserReposMenu} component={UserReposMenu}
/> />
<Route <Route path="/account/" exact={false} component={undefined} />
path="/account/" BuildMenu
exact={false}
component={undefined}
/>BuildMenu
<Route <Route
path="/:owner/:repo/:build(\d*)/:proc(\d*)" path="/:owner/:repo/:build(\d*)/:proc(\d*)"
exact={true} exact={true}

View file

@ -7,7 +7,7 @@ const binding = (props, context) => {
return { return {
feed: ["feed"], feed: ["feed"],
user: ["user", "data"], user: ["user", "data"],
syncing: ["user", "syncing"], syncing: ["user", "syncing"]
}; };
}; };

View file

@ -5,7 +5,7 @@ export class Elapsed extends Component {
super(props); super(props);
this.state = { this.state = {
elapsed: 0, elapsed: 0
}; };
this.tick = this.tick.bind(this); this.tick = this.tick.bind(this);
@ -23,7 +23,7 @@ export class Elapsed extends Component {
const { start } = this.props; const { start } = this.props;
const stop = ~~(Date.now() / 1000); const stop = ~~(Date.now() / 1000);
this.setState({ this.setState({
elapsed: stop - start, elapsed: stop - start
}); });
} }
@ -33,13 +33,11 @@ export class Elapsed extends Component {
date.setSeconds(elapsed); date.setSeconds(elapsed);
return ( return (
<time> <time>
{!elapsed ? ( {!elapsed
undefined ? undefined
) : elapsed > 3600 ? ( : elapsed > 3600
date.toISOString().substr(11, 8) ? date.toISOString().substr(11, 8)
) : ( : date.toISOString().substr(14, 5)}
date.toISOString().substr(14, 5)
)}
</time> </time>
); );
} }

View file

@ -5,7 +5,7 @@ import { fetchBuild, approveBuild, declineBuild } from "shared/utils/build";
import { import {
STATUS_BLOCKED, STATUS_BLOCKED,
STATUS_DECLINED, STATUS_DECLINED,
STATUS_ERROR, STATUS_ERROR
} from "shared/constants/status"; } from "shared/constants/status";
import { findChildProcess } from "shared/utils/proc"; import { findChildProcess } from "shared/utils/proc";
@ -29,7 +29,7 @@ const binding = (props, context) => {
return { return {
repo: ["repos", "data", slug], repo: ["repos", "data", slug],
build: ["builds", "data", slug, number], build: ["builds", "data", slug, number]
}; };
}; };
@ -54,7 +54,7 @@ export default class BuildLogs extends Component {
drone, drone,
repo.owner, repo.owner,
repo.name, repo.name,
build.number, build.number
); );
} }
@ -65,7 +65,7 @@ export default class BuildLogs extends Component {
drone, drone,
repo.owner, repo.owner,
repo.name, repo.name,
build.number, build.number
); );
} }
@ -81,7 +81,7 @@ export default class BuildLogs extends Component {
fetchRepository, fetchRepository,
props.drone, props.drone,
props.match.params.owner, props.match.params.owner,
props.match.params.repo, props.match.params.repo
); );
} }
if (!props.build || !props.build.procs) { if (!props.build || !props.build.procs) {
@ -90,7 +90,7 @@ export default class BuildLogs extends Component {
props.drone, props.drone,
props.match.params.owner, props.match.params.owner,
props.match.params.repo, props.match.params.repo,
props.match.params.build, props.match.params.build
); );
} }
} }
@ -160,11 +160,9 @@ export default class BuildLogs extends Component {
</div> </div>
<div className={styles.left}> <div className={styles.left}>
<div className={styles.logerror}> <div className={styles.logerror}>
{build.status === STATUS_ERROR ? ( {build.status === STATUS_ERROR
build.error ? build.error
) : ( : "Pipeline execution was declined"}
"Pipeline execution was declined"
)}
</div> </div>
</div> </div>
</div> </div>
@ -249,7 +247,7 @@ export class BuildLogsTitle extends Component {
key={`${owner}-${repo}-${build}`} key={`${owner}-${repo}-${build}`}
> >
{build} {build}
</Link>, </Link>
]} ]}
/> />
); );

View file

@ -24,7 +24,7 @@ const binding = (props, context) => {
eof: ["logs", "data", slug, number, pid, "eof"], eof: ["logs", "data", slug, number, pid, "eof"],
loading: ["logs", "data", slug, number, pid, "loading"], loading: ["logs", "data", slug, number, pid, "loading"],
error: ["logs", "data", slug, number, pid, "error"], error: ["logs", "data", slug, number, pid, "error"],
follow: ["logs", "follow"], follow: ["logs", "follow"]
}; };
}; };
@ -57,7 +57,7 @@ export default class Output extends Component {
nextProps.match.params.owner, nextProps.match.params.owner,
nextProps.match.params.repo, nextProps.match.params.repo,
nextProps.build.number, nextProps.build.number,
nextProps.proc.pid, nextProps.proc.pid
); );
} }
@ -68,7 +68,7 @@ export default class Output extends Component {
nextProps.match.params.owner, nextProps.match.params.owner,
nextProps.match.params.repo, nextProps.match.params.repo,
nextProps.build.number, nextProps.build.number,
nextProps.proc, nextProps.proc
); );
} }
} }

View file

@ -15,7 +15,7 @@ const binding = (props, context) => {
const number = parseInt(build); const number = parseInt(build);
return { return {
repo: ["repos", "data", slug], repo: ["repos", "data", slug],
build: ["builds", "data", slug, number], build: ["builds", "data", slug, number]
}; };
}; };
@ -44,7 +44,7 @@ export default class BuildMenu extends Component {
repo.owner, repo.owner,
repo.name, repo.name,
build.number, build.number,
proc.ppid, proc.ppid
); );
} }

View file

@ -11,7 +11,7 @@ export default class Header extends Component {
elements={[ elements={[
<Link to={`/${owner}/${repo}`} key={`${owner}-${repo}`}> <Link to={`/${owner}/${repo}`} key={`${owner}-${repo}`}>
{owner} / {repo} {owner} / {repo}
</Link>, </Link>
]} ]}
/> />
</div> </div>

View file

@ -17,7 +17,7 @@ const binding = (props, context) => {
repo: ["repos", "data", slug], repo: ["repos", "data", slug],
builds: ["builds", "data", slug], builds: ["builds", "data", slug],
loaded: ["builds", "loaded"], loaded: ["builds", "loaded"],
error: ["builds", "error"], error: ["builds", "error"]
}; };
}; };
@ -75,7 +75,7 @@ export default class Main extends Component {
drone, drone,
match.params.owner, match.params.owner,
match.params.repo, match.params.repo,
page, page
); );
} }

View file

@ -8,7 +8,7 @@ export default class RepoMenu extends Component {
{ to: `/${owner}/${repo}`, label: "Builds" }, { to: `/${owner}/${repo}`, label: "Builds" },
{ to: `/${owner}/${repo}/settings/secrets`, label: "Secrets" }, { to: `/${owner}/${repo}/settings/secrets`, label: "Secrets" },
{ to: `/${owner}/${repo}/settings/registry`, label: "Registry" }, { to: `/${owner}/${repo}/settings/registry`, label: "Registry" },
{ to: `/${owner}/${repo}/settings`, label: "Settings" }, { to: `/${owner}/${repo}/settings`, label: "Settings" }
]; ];
return <Menu items={menu} {...this.props} />; return <Menu items={menu} {...this.props} />;
} }

View file

@ -8,7 +8,7 @@ export class Form extends Component {
this.state = { this.state = {
address: "", address: "",
username: "", username: "",
password: "", password: ""
}; };
this._handleAddressChange = this._handleAddressChange.bind(this); this._handleAddressChange = this._handleAddressChange.bind(this);
@ -37,7 +37,7 @@ export class Form extends Component {
const detail = { const detail = {
address: this.state.address, address: this.state.address,
username: this.state.username, username: this.state.username,
password: this.state.password, password: this.state.password
}; };
onsubmit({ detail }); onsubmit({ detail });

View file

@ -4,7 +4,7 @@ import { repositorySlug } from "shared/utils/repository";
import { import {
fetchRegistryList, fetchRegistryList,
createRegistry, createRegistry,
deleteRegistry, deleteRegistry
} from "shared/utils/registry"; } from "shared/utils/registry";
import { branch } from "baobab-react/higher-order"; import { branch } from "baobab-react/higher-order";
@ -19,7 +19,7 @@ const binding = (props, context) => {
const slug = repositorySlug(owner, repo); const slug = repositorySlug(owner, repo);
return { return {
loaded: ["registry", "loaded"], loaded: ["registry", "loaded"],
registries: ["registry", "data", slug], registries: ["registry", "data", slug]
}; };
}; };
@ -49,7 +49,7 @@ export default class RepoRegistry extends Component {
const registry = { const registry = {
address: e.detail.address, address: e.detail.address,
username: e.detail.username, username: e.detail.username,
password: e.detail.password, password: e.detail.password
}; };
dispatch(createRegistry, drone, owner, repo, registry); dispatch(createRegistry, drone, owner, repo, registry);

View file

@ -4,7 +4,7 @@ import {
EVENT_PUSH, EVENT_PUSH,
EVENT_TAG, EVENT_TAG,
EVENT_PULL_REQUEST, EVENT_PULL_REQUEST,
EVENT_DEPLOY, EVENT_DEPLOY
} from "shared/constants/events"; } from "shared/constants/events";
import styles from "./form.less"; import styles from "./form.less";
@ -16,7 +16,7 @@ export class Form extends Component {
this.state = { this.state = {
name: "", name: "",
value: "", value: "",
event: [EVENT_PUSH, EVENT_TAG, EVENT_DEPLOY], event: [EVENT_PUSH, EVENT_TAG, EVENT_DEPLOY]
}; };
this._handleNameChange = this._handleNameChange.bind(this); this._handleNameChange = this._handleNameChange.bind(this);
@ -55,7 +55,7 @@ export class Form extends Component {
const detail = { const detail = {
name: this.state.name, name: this.state.name,
value: this.state.value, value: this.state.value,
event: this.state.event, event: this.state.event
}; };
onsubmit({ detail }); onsubmit({ detail });

View file

@ -4,7 +4,7 @@ import { repositorySlug } from "shared/utils/repository";
import { import {
fetchSecretList, fetchSecretList,
createSecret, createSecret,
deleteSecret, deleteSecret
} from "shared/utils/secrets"; } from "shared/utils/secrets";
import { branch } from "baobab-react/higher-order"; import { branch } from "baobab-react/higher-order";
@ -19,7 +19,7 @@ const binding = (props, context) => {
const slug = repositorySlug(owner, repo); const slug = repositorySlug(owner, repo);
return { return {
loaded: ["secrets", "loaded"], loaded: ["secrets", "loaded"],
secrets: ["secrets", "data", slug], secrets: ["secrets", "data", slug]
}; };
}; };
@ -47,7 +47,7 @@ export default class RepoSecrets extends Component {
const secret = { const secret = {
name: e.detail.name, name: e.detail.name,
value: e.detail.value, value: e.detail.value,
event: e.detail.event, event: e.detail.event
}; };
dispatch(createSecret, drone, owner, repo, secret); dispatch(createSecret, drone, owner, repo, secret);

View file

@ -6,13 +6,13 @@ import { inject } from "config/client/inject";
import { import {
fetchRepository, fetchRepository,
updateRepository, updateRepository,
repositorySlug, repositorySlug
} from "shared/utils/repository"; } from "shared/utils/repository";
import { import {
VISIBILITY_PUBLIC, VISIBILITY_PUBLIC,
VISIBILITY_PRIVATE, VISIBILITY_PRIVATE,
VISIBILITY_INTERNAL, VISIBILITY_INTERNAL
} from "shared/constants/visibility"; } from "shared/constants/visibility";
import styles from "./index.less"; import styles from "./index.less";
@ -22,7 +22,7 @@ const binding = (props, context) => {
const slug = repositorySlug(owner, repo); const slug = repositorySlug(owner, repo);
return { return {
user: ["user", "data"], user: ["user", "data"],
repo: ["repos", "data", slug], repo: ["repos", "data", slug]
}; };
}; };

View file

@ -6,7 +6,7 @@ import { inject } from "config/client/inject";
import { import {
fetchRepostoryList, fetchRepostoryList,
disableRepository, disableRepository,
enableRepository, enableRepository
} from "shared/utils/repository"; } from "shared/utils/repository";
import { List, Item } from "./components"; import { List, Item } from "./components";
@ -18,7 +18,7 @@ const binding = (props, context) => {
return { return {
repos: ["repos", "data"], repos: ["repos", "data"],
loaded: ["repos", "loaded"], loaded: ["repos", "loaded"],
error: ["repos", "error"], error: ["repos", "error"]
}; };
}; };
@ -35,7 +35,7 @@ export default class UserRepos extends Component {
handleFilter(e) { handleFilter(e) {
this.setState({ this.setState({
search: e.target.value, search: e.target.value
}); });
} }

View file

@ -7,7 +7,7 @@ import Menu from "shared/components/menu";
const binding = (props, context) => { const binding = (props, context) => {
return { return {
repos: ["repos"], repos: ["repos"]
}; };
}; };

View file

@ -8,7 +8,7 @@ import styles from "./index.less";
const binding = (props, context) => { const binding = (props, context) => {
return { return {
location: ["location"], location: ["location"],
token: ["token"], token: ["token"]
}; };
}; };
@ -48,7 +48,9 @@ export default class Tokens extends Component {
} }
const usageWithCURL = (location, token) => { const usageWithCURL = (location, token) => {
return `curl -i ${location.protocol}//${location.host}/api/user -H "Authorization: Bearer ${token}"`; return `curl -i ${location.protocol}//${
location.host
}/api/user -H "Authorization: Bearer ${token}"`;
}; };
const usageWithCLI = (location, token) => { const usageWithCLI = (location, token) => {

View file

@ -5,7 +5,7 @@ import Status from "../status";
import { import {
STATUS_FAILURE, STATUS_FAILURE,
STATUS_RUNNING, STATUS_RUNNING,
STATUS_SUCCESS, STATUS_SUCCESS
} from "shared/constants/status"; } from "shared/constants/status";
jest.dontMock("../status"); jest.dontMock("../status");
@ -16,10 +16,10 @@ describe("Status component", () => {
const instance = status.instance(); const instance = status.instance();
expect( expect(
instance.shouldComponentUpdate({ status: STATUS_FAILURE }), instance.shouldComponentUpdate({ status: STATUS_FAILURE })
).toBeFalsy(); ).toBeFalsy();
expect( expect(
instance.shouldComponentUpdate({ status: STATUS_SUCCESS }), instance.shouldComponentUpdate({ status: STATUS_SUCCESS })
).toBeTruthy(); ).toBeTruthy();
expect(status.hasClass("failure")).toBeTruthy(); expect(status.hasClass("failure")).toBeTruthy();
}); });

View file

@ -5,7 +5,7 @@ export default class Avatar extends Component {
render() { render() {
const image = this.props.image; const image = this.props.image;
const style = { const style = {
backgroundImage: `url(${image})`, backgroundImage: `url(${image})`
}; };
return <div className={styles.avatar} style={style} />; return <div className={styles.avatar} style={style} />;
} }

View file

@ -5,12 +5,12 @@ import {
DeployIcon, DeployIcon,
LaunchIcon, LaunchIcon,
MergeIcon, MergeIcon,
TagIcon, TagIcon
} from "shared/components/icons/index"; } from "shared/components/icons/index";
import { import {
EVENT_TAG, EVENT_TAG,
EVENT_PULL_REQUEST, EVENT_PULL_REQUEST,
EVENT_DEPLOY, EVENT_DEPLOY
} from "shared/constants/events"; } from "shared/constants/events";
import styles from "./build_event.less"; import styles from "./build_event.less";
@ -40,15 +40,13 @@ export default class BuildEvent extends Component {
)} )}
</div> </div>
<div> <div>
{event === EVENT_TAG && refs ? ( {event === EVENT_TAG && refs
trimTagRef(refs) ? trimTagRef(refs)
) : event === EVENT_PULL_REQUEST && refspec ? ( : event === EVENT_PULL_REQUEST && refspec
trimMergeRef(refs) ? trimMergeRef(refs)
) : event === EVENT_DEPLOY && target ? ( : event === EVENT_DEPLOY && target
target ? target
) : ( : branch}
branch
)}
</div> </div>
</div> </div>
<a href={link} target="_blank"> <a href={link} target="_blank">

View file

@ -41,5 +41,5 @@ export {
StarIcon, StarIcon,
SyncIcon, SyncIcon,
TagIcon, TagIcon,
TimelapseIcon, TimelapseIcon
}; };

View file

@ -10,7 +10,7 @@ import {
STATUS_RUNNING, STATUS_RUNNING,
STATUS_SKIPPED, STATUS_SKIPPED,
STATUS_STARTED, STATUS_STARTED,
STATUS_SUCCESS, STATUS_SUCCESS
} from "shared/constants/status"; } from "shared/constants/status";
import style from "./status.less"; import style from "./status.less";
@ -19,7 +19,7 @@ import {
CloseIcon, CloseIcon,
ClockIcon, ClockIcon,
RefreshIcon, RefreshIcon,
RemoveIcon, RemoveIcon
} from "./icons/index"; } from "./icons/index";
const defaultIconSize = 15; const defaultIconSize = 15;

View file

@ -19,5 +19,5 @@ export {
STATUS_RUNNING, STATUS_RUNNING,
STATUS_SKIPPED, STATUS_SKIPPED,
STATUS_SUCCESS, STATUS_SUCCESS,
STATUS_STARTED, STATUS_STARTED
}; };

View file

@ -20,7 +20,7 @@ export function fetchLogs(tree, client, owner, repo, build, proc) {
const slug = repositorySlug(owner, repo); const slug = repositorySlug(owner, repo);
const init = { const init = {
data: [], data: [],
loading: true, loading: true
}; };
tree.set(["logs", "data", slug, build, proc], init); tree.set(["logs", "data", slug, build, proc], init);

View file

@ -23,7 +23,7 @@
} }
} }
var _createClass = function () { var _createClass = (function() {
function defineProperties(target, props) { function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) { for (var i = 0; i < props.length; i++) {
var descriptor = props[i]; var descriptor = props[i];
@ -39,9 +39,9 @@
if (staticProps) defineProperties(Constructor, staticProps); if (staticProps) defineProperties(Constructor, staticProps);
return Constructor; return Constructor;
}; };
}(); })();
var DroneClient = function () { var DroneClient = (function() {
function DroneClient(server, token, csrf) { function DroneClient(server, token, csrf) {
_classCallCheck(this, DroneClient); _classCallCheck(this, DroneClient);
@ -50,160 +50,260 @@
this.csrf = csrf; this.csrf = csrf;
} }
_createClass(DroneClient, [{ _createClass(
DroneClient,
[
{
key: "getRepoList", key: "getRepoList",
value: function getRepoList(opts) { value: function getRepoList(opts) {
var query = encodeQueryString(opts); var query = encodeQueryString(opts);
return this._get("/api/user/repos?" + query); return this._get("/api/user/repos?" + query);
} }
}, { },
{
key: "getRepo", key: "getRepo",
value: function getRepo(owner, repo) { value: function getRepo(owner, repo) {
return this._get("/api/repos/" + owner + "/" + repo); return this._get("/api/repos/" + owner + "/" + repo);
} }
}, { },
{
key: "activateRepo", key: "activateRepo",
value: function activateRepo(owner, repo) { value: function activateRepo(owner, repo) {
return this._post("/api/repos/" + owner + "/" + repo); return this._post("/api/repos/" + owner + "/" + repo);
} }
}, { },
{
key: "updateRepo", key: "updateRepo",
value: function updateRepo(owner, repo, data) { value: function updateRepo(owner, repo, data) {
return this._patch("/api/repos/" + owner + "/" + repo, data); return this._patch("/api/repos/" + owner + "/" + repo, data);
} }
}, { },
{
key: "deleteRepo", key: "deleteRepo",
value: function deleteRepo(owner, repo) { value: function deleteRepo(owner, repo) {
return this._delete("/api/repos/" + owner + "/" + repo); return this._delete("/api/repos/" + owner + "/" + repo);
} }
}, { },
{
key: "getBuildList", key: "getBuildList",
value: function getBuildList(owner, repo, opts) { value: function getBuildList(owner, repo, opts) {
var query = encodeQueryString(opts); var query = encodeQueryString(opts);
return this._get("/api/repos/" + owner + "/" + repo + "/builds?" + query); return this._get(
"/api/repos/" + owner + "/" + repo + "/builds?" + query
);
} }
}, { },
{
key: "getBuild", key: "getBuild",
value: function getBuild(owner, repo, number) { value: function getBuild(owner, repo, number) {
return this._get("/api/repos/" + owner + "/" + repo + "/builds/" + number); return this._get(
"/api/repos/" + owner + "/" + repo + "/builds/" + number
);
} }
}, { },
{
key: "getBuildFeed", key: "getBuildFeed",
value: function getBuildFeed(opts) { value: function getBuildFeed(opts) {
var query = encodeQueryString(opts); var query = encodeQueryString(opts);
return this._get("/api/user/feed?" + query); return this._get("/api/user/feed?" + query);
} }
}, { },
{
key: "cancelBuild", key: "cancelBuild",
value: function cancelBuild(owner, repo, number, ppid) { value: function cancelBuild(owner, repo, number, ppid) {
return this._delete("/api/repos/" + owner + "/" + repo + "/builds/" + number + "/" + ppid); return this._delete(
"/api/repos/" +
owner +
"/" +
repo +
"/builds/" +
number +
"/" +
ppid
);
} }
}, { },
{
key: "approveBuild", key: "approveBuild",
value: function approveBuild(owner, repo, build) { value: function approveBuild(owner, repo, build) {
return this._post("/api/repos/" + owner + "/" + repo + "/builds/" + build + "/approve"); return this._post(
"/api/repos/" +
owner +
"/" +
repo +
"/builds/" +
build +
"/approve"
);
} }
}, { },
{
key: "declineBuild", key: "declineBuild",
value: function declineBuild(owner, repo, build) { value: function declineBuild(owner, repo, build) {
return this._post("/api/repos/" + owner + "/" + repo + "/builds/" + build + "/decline"); return this._post(
"/api/repos/" +
owner +
"/" +
repo +
"/builds/" +
build +
"/decline"
);
} }
}, { },
{
key: "restartBuild", key: "restartBuild",
value: function restartBuild(owner, repo, build, opts) { value: function restartBuild(owner, repo, build, opts) {
var query = encodeQueryString(opts); var query = encodeQueryString(opts);
return this._post("/api/repos/" + owner + "/" + repo + "/builds/" + build + "?" + query); return this._post(
"/api/repos/" +
owner +
"/" +
repo +
"/builds/" +
build +
"?" +
query
);
} }
}, { },
{
key: "getLogs", key: "getLogs",
value: function getLogs(owner, repo, build, proc) { value: function getLogs(owner, repo, build, proc) {
return this._get("/api/repos/" + owner + "/" + repo + "/logs/" + build + "/" + proc); return this._get(
"/api/repos/" + owner + "/" + repo + "/logs/" + build + "/" + proc
);
} }
}, { },
{
key: "getArtifact", key: "getArtifact",
value: function getArtifact(owner, repo, build, proc, file) { value: function getArtifact(owner, repo, build, proc, file) {
return this._get("/api/repos/" + owner + "/" + repo + "/files/" + build + "/" + proc + "/" + file + "?raw=true"); return this._get(
"/api/repos/" +
owner +
"/" +
repo +
"/files/" +
build +
"/" +
proc +
"/" +
file +
"?raw=true"
);
} }
}, { },
{
key: "getArtifactList", key: "getArtifactList",
value: function getArtifactList(owner, repo, build) { value: function getArtifactList(owner, repo, build) {
return this._get("/api/repos/" + owner + "/" + repo + "/files/" + build); return this._get(
"/api/repos/" + owner + "/" + repo + "/files/" + build
);
} }
}, { },
{
key: "getSecretList", key: "getSecretList",
value: function getSecretList(owner, repo) { value: function getSecretList(owner, repo) {
return this._get("/api/repos/" + owner + "/" + repo + "/secrets"); return this._get("/api/repos/" + owner + "/" + repo + "/secrets");
} }
}, { },
{
key: "createSecret", key: "createSecret",
value: function createSecret(owner, repo, secret) { value: function createSecret(owner, repo, secret) {
return this._post("/api/repos/" + owner + "/" + repo + "/secrets", secret); return this._post(
"/api/repos/" + owner + "/" + repo + "/secrets",
secret
);
} }
}, { },
{
key: "deleteSecret", key: "deleteSecret",
value: function deleteSecret(owner, repo, secret) { value: function deleteSecret(owner, repo, secret) {
return this._delete("/api/repos/" + owner + "/" + repo + "/secrets/" + secret); return this._delete(
"/api/repos/" + owner + "/" + repo + "/secrets/" + secret
);
} }
}, { },
{
key: "getRegistryList", key: "getRegistryList",
value: function getRegistryList(owner, repo) { value: function getRegistryList(owner, repo) {
return this._get("/api/repos/" + owner + "/" + repo + "/registry"); return this._get("/api/repos/" + owner + "/" + repo + "/registry");
} }
}, { },
{
key: "createRegistry", key: "createRegistry",
value: function createRegistry(owner, repo, registry) { value: function createRegistry(owner, repo, registry) {
return this._post("/api/repos/" + owner + "/" + repo + "/registry", registry); return this._post(
"/api/repos/" + owner + "/" + repo + "/registry",
registry
);
} }
}, { },
{
key: "deleteRegistry", key: "deleteRegistry",
value: function deleteRegistry(owner, repo, address) { value: function deleteRegistry(owner, repo, address) {
return this._delete("/api/repos/" + owner + "/" + repo + "/registry/" + address); return this._delete(
"/api/repos/" + owner + "/" + repo + "/registry/" + address
);
} }
}, { },
{
key: "getSelf", key: "getSelf",
value: function getSelf() { value: function getSelf() {
return this._get("/api/user"); return this._get("/api/user");
} }
}, { },
{
key: "getToken", key: "getToken",
value: function getToken() { value: function getToken() {
return this._post("/api/user/token"); return this._post("/api/user/token");
} }
}, { },
{
key: "on", key: "on",
value: function on(callback) { value: function on(callback) {
return this._subscribe("/stream/events", callback, { return this._subscribe("/stream/events", callback, {
reconnect: true reconnect: true
}); });
} }
}, { },
{
key: "stream", key: "stream",
value: function stream(owner, repo, build, proc, callback) { value: function stream(owner, repo, build, proc, callback) {
return this._subscribe("/stream/logs/" + owner + "/" + repo + "/" + build + "/" + proc, callback, { return this._subscribe(
"/stream/logs/" + owner + "/" + repo + "/" + build + "/" + proc,
callback,
{
reconnect: false reconnect: false
});
} }
}, { );
}
},
{
key: "_get", key: "_get",
value: function _get(path) { value: function _get(path) {
return this._request("GET", path, null); return this._request("GET", path, null);
} }
}, { },
{
key: "_post", key: "_post",
value: function _post(path, data) { value: function _post(path, data) {
return this._request("POST", path, data); return this._request("POST", path, data);
} }
}, { },
{
key: "_patch", key: "_patch",
value: function _patch(path, data) { value: function _patch(path, data) {
return this._request("PATCH", path, data); return this._request("PATCH", path, data);
} }
}, { },
{
key: "_delete", key: "_delete",
value: function _delete(path) { value: function _delete(path) {
return this._request("DELETE", path, null); return this._request("DELETE", path, null);
} }
}, { },
{
key: "_subscribe", key: "_subscribe",
value: function _subscribe(path, callback, opts) { value: function _subscribe(path, callback, opts) {
var query = encodeQueryString({ var query = encodeQueryString({
@ -226,7 +326,8 @@
} }
return events; return events;
} }
}, { },
{
key: "_request", key: "_request",
value: function _request(method, path, data) { value: function _request(method, path, data) {
var endpoint = [this.server, path].join(""); var endpoint = [this.server, path].join("");
@ -238,7 +339,8 @@
if (method !== "GET" && this.csrf) { if (method !== "GET" && this.csrf) {
xhr.setRequestHeader("X-CSRF-TOKEN", this.csrf); xhr.setRequestHeader("X-CSRF-TOKEN", this.csrf);
} }
return new Promise(function (resolve, reject) { return new Promise(
function(resolve, reject) {
xhr.onload = function() { xhr.onload = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if (xhr.status >= 300) { if (xhr.status >= 300) {
@ -253,7 +355,10 @@
return; return;
} }
var contentType = xhr.getResponseHeader("Content-Type"); var contentType = xhr.getResponseHeader("Content-Type");
if (contentType && contentType.startsWith("application/json")) { if (
contentType &&
contentType.startsWith("application/json")
) {
resolve(JSON.parse(xhr.response)); resolve(JSON.parse(xhr.response));
} else { } else {
resolve(xhr.response); resolve(xhr.response);
@ -269,38 +374,58 @@
} else { } else {
xhr.send(); xhr.send();
} }
}.bind(this)); }.bind(this)
);
} }
}], [{ }
],
[
{
key: "fromEnviron", key: "fromEnviron",
value: function fromEnviron() { value: function fromEnviron() {
return new DroneClient(process && process.env && process.env.DRONE_SERVER, process && process.env && process.env.DRONE_TOKEN, process && process.env && process.env.DRONE_CSRF); return new DroneClient(
process && process.env && process.env.DRONE_SERVER,
process && process.env && process.env.DRONE_TOKEN,
process && process.env && process.env.DRONE_CSRF
);
} }
}, { },
{
key: "fromWindow", key: "fromWindow",
value: function fromWindow() { value: function fromWindow() {
return new DroneClient(window && window.DRONE_SERVER, window && window.DRONE_TOKEN, window && window.DRONE_CSRF); return new DroneClient(
window && window.DRONE_SERVER,
window && window.DRONE_TOKEN,
window && window.DRONE_CSRF
);
} }
}]); }
]
);
return DroneClient; return DroneClient;
}(); })();
exports.default = DroneClient; exports.default = DroneClient;
/** /**
* Encodes the values into url encoded form sorted by key. * Encodes the values into url encoded form sorted by key.
* *
* @param {object} query parameters in key value object. * @param {object} query parameters in key value object.
* @return {string} query parameter string * @return {string} query parameter string
*/ */
var encodeQueryString = exports.encodeQueryString = function encodeQueryString() { var encodeQueryString = (exports.encodeQueryString = function encodeQueryString() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var params =
arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return params ? Object.keys(params).sort().map(function (key) { return params
? Object.keys(params)
.sort()
.map(function(key) {
var val = params[key]; var val = params[key];
return encodeURIComponent(key) + "=" + encodeURIComponent(val); return encodeURIComponent(key) + "=" + encodeURIComponent(val);
}).join("&") : ""; })
}; .join("&")
: "";
});
}); });