Skip to content

Commit 07f03e5

Browse files
committed
output commit hash & message during to execute 'deploy' command
1 parent 13b4a13 commit 07f03e5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/cmd/deploy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ func runDeploy(
6969
}
7070
}
7171
}
72+
// Print CommitHash & CommitMessage
73+
hash, msg, err := repo.GetHeadInfo(ctx)
74+
if err != nil {
75+
return err
76+
}
77+
fmt.Printf("hash: %s\nmessage: %s\n\n", hash, msg)
7278
// Set deployers
7379
deployers, err := newDeployersFunc(logger, template.New(conf.GitRevision), conf.LocalRepoPath, isucontinuous.Hosts)
7480
if err != nil {

pkg/localrepo/localrepo.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type LocalRepoIface interface {
3434
GetRevision(ctx context.Context) (string, error)
3535
SetRevision(ctx context.Context, revision string) error
3636
ClearRevision(ctx context.Context) error
37+
GetHeadInfo(ctx context.Context) (string, string, error)
3738
}
3839

3940
type LocalRepo struct {
@@ -229,3 +230,17 @@ func (l *LocalRepo) SetRevision(ctx context.Context, revision string) error {
229230
func (l *LocalRepo) ClearRevision(ctx context.Context) error {
230231
return os.Remove(filepath.Join(l.absPath, revisionStoreFilename))
231232
}
233+
234+
func (l *LocalRepo) GetHeadInfo(ctx context.Context) (string, string, error) {
235+
stdout, stderr, err := l.shell.Exec(ctx, l.absPath, "git rev-parse HEAD")
236+
if err != nil {
237+
return "", "", myerrors.NewErrorCommandExecutionFailed(stderr)
238+
}
239+
hash := stdout.String()
240+
stdout, stderr, err = l.shell.Exec(ctx, l.absPath, "git log -1 --pretty=%B")
241+
if err != nil {
242+
return "", "", myerrors.NewErrorCommandExecutionFailed(stderr)
243+
}
244+
msg := stdout.String()
245+
return hash, msg, nil
246+
}

0 commit comments

Comments
 (0)