-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: move to internal directory, remove cmd
- Loading branch information
1 parent
4f07657
commit cb955ff
Showing
7 changed files
with
52 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"os" | ||
"time" | ||
|
||
"github.com/alexandear/import-gitlab-commits/cmd" | ||
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 "[email protected]"`) | ||
} | ||
|
||
app, 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 := app.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 := cmd.Execute(logger); err != nil { | ||
if err := Execute(logger); err != nil { | ||
logger.Fatalln("Error:", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters