Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/.ghctl_cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.16"
go-version: "1.25.6"
- name: Build for multiple architectures
run: |
GOOS=darwin GOARCH=amd64 go build -o artifacts/${PROJECT_REPONAME}_darwin_amd64
Expand All @@ -26,7 +26,6 @@ jobs:
uses: actions/checkout@v4
with:
repository: mikefarah/yq
ref: v4.13.3
path: yq
- name: Build yq for alpine image
run: |
Expand All @@ -45,6 +44,6 @@ jobs:
run: ls -lah artifacts/
- name: Publish Release on GitHub
run: |
go get github.com/tcnksm/ghr@v0.14.0
go install github.com/tcnksm/ghr@latest
VERSION=v$(./artifacts/${PROJECT_REPONAME}_linux_amd64 --version)
ghr -t ${{ secrets.GITHUB_TOKEN }} -u ${GITHUB_ACTOR} -r ${PROJECT_REPONAME} -c ${{ github.sha }} -n ${VERSION} -delete ${VERSION} ./artifacts/
2 changes: 1 addition & 1 deletion .github/workflows/.ghctl_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Go environment
uses: actions/setup-go@v5
with:
go-version: "1.16"
go-version: "1.25.6"
- name: Build
run: go build
- name: "Vet: report likely mistakes in packages"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## v0.6.4 (2026-02-03)

- Update go version to 1.25.6, github-go version to v82, go-git version to v5.16.4, go-arg version to v1.6.1
- Improvement for Github Enterprise Server. Accept GitHub Enterprise Server host via `GITHUB_HOST` environment variable instead of --enterprise flag. If empty, will works on GitHub Cloud

## v0.6.3 (2026-02-02)

- Migrate to GitHub Actions
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You can download the binary built for your architecture from [the latest release
The following is an example of installation on macOS:

```console
$ curl https://github.com/amirashad/ghctl/releases/download/v0.6.3/ghctl_darwin_amd64 -L -o /usr/local/bin/ghctl
$ curl https://github.com/amirashad/ghctl/releases/download/v0.6.4/ghctl_darwin_amd64 -L -o /usr/local/bin/ghctl
$ chmod +x /usr/local/bin/ghctl
```

Expand All @@ -47,7 +47,7 @@ $ curl -L "$(curl -Ls https://api.github.com/repos/amirashad/ghctl/releases/late

For Windows OS, you can use following PowerShell command to download binary for AMD64 architecture.
```
Invoke-WebRequest https://github.com/amirashad/ghctl/releases/download/v0.6.3/ghctl_windows_amd64.exe -O ghctl.exe
Invoke-WebRequest https://github.com/amirashad/ghctl/releases/download/v0.6.4/ghctl_windows_amd64.exe -O ghctl.exe
```

</p></details>
Expand Down Expand Up @@ -82,7 +82,7 @@ ghctl currently only manages repositories.

## Usage

1) ghctl to work properly should set environment variable `GITHUB_TOKEN` and `GITHUB_ORG` or specify as command-line argument `--token` and `--org` appropriately.
1) ghctl to work properly should set environment variable `GITHUB_TOKEN`, `GITHUB_ORG` and `GITHUB_HOST` or specify as command-line argument `--token` and `--org` appropriately.

