AppRunner: Include commit message in the status
Change-Id: I1c9101df71e004888b0fc38cbc351d77fbcc70bd
diff --git a/apps/app-runner/main.go b/apps/app-runner/main.go
index b9acaa6..96a647e 100644
--- a/apps/app-runner/main.go
+++ b/apps/app-runner/main.go
@@ -35,7 +35,12 @@
Env []string `json:"env"`
}
-func CloneRepositoryBranch(addr, branch, rootDir string, signer ssh.Signer, path string) (string, error) {
+type Commit struct {
+ Hash string `json:"hash"`
+ Message string `json:"message"`
+}
+
+func CloneRepositoryBranch(addr, branch, rootDir string, signer ssh.Signer, path string) (*Commit, error) {
ref := fmt.Sprintf("refs/heads/%s", branch)
opts := &git.CloneOptions{
URL: addr,
@@ -59,15 +64,22 @@
},
}
}
- c, err := git.Clone(memory.NewStorage(), osfs.New(path, osfs.WithBoundOS()), opts)
+ repo, err := git.Clone(memory.NewStorage(), osfs.New(path, osfs.WithBoundOS()), opts)
if err != nil {
- return "", err
+ return nil, err
}
- head, err := c.Head()
+ head, err := repo.Head()
if err != nil {
- return "", err
+ return nil, err
}
- return head.Hash().String(), nil
+ commit, err := repo.CommitObject(head.Hash())
+ if err != nil {
+ return nil, err
+ }
+ return &Commit{
+ Hash: head.Hash().String(),
+ Message: commit.Message,
+ }, nil
}
func main() {
diff --git a/apps/app-runner/server.go b/apps/app-runner/server.go
index 1661731..4174ece 100644
--- a/apps/app-runner/server.go
+++ b/apps/app-runner/server.go
@@ -25,8 +25,7 @@
}
type Status struct {
- RepoOK bool `json:"repoOK"`
- Commit string `json:"commit"`
+ Commit *Commit `json:"commit"`
Commands []CommandStatus `json:"commands"`
}
@@ -122,12 +121,11 @@
commit, err := CloneRepositoryBranch(s.repoAddr, s.branch, s.rootDir, s.signer, newDir)
if err != nil {
s.status = &Status{
- RepoOK: false,
+ Commit: nil,
}
return err
}
s.status = &Status{
- RepoOK: true,
Commit: commit,
Commands: []CommandStatus{},
}