Skip to content

Commit 6f20e8d

Browse files
committed
fix(bintray): do not require explicit publish=always (regression) #529
1 parent 9dbb724 commit 6f20e8d

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

.idea/runConfigurations/ArtifactPublisherTest.xml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/builder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ function publishManager(packager: Packager, publishTasks: Array<BluebirdPromise<
277277
})
278278
}
279279

280-
export async function createPublisher(packager: Packager, publishConfig: PublishConfiguration | GithubOptions | BintrayOptions, options?: PublishOptions, isPublishOptionGuessed: boolean = false): Promise<Publisher | null> {
280+
// visible only for tests
281+
// call only from this file or from tests
282+
export async function createPublisher(packager: Packager, publishConfig: PublishConfiguration | GithubOptions | BintrayOptions, options: PublishOptions, isPublishOptionGuessed: boolean = false): Promise<Publisher | null> {
281283
const config = await getResolvedPublishConfig(packager, publishConfig, isPublishOptionGuessed)
282284
if (config == null) {
283285
return null
@@ -287,7 +289,7 @@ export async function createPublisher(packager: Packager, publishConfig: Publish
287289
if (publishConfig.provider === "github") {
288290
const githubInfo: GithubOptions = config
289291
log(`Creating Github Publisher — owner: ${githubInfo.owner}, project: ${githubInfo.repo}, version: ${version}`)
290-
return new GitHubPublisher(githubInfo, version, options, isPublishOptionGuessed, githubInfo)
292+
return new GitHubPublisher(githubInfo, version, options, isPublishOptionGuessed)
291293
}
292294
if (publishConfig.provider === "bintray") {
293295
const bintrayInfo: BintrayOptions = config

src/publish/BintrayPublisher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class BintrayPublisher implements Publisher {
1717

1818
private readonly client: BintrayClient
1919

20-
constructor(private info: BintrayOptions, private version: string, private options?: PublishOptions) {
20+
constructor(private readonly info: BintrayOptions, private readonly version: string, private readonly options: PublishOptions = {}) {
2121
let token = info.token
2222
if (isEmptyOrSpaces(token)) {
2323
token = process.env.BT_TOKEN
@@ -36,7 +36,7 @@ export class BintrayPublisher implements Publisher {
3636
}
3737
catch (e) {
3838
if (e instanceof HttpError && e.response.statusCode === 404) {
39-
if (this.options != null && this.options.publish !== "onTagOrDraft") {
39+
if (this.options.publish !== "onTagOrDraft") {
4040
log(`Version ${this.version} doesn't exist, creating one`)
4141
return this.client.createVersion(this.version)
4242
}

src/publish/gitHubPublisher.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ export class GitHubPublisher implements Publisher {
3535
private readonly token: string
3636
private readonly policy: PublishPolicy
3737

38-
private readonly options: PublishOptions
39-
4038
get releasePromise(): Promise<Release | null> {
4139
return this._releasePromise
4240
}
4341

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

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

test/src/ArtifactPublisherTest.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ test("create publisher", async () => {
115115
repository: "develar/test"
116116
},
117117
}
118-
const publisher = await createPublisher(packager, {provider: "github", vPrefixedTagName: false, token: token})
118+
const publisher = await createPublisher(packager, {provider: "github", vPrefixedTagName: false, token: "__test__"}, {})
119119

120120
assertThat(publisher).hasProperties({
121-
"owner": "develar",
122-
"repo": "test",
123-
"token": "__test__",
121+
info: {
122+
provider: "github",
123+
vPrefixedTagName: false,
124+
owner: "develar",
125+
repo: "test",
126+
token: "__test__",
127+
},
128+
token: "__test__",
124129
"version": "2.0.0",
125130
"tag": "2.0.0",
126131
})

test/src/helpers/runTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function runTests(): BluebirdPromise<any> {
168168
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")
169169
}
170170
else if (!util.isCi()) {
171-
args.push("test/out/*.js", "!test/out/ArtifactPublisherTest.js", "!test/out/httpRequestTest.js")
171+
args.push("test/out/*.js", "!test/out/httpRequestTest.js")
172172
}
173173

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

0 commit comments

Comments
 (0)