Skip to content

Commit

Permalink
fix(bintray): do not require explicit publish=always (regression) #529
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Oct 17, 2016
1 parent 9dbb724 commit 6f20e8d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
8 changes: 7 additions & 1 deletion .idea/runConfigurations/ArtifactPublisherTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ function publishManager(packager: Packager, publishTasks: Array<BluebirdPromise<
})
}

export async function createPublisher(packager: Packager, publishConfig: PublishConfiguration | GithubOptions | BintrayOptions, options?: PublishOptions, isPublishOptionGuessed: boolean = false): Promise<Publisher | null> {
// visible only for tests
// call only from this file or from tests
export async function createPublisher(packager: Packager, publishConfig: PublishConfiguration | GithubOptions | BintrayOptions, options: PublishOptions, isPublishOptionGuessed: boolean = false): Promise<Publisher | null> {
const config = await getResolvedPublishConfig(packager, publishConfig, isPublishOptionGuessed)
if (config == null) {
return null
Expand All @@ -287,7 +289,7 @@ export async function createPublisher(packager: Packager, publishConfig: Publish
if (publishConfig.provider === "github") {
const githubInfo: GithubOptions = config
log(`Creating Github Publisher — owner: ${githubInfo.owner}, project: ${githubInfo.repo}, version: ${version}`)
return new GitHubPublisher(githubInfo, version, options, isPublishOptionGuessed, githubInfo)
return new GitHubPublisher(githubInfo, version, options, isPublishOptionGuessed)
}
if (publishConfig.provider === "bintray") {
const bintrayInfo: BintrayOptions = config
Expand Down
4 changes: 2 additions & 2 deletions src/publish/BintrayPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class BintrayPublisher implements Publisher {

private readonly client: BintrayClient

constructor(private info: BintrayOptions, private version: string, private options?: PublishOptions) {
constructor(private readonly info: BintrayOptions, private readonly version: string, private readonly options: PublishOptions = {}) {
let token = info.token
if (isEmptyOrSpaces(token)) {
token = process.env.BT_TOKEN
Expand All @@ -36,7 +36,7 @@ export class BintrayPublisher implements Publisher {
}
catch (e) {
if (e instanceof HttpError && e.response.statusCode === 404) {
if (this.options != null && this.options.publish !== "onTagOrDraft") {
if (this.options.publish !== "onTagOrDraft") {
log(`Version ${this.version} doesn't exist, creating one`)
return this.client.createVersion(this.version)
}
Expand Down
6 changes: 2 additions & 4 deletions src/publish/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ export class GitHubPublisher implements Publisher {
private readonly token: string
private readonly policy: PublishPolicy

private readonly options: PublishOptions

get releasePromise(): Promise<Release | null> {
return this._releasePromise
}

constructor(private info: GithubOptions, private version: string, options?: PublishOptions, private isPublishOptionGuessed: boolean = false, config?: GithubOptions | null) {
constructor(private readonly info: GithubOptions, private readonly version: string, private readonly options: PublishOptions = {}, private readonly isPublishOptionGuessed: boolean = false) {
let token = info.token
if (isEmptyOrSpaces(token)) {
token = process.env.GH_TOKEN
Expand All @@ -58,7 +56,7 @@ export class GitHubPublisher implements Publisher {
throw new Error(`Version must not starts with "v": ${version}`)
}

this.tag = config != null && config.vPrefixedTagName === false ? version : `v${version}`
this.tag = info.vPrefixedTagName === false ? version : `v${version}`
this._releasePromise = this.token === "__test__" ? BluebirdPromise.resolve(<any>null) : <BluebirdPromise<Release>>this.init()
}

Expand Down
13 changes: 9 additions & 4 deletions test/src/ArtifactPublisherTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@ test("create publisher", async () => {
repository: "develar/test"
},
}
const publisher = await createPublisher(packager, {provider: "github", vPrefixedTagName: false, token: token})
const publisher = await createPublisher(packager, {provider: "github", vPrefixedTagName: false, token: "__test__"}, {})

assertThat(publisher).hasProperties({
"owner": "develar",
"repo": "test",
"token": "__test__",
info: {
provider: "github",
vPrefixedTagName: false,
owner: "develar",
repo: "test",
token: "__test__",
},
token: "__test__",
"version": "2.0.0",
"tag": "2.0.0",
})
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function runTests(): BluebirdPromise<any> {
args.push("test/out/*.js", "!test/out/macPackagerTest.js", "!test/out/linuxPackagerTest.js", "!test/out/CodeSignTest.js", "!test/out/ArtifactPublisherTest.js", "!test/out/httpRequestTest.js")
}
else if (!util.isCi()) {
args.push("test/out/*.js", "!test/out/ArtifactPublisherTest.js", "!test/out/httpRequestTest.js")
args.push("test/out/*.js", "!test/out/httpRequestTest.js")
}

return utilSpawn(path.join(rootDir, "node_modules", ".bin", "ava"), args, {
Expand Down

0 comments on commit 6f20e8d

Please sign in to comment.