Skip to content
Permalink
Browse files

feat(linux): accept distribution and component Bintray options

This options are needed to correctly publish Debian packages to a
Bintray Debian repository.

Fixes: #1702
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information...
jviotti committed Aug 1, 2017
1 parent fc358f6 commit 0911abbe9e4a75b995e7c44866066b3e6bc65304
@@ -88,6 +88,8 @@ Bintray options.
* <a name="BintrayOptions-package"></a>`package` String - The Bintray package name.
* <a name="BintrayOptions-repo"></a>`repo` = `generic` String - The Bintray repository name.
* <a name="BintrayOptions-owner"></a>`owner` String - The owner.
* <a name="BintrayOptions-distribution"></a>`distribution` = `stable` String - The Bintray distribution (Debian only).
* <a name="BintrayOptions-component"></a>`component` String - The Bintray component (Debian only).
* <a name="BintrayOptions-user"></a>`user` String - The Bintray user account. Used in cases where the owner is an organization.
* <a name="BintrayOptions-token"></a>`token` String
* <a name="BintrayOptions-provider"></a>**`provider`** "github" | "bintray" | "s3" | "generic" - The provider.
@@ -23,6 +23,8 @@ export class BintrayClient {

readonly owner: string
readonly user: string
readonly component: string | null
readonly distribution: string | null
readonly packageName: string

private requestHeaders: RequestHeaders | null
@@ -43,6 +45,8 @@ export class BintrayClient {
this.packageName = options.package
this.owner = options.owner
this.user = options.user || options.owner
this.component = options.component || null
this.distribution = options.distribution || "stable"
this.auth = apiKey == null ? null : `Basic ${new Buffer(`${this.user}:${apiKey}`).toString("base64")}`
this.basePath = `/packages/${this.owner}/${this.repo}/${this.packageName}`
}
@@ -179,6 +179,16 @@ export interface BintrayOptions extends PublishConfiguration {
*/
readonly owner?: string | null

/**
* The Debian component.
*/
readonly component?: string | null

/**
* The Debian distribution.
*/
readonly distribution?: string | null

/**
* The Bintray user account. Used in cases where the owner is an organization.
*/
@@ -4,7 +4,7 @@ import { BintrayClient, Version } from "electron-builder-http/out/bintray"
import { BintrayOptions } from "electron-builder-http/out/publishOptions"
import { debug, isEmptyOrSpaces, isTokenCharValid, log } from "electron-builder-util"
import { httpExecutor } from "electron-builder-util/out/nodeHttpExecutor"
import { ClientRequest } from "http"
import { ClientRequest, RequestOptions } from "http"
import { HttpPublisher, PublishContext, PublishOptions } from "./publisher"

export class BintrayPublisher extends HttpPublisher {
@@ -62,19 +62,32 @@ export class BintrayPublisher extends HttpPublisher {
}

let attemptNumber = 0

const options: RequestOptions = {
hostname: "api.bintray.com",
path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${version.name}/${fileName}`,
method: "PUT",
headers: {
"Content-Length": dataLength,
"X-Bintray-Override": "1",
"X-Bintray-Publish": "1",
"X-Bintray-Debian-Architecture": arch
}
}

if (this.client.distribution) {
options.headers = options.headers || {}
options.headers["X-Bintray-Debian-Distribution"] = this.client.distribution
}

if (this.client.component) {
options.headers = options.headers || {}
options.headers["X-Bintray-Debian-Component"] = this.client.component
}

for (let i = 0; i < 3; i++) {
try {
return await httpExecutor.doApiRequest<any>(configureRequestOptions({
hostname: "api.bintray.com",
path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${version.name}/${fileName}`,
method: "PUT",
headers: {
"Content-Length": dataLength,
"X-Bintray-Override": "1",
"X-Bintray-Publish": "1",
"X-Bintray-Debian-Architecture": arch
}
}, this.client.auth), this.context.cancellationToken, requestProcessor)
return await httpExecutor.doApiRequest<any>(configureRequestOptions(options, this.client.auth), this.context.cancellationToken, requestProcessor)
}
catch (e) {
if (attemptNumber++ < 3 && ((e instanceof HttpError && e.response.statusCode === 502) || e.code === "EPIPE")) {

0 comments on commit 0911abb

Please sign in to comment.
You can’t perform that action at this time.