Skip to content

Commit

Permalink
feat(publisher): Check that tag name starts with "v" #340
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 26, 2016
1 parent 65650ea commit bb71621
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ export class GitHubPublisher implements Publisher {
return this._releasePromise
}

constructor(private owner: string, private repo: string, version: string, private options: PublishOptions, private isPublishOptionGuessed: boolean = false) {
constructor(private owner: string, private repo: string, private version: string, private options: PublishOptions, private isPublishOptionGuessed: boolean = false) {
if (isEmptyOrSpaces(options.githubToken)) {
throw new Error("GitHub Personal Access Token is not specified")
}

this.token = options.githubToken!
this.policy = options.publish!
this.policy = options.publish || "always"

this.tag = "v" + version
if (version.startsWith("v")) {
throw new Error(`Version must not starts with "v": ${version}`)
}

this.tag = `v${version}`
this._releasePromise = <BluebirdPromise<Release>>this.init()
}

Expand All @@ -75,6 +79,9 @@ export class GitHubPublisher implements Publisher {
}
return null
}
else if (release.tag_name === this.version) {
throw new Error(`Tag name must starts with "v": ${release.tag_name}`)
}
}

if (createReleaseIfNotExists) {
Expand Down
2 changes: 1 addition & 1 deletion src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class NsisTarget extends Target {
defines.MUI_HEADERIMAGE_BITMAP = installerHeader
}

const headerIcon = oneClick ? await this.getResource(this.options.installerHeader, "headerIcon.ico") : null
const headerIcon = oneClick ? await this.getResource(this.options.headerIcon, "headerIcon.ico") : null
if (headerIcon != null) {
defines.HEADER_ICO = headerIcon
}
Expand Down
22 changes: 22 additions & 0 deletions test/src/ArtifactPublisherTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ testAndIgnoreApiRate("prerelease", async () => {
}
})

testAndIgnoreApiRate("incorrect tag name", async () => {
const publisher = new GitHubPublisher("actperepo", "ecb2", "5.0", {
githubToken: token,
draft: false,
prerelease: true,
publish: "onTagOrDraft",
})
try {
await publisher.releasePromise
//noinspection ExceptionCaughtLocallyJS
throw new Error("No expected error")
}
catch (e) {
if (e.message !== 'Tag name must starts with "v": 5.0') {
throw e
}
}
finally {
await publisher.deleteRelease()
}
})

testAndIgnoreApiRate("GitHub upload org", async () => {
//noinspection SpellCheckingInspection
const publisher = new GitHubPublisher("builder-gh-test", "darpa", versionNumber(), {
Expand Down

0 comments on commit bb71621

Please sign in to comment.