Skip to content

Commit

Permalink
Merge pull request #119 from coro/generate-release-notes
Browse files Browse the repository at this point in the history
Allow release notes for a GitHub release to be autogenerated
  • Loading branch information
Rui Yang authored Aug 25, 2022
2 parents f963eb9 + 8ea5d3d commit 0fadec1
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 14 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Fetches and creates versioned GitHub resources.
body: path/to/body/file
globs:
- paths/to/files/to/upload-*.tgz
generate_release_notes: true
```
To get a specific version of a release:
Expand Down Expand Up @@ -180,6 +181,11 @@ prepended with this string. This is useful for adding v in front of version numb
* `globs`: *Optional.* A list of globs for files that will be uploaded alongside
the created release.

* `generate_release_notes`: *Optional.* Causes GitHub to autogenerate the release notes
when creating a new release, based on the commits since the last release.
If `body` is specified, the body will be pre-pended to the automatically generated
notes. Has no effect when updating an existing release. Defaults to `false`.

## Development

### Prerequisites
Expand All @@ -200,7 +206,7 @@ Run the tests with the following commands for both `alpine` and `ubuntu` images:

```sh
docker build -t github-release-resource -f dockerfiles/alpine/Dockerfile .
docker build -t github-release-resource -f dockerfiles/ubuntu/Dockerfile .
docker build -t github-release-resource -f dockerfiles/ubuntu/Dockerfile --build-arg base_image=ubuntu:latest .
```

### Contributing
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG base_image
ARG builder_image=concourse/golang-builder

FROM ${builder_image} as builder
FROM ${builder_image} AS builder
COPY . $GOPATH/src/github.com/concourse/github-release-resource
ENV CGO_ENABLED 0
WORKDIR $GOPATH/src/github.com/concourse/github-release-resource
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/cppforlife/go-semi-semantic v0.0.0-20160921010311-576b6af77ae4
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github/v39 v39.0.0
github.com/google/go-github/v39 v39.2.0
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
github.com/nxadm/tail v1.4.5 // indirect
github.com/onsi/ginkgo v1.14.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github/v39 v39.0.0 h1:pygGA5ySwxEez1N39GnDauD0PaWWuGgayudyZAc941s=
github.com/google/go-github/v39 v39.0.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
github.com/google/go-github/v39 v39.2.0 h1:rNNM311XtPOz5rDdsJXAp2o8F67X9FnROXTvto3aSnQ=
github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down
15 changes: 9 additions & 6 deletions out_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
prerelease = request.Source.PreRelease
}

generateReleaseNotes := request.Params.GenerateReleaseNotes

release := &github.RepositoryRelease{
Name: github.String(name),
TagName: github.String(tag),
Body: github.String(body),
Draft: github.Bool(draft),
Prerelease: github.Bool(prerelease),
TargetCommitish: github.String(targetCommitish),
Name: github.String(name),
TagName: github.String(tag),
Body: github.String(body),
Draft: github.Bool(draft),
Prerelease: github.Bool(prerelease),
TargetCommitish: github.String(targetCommitish),
GenerateReleaseNotes: github.Bool(generateReleaseNotes),
}

existingReleases, err := c.github.ListReleases()
Expand Down
50 changes: 50 additions & 0 deletions out_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ var _ = Describe("Out Command", func() {
Ω(updatedRelease.TargetCommitish).Should(Equal(github.String("1z22f1")))
})
})

Context("when set to autogenerate release notes", func() {
BeforeEach(func() {
request.Params.GenerateReleaseNotes = true
})
// See https://github.com/google/go-github/issues/2444
It("has no effect on updating the existing release", func() {
_, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())

Ω(githubClient.UpdateReleaseCallCount()).Should(Equal(1))

updatedRelease := githubClient.UpdateReleaseArgsForCall(0)
Ω(*updatedRelease.Name).Should(Equal("v0.3.12"))
Ω(*updatedRelease.Body).Should(Equal("this is a great release"))
Ω(updatedRelease.GenerateReleaseNotes).Should(BeNil())
})
})
})

Context("when the release has not already been created", func() {
Expand Down Expand Up @@ -585,5 +603,37 @@ var _ = Describe("Out Command", func() {
Ω(*release.TagName).Should(Equal("version-0.3.12"))
})
})

Context("with generate_release_notes set to false", func() {
BeforeEach(func() {
request.Params.GenerateReleaseNotes = false
})

It("creates a release on GitHub without autogenerated release notes", func() {
_, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())

Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1))
release := githubClient.CreateReleaseArgsForCall(0)

Ω(release.GenerateReleaseNotes).Should(Equal(github.Bool(false)))
})
})

Context("with generate_release_notes set to true", func() {
BeforeEach(func() {
request.Params.GenerateReleaseNotes = true
})

It("creates a release on GitHub with autogenerated release notes", func() {
_, err := command.Run(sourcesDir, request)
Ω(err).ShouldNot(HaveOccurred())

Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1))
release := githubClient.CreateReleaseArgsForCall(0)

Ω(release.GenerateReleaseNotes).Should(Equal(github.Bool(true)))
})
})
})
})
11 changes: 6 additions & 5 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ type OutRequest struct {
}

type OutParams struct {
NamePath string `json:"name"`
BodyPath string `json:"body"`
TagPath string `json:"tag"`
CommitishPath string `json:"commitish"`
TagPrefix string `json:"tag_prefix"`
NamePath string `json:"name"`
BodyPath string `json:"body"`
TagPath string `json:"tag"`
CommitishPath string `json:"commitish"`
TagPrefix string `json:"tag_prefix"`
GenerateReleaseNotes bool `json:"generate_release_notes"`

Globs []string `json:"globs"`
}
Expand Down

0 comments on commit 0fadec1

Please sign in to comment.