@@ -4,6 +4,7 @@ import "fmt"
44import "flag"
55import "context"
66import "os"
7+ import "os/exec"
78import "time"
89import "github.com/google/go-github/github"
910
@@ -27,6 +28,17 @@ func main() {
2728
2829 fmt .Println (* username , * password , * org , * repo , * env , * app )
2930
31+ repoPath := "." + * app ;
32+ _ , err := os .Stat (repoPath )
33+ if err != nil {
34+ repoURL := "https://" + * username + ":" + * password + "@github.com/" + * org + "/" + * repo + ".git"
35+ err = cloneRepo (repoURL , repoPath )
36+ if err != nil {
37+ fmt .Printf ("Problem cloning repo %v\n " , err )
38+ os .Exit (1 )
39+ }
40+ }
41+
3042 sleepDuration := time .Duration (* sleepInt ) * time .Second
3143 fmt .Printf ("Sleep duration: %v\n " , sleepDuration )
3244
@@ -38,7 +50,10 @@ func main() {
3850
3951 client := github .NewClient (tp .Client ())
4052
41- opt := & github.DeploymentsListOptions {}
53+ opt := & github.DeploymentsListOptions {
54+ Environment : * env ,
55+ ListOptions : github.ListOptions {PerPage : 1 },
56+ }
4257
4358 for {
4459 deployments , _ , err := client .Repositories .ListDeployments (ctx , * org , * repo , opt )
@@ -49,16 +64,45 @@ func main() {
4964 continue ;
5065 }
5166
52- for _ , deployment := range deployments {
67+ deployment := deployments [0 ]
68+ if deployment != nil {
5369 fmt .Println (* deployment .ID , * deployment .Ref , * deployment .Environment )
54- }
5570
56- sleep (sleepDuration )
71+ fmt .Println ("Gist it" )
72+
73+ title := fmt .Sprintf ("ID: %d, Ref: %s, Environment: %s" , * deployment .ID , * deployment .Ref , * deployment .Environment )
74+ input := & github.Gist {
75+ Description : github .String (title ),
76+ Public : github .Bool (false ),
77+ Files : map [github.GistFilename ]github.GistFile {
78+ "output.txt" : {Content : github .String ("new file content" )},
79+ },
80+ }
81+ gist , _ , err := client .Gists .Create (ctx , input )
82+
83+ if err != nil {
84+ fmt .Printf ("Problem in creating gist %v\n " , err )
85+ sleep (sleepDuration )
86+ continue ;
87+ }
88+
89+ fmt .Println (* gist .HTMLURL )
90+
91+ sleep (sleepDuration )
92+ }
5793 }
5894}
5995
60-
6196func sleep (duration time.Duration ) {
6297 fmt .Printf ("Sleeping %v\n " , duration )
6398 time .Sleep (duration )
6499}
100+
101+ func cloneRepo (repoURL string , repoPath string ) (error ) {
102+ fmt .Println ("Cloning " , repoURL )
103+ cmd := exec .Command ("git" , "clone" , repoURL , repoPath )
104+ cmd .Stdout = os .Stdout
105+ cmd .Stderr = os .Stderr
106+ err := cmd .Run ()
107+ return err
108+ }
0 commit comments