github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/deployment/internal/repodiscovery/tiny/tiny.go (about) 1 package tiny 2 3 import ( 4 "encoding/json" 5 6 "github.com/henvic/wedeploycli/deployment/internal/repodiscovery" 7 ) 8 9 // Info about the deployment. 10 // Copy of deployment.Info struct. 11 type Info struct { 12 CLIVersion string `json:"cliVersion,omitempty"` 13 Time string `json:"time,omitempty"` 14 Deploy bool `json:"deploy,omitempty"` 15 16 Repositories []repodiscovery.Repository `json:"repos,omitempty"` 17 Repoless []string `json:"repoless,omitempty"` 18 19 Metadata json.RawMessage `json:"metadata,omitempty"` 20 } 21 22 // Tiny deployment info. 23 type Tiny struct { 24 Deploy bool `json:"deploy"` 25 26 Commit *commitInfo `json:"commit,omitempty"` 27 28 Metadata json.RawMessage `json:"metadata,omitempty"` 29 } 30 31 type commitInfo struct { 32 SHA string `json:"sha,omitempty"` 33 Repository string `json:"repository,omitempty"` 34 Branch string `json:"branch,omitempty"` 35 Message string `json:"message,omitempty"` 36 AuthorName string `json:"authorName,omitempty"` 37 AuthorEmail string `json:"authorEmail,omitempty"` 38 Date string `json:"date,omitempty"` 39 } 40 41 // Convert deployinfo format to this tiny format. 42 // see https://github.com/wedeploy/nodegit/issues/43#issuecomment-417728174 43 func Convert(i Info) Tiny { 44 var t = Tiny{ 45 Deploy: i.Deploy, 46 Metadata: i.Metadata, 47 } 48 49 convertCommit(i, &t) 50 51 return t 52 } 53 54 func convertCommit(i Info, t *Tiny) { 55 if len(i.Repoless) != 0 || len(i.Repositories) != 1 { 56 return 57 } 58 59 repo := i.Repositories[0] 60 61 t.Commit = &commitInfo{ 62 SHA: repo.Commit, 63 Repository: repo.Origin, 64 Branch: repo.Branch, 65 Message: repo.CommitMessage, 66 AuthorName: repo.CommitAuthor, 67 AuthorEmail: repo.CommitAuthorEmail, 68 Date: repo.CommitDate, 69 } 70 }