/
ghrelease.go
67 lines (56 loc) · 1.73 KB
/
ghrelease.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
62
63
64
65
66
67
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"os"
"os/exec"
"os/user"
"path"
"code.google.com/p/goauth2/oauth"
flag "github.com/docker/docker/pkg/mflag"
"github.com/google/go-github/github"
)
type Config struct {
AuthToken string `json:"auth_token"`
}
// initialize flags
var (
// Config needs to be initted in init()
ConfigPath *string
ForceCreate = flag.Bool([]string{"f", "-force"}, false, "Replace the asset if it already exists")
AssetName = flag.String([]string{"n", "-name"}, "", "Set the name for the release asset")
Prerelease = flag.Bool([]string{"p", "-prerelease"}, false, "With -create, create as a dev release")
ReleaseName = flag.String([]string{"r", "-release"}, "", "Create the release if it does not exist and set the release name")
Version = flag.Bool([]string{"v", "-version"}, false, "Print the name and version")
)
func init() {
CurrentUser, _ := user.Current()
DefaultConfigPath := path.Join(CurrentUser.HomeDir, ".config/ghrelease/config.json")
ConfigPath = flag.String([]string{"c", "-config"}, DefaultConfigPath, "Set ghrelease config file")
flag.Parse()
}
func LoadConfig(ConfigPath *string) *Config {
var ret Config
ConfigFile, err := ioutil.ReadFile(*ConfigPath)
err = json.Unmarshal(ConfigFile, &ret)
if err != nil {
log.Fatalln(err)
}
return &ret
}
func main() {
GHRConfig := LoadConfig(ConfigPath)
EnvAuthToken := os.Getenv("GHRELEASE_AUTH_TOKEN")
if EnvAuthToken != "" {
GHRConfig.AuthToken = EnvAuthToken
}
if GHRConfig.AuthToken == "" {
log.Println("auth_token is required to upload release assets to GitHub")
}
transport := &oauth.Transport{
Token: &oauth.Token{AccessToken: GHRConfig.AuthToken},
}
client := github.NewClient(transport.Client())
}