Skip to content

Commit 68f2650

Browse files
committed
Clone repo and create gist
1 parent bc7ae65 commit 68f2650

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor
22
/deployer
3+
/.*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Deployer
22

3-
1. Listen to GitHub deployment
3+
1. Listen to new GitHub deployments
44
2. Create pending GitHub deployment status
55
3. Deploy application to locally installed dokku
66
4. Create success/failure Github deployment status

main.go

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "fmt"
44
import "flag"
55
import "context"
66
import "os"
7+
import "os/exec"
78
import "time"
89
import "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-
6196
func 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

Comments
 (0)