Skip to content

Commit

Permalink
Permit specifying the target commit of a release (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
travisgroth authored May 22, 2020
1 parent 12333c9 commit 41c62a4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions cr/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ func init() {
uploadCmd.Flags().StringP("token", "t", "", "GitHub Auth Token")
uploadCmd.Flags().StringP("git-base-url", "b", "https://api.github.com/", "GitHub Base URL (only needed for private GitHub)")
uploadCmd.Flags().StringP("git-upload-url", "u", "https://uploads.github.com/", "GitHub Upload URL (only needed for private GitHub)")
uploadCmd.Flags().StringP("commit", "c", "", "Target commit for release")
}
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Options struct {
Token string `mapstructure:"token"`
GitBaseURL string `mapstructure:"git-base-url"`
GitUploadURL string `mapstructure:"git-upload-url"`
Commit string `mapstructure:"commit"`
}

func LoadConfiguration(cfgFile string, cmd *cobra.Command, requiredFlags []string) (*Options, error) {
Expand Down
8 changes: 5 additions & 3 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Release struct {
Name string
Description string
Assets []*Asset
Commit string
}

type Asset struct {
Expand Down Expand Up @@ -102,9 +103,10 @@ func (c *Client) GetRelease(ctx context.Context, tag string) (*Release, error) {
// CreateRelease creates a new release object in the GitHub API
func (c *Client) CreateRelease(ctx context.Context, input *Release) error {
req := &github.RepositoryRelease{
Name: &input.Name,
Body: &input.Description,
TagName: &input.Name,
Name: &input.Name,
Body: &input.Description,
TagName: &input.Name,
TargetCommitish: &input.Commit,
}

release, _, err := c.Repositories.CreateRelease(context.TODO(), c.owner, c.repo, req)
Expand Down
1 change: 1 addition & 0 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func (r *Releaser) CreateReleases() error {
Assets: []*github.Asset{
{Path: p},
},
Commit: r.config.Commit,
}
provFile := fmt.Sprintf("%s.prov", p)
if _, err := os.Stat(provFile); err == nil {
Expand Down
14 changes: 13 additions & 1 deletion pkg/releaser/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,28 +209,39 @@ func TestReleaser_CreateReleases(t *testing.T) {
packagePath string
chart string
version string
commit string
error bool
}{
{
"invalid-package-path",
"testdata/does-not-exist",
"test-chart",
"0.1.0",
"",
true,
},
{
"valid-package-path",
"testdata/release-packages",
"test-chart",
"0.1.0",
"",
false,
},
{
"valid-package-path-with-commit",
"testdata/release-packages",
"test-chart",
"0.1.0",
"5e239bd19fbefb9eb0181ecf0c7ef73b8fe2753c",
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fakeGitHub := new(FakeGitHub)
r := &Releaser{
config: &config.Options{PackagePath: tt.packagePath},
config: &config.Options{PackagePath: tt.packagePath, Commit: tt.commit},
github: fakeGitHub,
}
fakeGitHub.On("CreateRelease", mock.Anything, mock.Anything).Return(nil)
Expand All @@ -248,6 +259,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
assert.Equal(t, releaseDescription, fakeGitHub.release.Description)
assert.Len(t, fakeGitHub.release.Assets, 1)
assert.Equal(t, assetPath, fakeGitHub.release.Assets[0].Path)
assert.Equal(t, tt.commit, fakeGitHub.release.Commit)
fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 1)
}
})
Expand Down

0 comments on commit 41c62a4

Please sign in to comment.