Skip to content

Commit

Permalink
fix: check for tag using GitHub API before uploading Changelog
Browse files Browse the repository at this point in the history
Closes: #3
  • Loading branch information
tschulte committed Sep 21, 2015
1 parent 07607af commit f15e8fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
package de.gliderpilot.gradle.semanticrelease

import com.github.zafarkhaja.semver.Version
import com.jcabi.github.Coordinates
import com.jcabi.github.Github
import com.jcabi.github.Release
import com.jcabi.github.RtGithub
import com.jcabi.github.*
import groovy.text.SimpleTemplateEngine
import groovy.text.Template
import groovy.transform.Memoized
Expand Down Expand Up @@ -214,7 +211,24 @@ class SemanticReleaseChangeLogService {
if (!github)
return
String tag = tagStrategy.prefixNameWithV ? "v$version.version" : "$version.version"
Release release = github.repos().get(new Coordinates.Simple(mnemo)).releases().create(tag)

Repo repo = github.repos().get(new Coordinates.Simple(mnemo))

// check for the existance of the tag using the api -> #3
long start = System.currentTimeMillis()
while(!tagExists(repo, tag) && System.currentTimeMillis() - start < 60000) {}

Release release = repo.releases().create(tag)
new Release.Smart(release).body(changeLog(commits(Version.valueOf(version.previousVersion)), version).toString())
}

private boolean tagExists(Repo repo, String tag) {
try {
repo.git().references().get("refs/tags/$tag").json()
return true
} catch (Throwable t) {
return false
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.ajoberstar.grgit.Commit
import org.ajoberstar.grgit.Grgit
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Timeout
import spock.lang.Unroll

import javax.json.Json
Expand Down Expand Up @@ -215,19 +216,22 @@ class SemanticReleaseChangeLogServiceSpec extends Specification {
changeLogService.changeLog(commits.collect(asCommit), new ReleaseVersion(previousVersion: '1.0.0', version: '2.0.0', createTag: true)).toString() == expected
}

@Timeout(10)
def "change log is uploaded to GitHub"() {
given:
grgit = Grgit.open()
changeLogService = new SemanticReleaseChangeLogService(grgit, tagStrategy)
changeLogService.github = new MkGithub("tschulte")
changeLogService.github.repos().create(Json.createObjectBuilder().add("name", "gradle-semantic-release-plugin").build())
def coordinates = new Coordinates.Simple("tschulte/gradle-semantic-release-plugin")
changeLogService.github.repos().get(coordinates).git().references().create("refs/tags/v1.0.0", "affe")
changeLogService.changeLog = { List<Commit> commits, ReleaseVersion version ->
"${'changelog'}"
}

when:
changeLogService.createGitHubVersion(new ReleaseVersion(previousVersion: '0.0.0', version: '1.0.0'))
def releases = changeLogService.github.repos().get(new Coordinates.Simple("tschulte/gradle-semantic-release-plugin")).releases()
def releases = changeLogService.github.repos().get(coordinates).releases()
def release = releases.iterate().collect { new Release.Smart(it) }.find {
it.tag() == 'v1.0.0'
}
Expand Down

0 comments on commit f15e8fd

Please sign in to comment.