forked from hyperledger-tooling/github-contributors-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (47 loc) · 1.2 KB
/
config.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
package main
import (
"errors"
"fmt"
"os"
"strings"
)
type Config struct {
GitHubToken string
SourceRepo string
Pattern string
TemplateFile string
FileWithPattern string
}
func readConfiguration() (Config, error) {
// Read inputs from ENV
token := getEnvOrDefault("GITHUB_AUTH_TOKEN", "")
repo :=
getEnvOrDefault("GITHUB_REPOSITORY_URL",
"arsulegai/github-contributors-action")
pattern :=
getEnvOrDefault("CONTRIBUTORS_SECTION_PATTERN", "{{PlaceHolder}}")
inputTemplate :=
getEnvOrDefault("INPUT_TEMPLATE_FILE", "templates/minimal.tpl")
outputFile := getEnvOrDefault("FILE_WITH_PATTERN", "README.md")
// Convert input repo to owner/repo form
repoParts := strings.Split(repo, "/")
if len(repoParts) < 2 {
return Config{},
errors.New(
fmt.Sprintf("%s", "Input should have owner and repository at the least. Expected format owner/repo"))
}
return Config{
GitHubToken: token,
SourceRepo: repo,
Pattern: pattern,
TemplateFile: inputTemplate,
FileWithPattern: outputFile,
}, nil
}
func getEnvOrDefault(env, defaultValue string) string {
value, isPresent := os.LookupEnv(env)
if !isPresent {
value = defaultValue
}
return value
}