To get more help:
```
Expand Down
10 changes: 3 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package main

import (
"context"
"fmt"

"github.com/google/go-github/v33/github"
"github.com/google/go-github/v82/github"
"golang.org/x/oauth2"
)

Expand All @@ -15,11 +14,8 @@ func createGithubClient(ctx context.Context) *github.Client {
var client *github.Client
var err error

if args.Enterprise {
baseUrl := fmt.Sprintf("%s/api/v3/", args.EnterpriseUrl)
uploadUrl := fmt.Sprintf("%s/api/uploads/", args.EnterpriseUrl)

client, err = github.NewEnterpriseClient(baseUrl, uploadUrl, tc)
if args.Host != "" {
client, err = github.NewClient(tc).WithEnterpriseURLs(args.Host, args.Host)
CheckIfError(err)
} else {
client = github.NewClient(tc)
Expand Down
2 changes: 1 addition & 1 deletion examples/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
executors:
ghctl:
docker:
- image: amirashad/ghctl:0.6.3
- image: amirashad/ghctl:0.6.4

commands:
validate:
Expand Down
21 changes: 6 additions & 15 deletions flag.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package main

import "fmt"

type Args struct {
Token string `arg:"env:GITHUB_TOKEN,required"`
Org string `arg:"env:GITHUB_ORG,required"`
EnterpriseUrl string `arg:"env:ENTERPRISE_URL"`
Enterprise bool `arg:"--enterprise" help:"Is GitHub Enterprise (default: false)" default:"false"`
OutputFormat string `arg:"-o" help:"output format: normal, json" default:"normal"`
Verbose bool `arg:"-v" default:"false"`
Token string `arg:"env:GITHUB_TOKEN,required"`
Org string `arg:"env:GITHUB_ORG,required"`
Host string `arg:"env:GITHUB_HOST"`
OutputFormat string `arg:"-o" help:"output format: normal, json" default:"normal"`
Verbose bool `arg:"-v" default:"false"`

Get *Get `arg:"subcommand:get"`
Create *Create `arg:"subcommand:create"`
Expand All @@ -18,13 +15,7 @@ type Args struct {
}

func (Args) Version() string {
return "0.6.3"
}

func (a *Args) Validate() {
if a.Enterprise && a.EnterpriseUrl == "" {
CheckIfError(fmt.Errorf("ENTERPRISE_URL is required when --enterprise is set"))
}
return "0.6.4"
}

type Get struct {
Expand Down
27 changes: 13 additions & 14 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand All @@ -25,7 +24,7 @@ func createBranch(org string, repo string, branch string, format string) {
}

// Clone the given repository to the memory
repoURL := GenerateRepoURL(org, repo)
repoURL := fmt.Sprintf("%s/%s/%s.git", getGithubHost(), org, repo)
Info("git clone %s", repoURL)
r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: repoURL,
Expand Down Expand Up @@ -69,15 +68,15 @@ func addFile(org, repo, branch, fileFrom, fileTo, commitMessage, gitEmail, forma
Password: args.Token,
}

dir, err := ioutil.TempDir("", repo+"-"+branch)
dir, err := os.MkdirTemp("", repo+"-"+branch)
if err != nil {
log.Fatal(err)
}
fmt.Println(dir)
defer os.RemoveAll(dir)

// Clone the given repository to the memory
repoURL := GenerateRepoURL(org, repo)
repoURL := fmt.Sprintf("%s/%s/%s.git", getGithubHost(), org, repo)
Info("git clone %s", repoURL)
r, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: repoURL,
Expand Down Expand Up @@ -143,29 +142,21 @@ func ensureDirExists(fileName string) {
}

func copyFile(from, to string) {
input, err := ioutil.ReadFile(from)
input, err := os.ReadFile(from)
if err != nil {
fmt.Println(err)
return
}

ensureDirExists(to)
err = ioutil.WriteFile(to, input, 0644)
err = os.WriteFile(to, input, 0644)
if err != nil {
fmt.Println("Error creating", to)
fmt.Println(err)
return
}
}

func GenerateRepoURL(org, repo string) string {
if args.Enterprise {
return fmt.Sprintf("%s/%s/%s.git", args.EnterpriseUrl, org, repo)
}

return fmt.Sprintf("https://github.com/%s/%s.git", org, repo)
}

// CheckIfError should be used to naively panics if an error is not nil.
func CheckIfError(err error) {
if err == nil {
Expand All @@ -175,3 +166,11 @@ func CheckIfError(err error) {
Error(err)
os.Exit(1)
}

// getGithubHost returns GitHub host URL
func getGithubHost() string {
if args.Host != "" {
return args.Host
}
return "https://github.com"
}
8 changes: 4 additions & 4 deletions git_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import "testing"
import "fmt"

func Test_GenerateRepoURL(t *testing.T) {
tests := []struct {
Expand All @@ -12,7 +13,7 @@ func Test_GenerateRepoURL(t *testing.T) {
{
name: "GitHub URL",
args: Args{
Enterprise: false,
Host: "",
},
org: "exampleOrg",
repo: "exampleRepo",
Expand All @@ -21,8 +22,7 @@ func Test_GenerateRepoURL(t *testing.T) {
{
name: "Enterprise URL",
args: Args{
Enterprise: true,
EnterpriseUrl: "https://enterprise.example.com",
Host: "https://enterprise.example.com",
},
org: "exampleOrg",
repo: "exampleRepo",
Expand All @@ -33,7 +33,7 @@ func Test_GenerateRepoURL(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
args = tt.args
got := GenerateRepoURL(tt.org, tt.repo)
got := fmt.Sprintf("%s/%s/%s.git", getGithubHost(), tt.org, tt.repo)
if got != tt.expectedURL {
t.Errorf("generateRepoURL() = %v, want %v", got, tt.expectedURL)
}
Expand Down
37 changes: 29 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
module github.com/amirashad/ghctl

go 1.16
go 1.25.6

require (
github.com/alexflint/go-arg v1.3.0
github.com/go-git/go-git/v5 v5.2.0
github.com/google/go-github/v33 v33.0.0
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93 // indirect
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 // indirect
github.com/alexflint/go-arg v1.6.1
github.com/go-git/go-git/v5 v5.16.4
github.com/google/go-github/v82 v82.0.0
golang.org/x/oauth2 v0.34.0
gopkg.in/yaml.v2 v2.4.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/alexflint/go-scalar v1.2.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sys v0.40.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading