-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
61 lines (48 loc) · 1.27 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"errors"
"fmt"
"log"
"net/url"
"os"
"time"
app "github.com/alexandear/import-gitlab-commits/internal"
)
const (
runTimeout = 10 * time.Minute
)
func Execute(logger *log.Logger) error {
token := os.Getenv("GITLAB_TOKEN")
if token == "" {
return errors.New(`empty GITLAB_TOKEN, example "yourgitlabtoken"`)
}
baseURL, err := url.Parse(os.Getenv("GITLAB_BASE_URL"))
if err != nil {
return errors.New(`wrong GITLAB_BASE_URL, example "https://gitlab.com"`)
}
committerName := os.Getenv("COMMITTER_NAME")
if committerName == "" {
return errors.New(`empty COMMITTER_NAME, example "John Doe"`)
}
committerEmail := os.Getenv("COMMITTER_EMAIL")
if committerEmail == "" {
return errors.New(`empty COMMITTER_EMAIL, example "john.doe@example.com"`)
}
application, err := app.New(logger, token, baseURL, committerName, committerEmail)
if err != nil {
return fmt.Errorf("create app: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), runTimeout)
defer cancel()
if err := application.Run(ctx); err != nil {
return fmt.Errorf("app run: %w", err)
}
return nil
}
func main() {
logger := log.New(os.Stdout, "", log.Lshortfile|log.Ltime)
if err := Execute(logger); err != nil {
logger.Fatalln("Error:", err)
}
}