-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (65 loc) · 2.26 KB
/
main.go
File metadata and controls
82 lines (65 loc) · 2.26 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"context"
"flag"
"fmt"
"os"
"github.com/cli/go-gh/v2/pkg/auth"
"github.com/cli/go-gh/v2/pkg/repository"
"github.com/gofri/go-github-ratelimit/github_ratelimit"
"github.com/google/go-github/v67/github"
"github.com/prefapp/gh-commit/git"
)
func main() {
currentDir, err := os.Getwd()
defaultRepo, err := repository.Current()
repo := flag.String("R", fmt.Sprintf("%s/%s", defaultRepo.Owner, defaultRepo.Name), "Repository to use")
branch := flag.String("b", "main", "Branch to use")
dir := flag.String("d", currentDir, "Directory to use")
message := flag.String("m", "Commit message", "Commit message")
deletePath := flag.String("delete-path", "", "Path in the origin repository to delete files from before adding new ones")
baseBranch := flag.String("base", "", "Base branch name")
createEmptyCommit := flag.Bool( // Setting this to true will force the creation of a commit with no changes
"e", false, "Create empty commit",
)
allowEmptyCommit := flag.Bool( // Setting this to true will upload a new commit to the repo even if no files were changed
"a", false, "Upload commit even if no files were changed",
)
allowEmptyTree := flag.Bool( // Setting this to true will allow uploading commits that result in an empty tree (i.e. deleting all files)
"allow-empty-tree", false, "Upload commits that result in an empty tree",
)
flag.Parse()
if *baseBranch == "" {
*baseBranch, err = git.GetBaseBranch(*dir)
if err != nil {
panic(err)
}
}
if dir == nil && err != nil {
fmt.Println("Error getting current directory:", err)
return
}
host, _ := auth.DefaultHost()
token, _ := auth.TokenForHost(host)
rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(nil)
if err != nil {
panic(err)
}
client := github.NewClient(rateLimiter).WithAuthToken(token)
parsedRepo, err := repository.Parse(*repo)
if err != nil {
panic(err)
}
// upload files
ref, _, err, exitCode := git.UploadToRepo(
context.Background(), client, parsedRepo, *dir,
*deletePath, *branch, *baseBranch, *message,
createEmptyCommit, allowEmptyCommit, allowEmptyTree,
)
if err != nil {
fmt.Println("Error uploading files:", err)
} else {
fmt.Println("Files uploaded to", *repo, "on branch", *branch, "with ref", *ref)
}
os.Exit(exitCode)
}