Skip to content

Commit a6f555f

Browse files
committed
Init
0 parents  commit a6f555f

File tree

8 files changed

+194
-0
lines changed

8 files changed

+194
-0
lines changed

.codegate/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go build codegate.go

.github/workflows/go.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Go CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version: '1.22.3'
25+
26+
- name: Install dependencies
27+
run: go mod tidy
28+
29+
- name: Run Go Vulnerability Scanner
30+
uses: debug-ing/[email protected]
31+
32+
- name: Build project
33+
run: go build codegate.go

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
9+
permissions:
10+
contents: write
11+
12+
13+
jobs:
14+
release:
15+
name: Build and Publish Release
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout Code
20+
uses: actions/checkout@v3
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v4
24+
with:
25+
go-version: 1.23
26+
27+
- name: Cache Go Modules
28+
uses: actions/cache@v3
29+
with:
30+
path: ~/go/pkg/mod
31+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
32+
restore-keys: |
33+
${{ runner.os }}-go-
34+
35+
- name: Install GoReleaser
36+
run: |
37+
curl -sL https://install.goreleaser.com/github-cli.sh | bash
38+
39+
- name: Run GoReleaser
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
run: |
43+
goreleaser release --rm-dist

.goreleaser.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
project_name: codegate
2+
builds:
3+
- main: ./codegate.go
4+
goos:
5+
- linux
6+
- darwin
7+
- windows
8+
goarch:
9+
- amd64
10+
- arm64
11+
release:
12+
github:
13+
owner: debug-ing
14+
name: codegate

codegate.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
7+
"github.com/debug-ing/codegate/internal"
8+
)
9+
10+
func main() {
11+
mode := flag.String("mode", "init", "enter mode")
12+
flag.Parse()
13+
fmt.Println(*mode)
14+
if *mode == "init" {
15+
internal.Initialize()
16+
return
17+
}
18+
if *mode == "run" {
19+
internal.Run()
20+
return
21+
}
22+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/debug-ing/codegate
2+
3+
go 1.22.3

internal/initialize.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package internal
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
)
8+
9+
func Initialize() {
10+
dirName := ".codegate"
11+
err := os.MkdirAll(dirName, os.ModePerm)
12+
if err != nil {
13+
fmt.Printf("Error :", err)
14+
return
15+
}
16+
filePath := dirName + "/pre-commit"
17+
file, err := os.Create(filePath)
18+
defer file.Close()
19+
if err != nil {
20+
fmt.Printf("Error :", err)
21+
return
22+
}
23+
addIgnoredHook()
24+
createPreCommitFile()
25+
addPermission()
26+
fmt.Println("File created successfully")
27+
}
28+
func createPreCommitFile() {
29+
content := `#!/bin/bash
30+
codegate --mode run`
31+
filePath := ".git/hooks/pre-commit"
32+
err := os.WriteFile(filePath, []byte(content), 0755)
33+
if err != nil {
34+
fmt.Printf("Failed to create pre-commit file: %v\n", err)
35+
return
36+
}
37+
}
38+
func addPermission() {
39+
_ = exec.Command("chmod", "+x", ".git/hooks/pre-commit")
40+
}
41+
func addIgnoredHook() {
42+
_ = exec.Command("git", "config", "advice.ignoredHook", "false")
43+
}

internal/run.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package internal
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"os/exec"
8+
)
9+
10+
func Run() {
11+
filePath := ".codegate/pre-commit"
12+
file, err := os.Open(filePath)
13+
if err != nil {
14+
fmt.Printf("Error : %s", err)
15+
return
16+
}
17+
defer file.Close()
18+
scanner := bufio.NewScanner(file)
19+
lineNumber := 1
20+
for scanner.Scan() {
21+
line := scanner.Text()
22+
cmd := exec.Command("bash", "-c", line)
23+
output, err := cmd.CombinedOutput()
24+
if err != nil {
25+
fmt.Printf("Error: %s", err)
26+
continue
27+
}
28+
fmt.Printf("%s", output)
29+
lineNumber++
30+
}
31+
if err := scanner.Err(); err != nil {
32+
fmt.Printf("Error: %s", err)
33+
return
34+
}
35+
}

0 commit comments

Comments
 (0)