Skip to content

Commit

Permalink
feat: add command qovery deploy list to show the 10 last commit id
Browse files Browse the repository at this point in the history
feat: add command `qovery deploy <commit id>`
  • Loading branch information
evoxmusic committed Jan 25, 2020
1 parent b6a7b54 commit efd5dc9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var deployCmd = &cobra.Command{
api.Deploy(projectId, BranchName, applicationId, commitId)

fmt.Println("deployment in progress...")
fmt.Println("hint: type \"qovery status --watch\" to track the deployment progress")
fmt.Println("hint: type \"qovery status --watch\" to track the progression of deployment")
},
}

Expand Down
12 changes: 8 additions & 4 deletions cmd/deploy_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/ryanuber/columnize"
"github.com/spf13/cobra"
"github.com/xeonx/timeago"
"os"
"qovery.go/api"
"qovery.go/util"
Expand Down Expand Up @@ -63,11 +64,14 @@ func ShowDeploymentList(projectName string, branchName string, applicationName s
return
}

for _, id := range util.ListCommits(10) {
if environment.CommitId == id {
output = append(output, branchName+" | "+"now"+" | "+id+" | "+"✓")
for _, commit := range util.ListCommits(10) {
config := timeago.English
config.Max = 30 * timeago.Day

if environment.CommitId == commit.ID().String() {
output = append(output, branchName+" | "+config.Format(commit.Committer.When)+" | "+commit.ID().String()+" | "+"✓")
} else {
output = append(output, branchName+" | "+"now"+" | "+id+" | "+"𐄂")
output = append(output, branchName+" | "+config.Format(commit.Committer.When)+" | "+commit.ID().String()+" | "+"𐄂")
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var versionCmd = &cobra.Command{
qovery version`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Qovery version 0.8.1")
fmt.Println("Qovery version 0.9.0")
},
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
github.com/xeonx/timeago v1.0.0-rc4
golang.org/x/sys v0.0.0-20191008105621-543471e840be // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.2.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ github.com/ulikunitz/xz v0.5.6 h1:jGHAfXawEGZQ3blwU5wnWKQJvAraT7Ftq9EXjnXYgt8=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xeonx/timeago v1.0.0-rc4 h1:9rRzv48GlJC0vm+iBpLcWAr8YbETyN9Vij+7h2ammz4=
github.com/xeonx/timeago v1.0.0-rc4/go.mod h1:qDLrYEFynLO7y5Ho7w3GwgtYgpy5UfhcXIIQvMKVDkA=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
29 changes: 20 additions & 9 deletions util/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"sort"
"strings"
)

Expand Down Expand Up @@ -65,27 +67,36 @@ func ListRemoteURLs() []string {
return urls
}

func ListCommits(nLast int) []string {
func ListCommits(nLast int) []*object.Commit {
repo, err := git.PlainOpen(".")
if err != nil {
return []string{}
return []*object.Commit{}
}

c, err := repo.CommitObjects()
if err != nil {
return []string{}
return []*object.Commit{}
}

var commitIds []string
var commits []*object.Commit

_ = c.ForEach(func(commit *object.Commit) error {
commits = append(commits, commit)
return nil
})

sort.Slice(commits, func(i, j int) bool {
return commits[i].Committer.When.Unix() > commits[j].Committer.When.Unix()
})

for i := 0; i < nLast; i++ {
commit, err := c.Next()
if err != nil {
var finalCommits []*object.Commit
for k, commit := range commits {
if k == nLast {
break
}

commitIds = append(commitIds, commit.ID().String())
finalCommits = append(finalCommits, commit)
}

return commitIds
return finalCommits
}

0 comments on commit efd5dc9

Please sign in to comment.