-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from garethjevans/fix-changelog-for-submodules
Fix changelog generation when querying submodules
- Loading branch information
Showing
3 changed files
with
46 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package util | ||
|
||
import "strings" | ||
|
||
var Runner CommandRunner | ||
|
||
func GetShaOfSubmoduleAtCommit(commit string) (string, error) { | ||
cmd := Command{Name: "git", Args: []string{"ls-tree", commit, "../app-autoscaler"}} | ||
if Runner == nil { | ||
Runner = DefaultCommandRunner{} | ||
} | ||
output, err := Runner.RunWithoutRetry(&cmd) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
parts := strings.Split(output, " ") | ||
return strings.Split(parts[2], "\t")[0], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package util_test | ||
|
||
import ( | ||
"changelog/util" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetShaOfSubmoduleAtCommit(t *testing.T) { | ||
util.Runner = &FakeCommandRunner{} | ||
sha, err := util.GetShaOfSubmoduleAtCommit("HEAD") | ||
assert.NoError(t, err) | ||
assert.Equal(t, sha, "e57e6dccf303e621ec4239b5d97aeba168a6de50") | ||
} | ||
|
||
type FakeCommandRunner struct { | ||
} | ||
|
||
// RunWithoutRetry Execute the command without retrying on failure and block waiting for return values. | ||
func (d FakeCommandRunner) RunWithoutRetry(c *util.Command) (string, error) { | ||
return "160000 commit e57e6dccf303e621ec4239b5d97aeba168a6de50\t../app-autoscaler", nil | ||
} |