Skip to content

Commit 70dc2fe

Browse files
committed
error messages
2 parents 1f71e5f + 68fce04 commit 70dc2fe

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

local/bin/post-commit.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"net/url"
1212
"os"
13+
"time"
1314
)
1415

1516
type Commit struct {
@@ -28,14 +29,21 @@ func main() {
2829

2930
if commit, err := git.GetLastCommit(os.Getenv("PWD")); err == nil {
3031

31-
send(Commit{
32+
err := send(Commit{
3233
Ref: ref,
3334
Commit: commit,
3435
})
36+
37+
if err != nil {
38+
39+
fmt.Println(err)
40+
}
3541
}
3642
}
3743

3844
var client = http.Client{
45+
46+
Timeout: time.Second * 2,
3947
Transport: &http.Transport{
4048
TLSClientConfig: &tls.Config{
4149
InsecureSkipVerify: true,
@@ -63,15 +71,15 @@ func send(commit Commit) error {
6371

6472
if err != nil {
6573

66-
fmt.Printf("Error when sending a commit to Postgres-CI: %v\n", err)
67-
68-
return nil
74+
return fmt.Errorf("Error when sending a commit to Postgres-CI: %v", err)
6975
}
7076

7177
if response.StatusCode != http.StatusOK {
7278

73-
fmt.Printf("Error when sending a commit to Postgres-CI: %v\n", response.Status)
79+
return fmt.Errorf("Error when sending a commit to Postgres-CI: %v", response.Status)
7480
}
7581

82+
fmt.Printf("\nCommit %s was sent to Postgres-CI server (%s://%s)\n\n", commit.ID, _url.Scheme, _url.Host)
83+
7684
return nil
7785
}

server-side/bin/post-receive.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"net/url"
1313
"os"
1414
"strings"
15+
"time"
1516
)
1617

1718
func main() {
@@ -53,11 +54,15 @@ func main() {
5354
}
5455
}
5556

56-
send(push)
57+
if err := send(push); err != nil {
58+
59+
fmt.Println(err)
60+
}
5761
}
5862
}
5963

6064
var client = http.Client{
65+
Timeout: time.Second * 2,
6166
Transport: &http.Transport{
6267
TLSClientConfig: &tls.Config{
6368
InsecureSkipVerify: true,
@@ -85,15 +90,22 @@ func send(push git.Push) error {
8590

8691
if err != nil {
8792

88-
fmt.Printf("Error when sending a push to Postgres-CI: %v\n", err)
89-
90-
return nil
93+
return fmt.Errorf("Error when sending a push to Postgres-CI: %v", err)
9194
}
9295

9396
if response.StatusCode != http.StatusOK {
9497

95-
fmt.Printf("Error when sending a push to Postgres-CI: %s\n", response.Status)
98+
return fmt.Errorf("Error when sending a push to Postgres-CI: %s", response.Status)
99+
}
100+
101+
fmt.Println("\nCommits:")
102+
103+
for _, commit := range push.Commits {
104+
105+
fmt.Printf(" %s %s %s\n", push.Ref, commit.ID, commit.Author.Name)
96106
}
97107

108+
fmt.Printf("\nwas sent to Postgres-CI server (%s://%s)\n\n", _url.Scheme, _url.Host)
109+
98110
return nil
99111
}

0 commit comments

Comments
 (0)