Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Ensure release notes file on repository (#21)
Browse files Browse the repository at this point in the history
Description
===========

If a repository does not contain a release notes file
then create it when retrieving fails.

Changes
=======

* ![FIX] ensure release notes file on update
  • Loading branch information
Larusso authored Oct 11, 2017
1 parent 7877b91 commit d405fc3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ class ReleaseNotesUpdateIntegrationSpec extends GithubIntegrationWithDefaultAuth
initialContent = "# 1.0.0 - Test #"
}

def "creates release notes file if it doesn't exist"() {
given: "a repo without a release notes file"

when:
runTasksSuccessfully("customUpdateNotes")

then:
def lastCommit = ++testRepo.listCommits().iterator()
lastCommit.getCommitShortInfo().getMessage() == "Update release notes"

where:
initialContent = "# 1.0.0 - Test #"

}

@Unroll
def "updates release note with message #commitMessageObject value set via #methodName"() {
given: "release notes file on remote repo"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package wooga.gradle.release.tasks

import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.StopActionException
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*
import org.kohsuke.github.GHCommit
import org.kohsuke.github.GHContent
import org.kohsuke.github.GHFileNotFoundException
import wooga.gradle.github.base.AbstractGithubTask

import java.util.concurrent.Callable
Expand Down Expand Up @@ -60,14 +56,25 @@ class UpdateReleaseNotes extends AbstractGithubTask {

@TaskAction
protected update() {
GHCommit lastCommit = ++repository.listCommits().iterator()
GHContent content = repository.getFileContent(project.relativePath(getReleaseNotes()), lastCommit.getSHA1())
logger.debug("update release notes")
def body = getReleaseNotes().text.normalize()
if (content.read().text == body) {
logger.info("no content change in release notes")
throw new StopActionException()
GHCommit lastCommit = ++repository.listCommits().iterator()
String releaseNotesFileName = project.relativePath(getReleaseNotes())
GHContent content
try {
content = repository.getFileContent(releaseNotesFileName, lastCommit.getSHA1())
if (content.read().text == body) {
logger.info("no content change in release notes")
throw new StopActionException()
}
logger.info("update release notes")
content.update(body, getCommitMessage())
}
catch (GHFileNotFoundException error) {
logger.info("release notes file not found")
logger.debug(error.message)
logger.info("create release notes file")
repository.createContent(body, getCommitMessage(), releaseNotesFileName)
}

content.update(body, getCommitMessage())
}
}

0 comments on commit d405fc3

Please sign in to comment.