Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show live progress on commit and push #56 #62

Merged
merged 7 commits into from
Mar 12, 2023
Merged
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
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ jobs:
key: go-${{ runner.os }}-${{ hashFiles('go.mod') }}
restore-keys: |
go-${{ runner.os }}-

- name: Create config.priv.go (bash)
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
echo "package config; type IConfigPrivate struct {GithubClient string;EncryptKey string};var Private = IConfigPrivate{GithubClient: \"some\",EncryptKey:\"some\",}" >> ./config/config.priv.go

- name: Create config.priv.go (Windows)
if: runner.os == 'Windows'
run: |
echo "package config; type IConfigPrivate struct {GithubClient string;EncryptKey string};var Private = IConfigPrivate{GithubClient: `"some`",EncryptKey:`"some`",}" | Out-File -FilePath .\config\config.priv.go

- name: Download dependencies
run: go mod download

Expand Down
4 changes: 2 additions & 2 deletions controllers/github/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ func CreatePullRequest(prData NewPullRequest) {
}

loading.Stop()

fmt.Printf("PR created: %s\n", pr.GetHTMLURL())
color.Yellow("\nPull request created\n")
println(pr.GetHTMLURL(), "\n")
}
1 change: 1 addition & 0 deletions pkg/cli/actions/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func addToStage(raw []string) {

func processFiles(raw []string, unstaged []string, list []string) (newList []string, changesMsg string, defaults []string) {
if len(raw) == 0 {
loading.Stop()
println("No changes to commit ✅")
os.Exit(0)
return
Expand Down
17 changes: 7 additions & 10 deletions pkg/git/Commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ import (
)

func _commit(msg string, body string, ctype string, scope string, ticket string) string {
color.Yellow("\nCommiting files\n")
cmd := git_controller.Commit(msg, body, ctype, ticket, scope)
out, outErr, err := shell.Out(cmd)
out, _, err := shell.OutLive(cmd)

if err != nil {
loading.Stop()

if strings.Contains(out, "nothing to commit") {
fmt.Println(out)
fmt.Println("Aborting commit...")
fmt.Println("\nAborting commit...")

os.Exit(1)
} else {
fmt.Println(outErr)
log.Fatal("Commit failed")
}
}
Expand Down Expand Up @@ -62,16 +61,14 @@ func Commit(msg string, body string, ctype string, scope string) {
}

ticket := _checkTicket(git_controller.GetTicketNumber())
out := _commit(msg, body, ctype, scope, ticket)

loading.Stop()
fmt.Println(out)
_commit(msg, body, ctype, scope, ticket)

}

func CommitWithoutTicket(msg string, body string, ctype string, scope string) {
loading.Start("Commiting files ")
out := _commit(msg, body, ctype, scope, "")


loading.Stop()
fmt.Println(out)
_commit(msg, body, ctype, scope, "")
}
14 changes: 4 additions & 10 deletions pkg/git/Publish.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package git

import (
"fmt"
"log"

git_controller "github.com/Minnek-Digital-Studio/cominnek/controllers/git"
"github.com/Minnek-Digital-Studio/cominnek/controllers/loading"
"github.com/Minnek-Digital-Studio/cominnek/pkg/shell"
"github.com/fatih/color"
)

func PushPublish() {
loading.Start("Pushing to remote ")
color.Yellow("\nPushing to remote\n")
currentBranch := git_controller.GetCurrentBranch()
cmd := git_controller.Publish(currentBranch)
_, _, err := shell.OutLive(cmd)

out, errout, err := shell.Out(cmd)
if err != nil {
fmt.Println(out)
fmt.Println(errout)
log.Fatal(errout)
log.Fatal("Error pushing to remote")
}

loading.Stop()
fmt.Println(out)
}
13 changes: 4 additions & 9 deletions pkg/git/Push.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package git

import (
"fmt"
"log"

git_controller "github.com/Minnek-Digital-Studio/cominnek/controllers/git"
"github.com/Minnek-Digital-Studio/cominnek/controllers/loading"
"github.com/Minnek-Digital-Studio/cominnek/pkg/shell"
"github.com/fatih/color"
)

func _push() {
loading.Start("Pushing to remote ")
color.Yellow("\nPushing to remote\n")
cmd := git_controller.Push()
out, errout, err := shell.Out(cmd)
_, _, err := shell.OutLive(cmd)

if err != nil {
fmt.Println(out)
fmt.Println(errout)
log.Fatal(errout)
log.Fatal("Error pushing to remote")
}

loading.Stop()
fmt.Println(out)
}

func Push() {
Expand Down
29 changes: 11 additions & 18 deletions pkg/shell/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package shell

import (
"bufio"
"bytes"
"fmt"
"io"
"log"
"os"
"os/exec"
"runtime"

"github.com/Minnek-Digital-Studio/cominnek/controllers/loading"
"github.com/Minnek-Digital-Studio/cominnek/pkg/events"
)

Expand All @@ -35,28 +35,21 @@ func Out(command string) (string, string, error) {
return stdout.String(), stderr.String(), err
}

func OutLive(command string) {
func OutLive(command string) (string, string, error) {
cmd := exec.Command(shellToUse, "-c", command)

stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Println(err)
}
var stdoutBuf, stderrBuf bytes.Buffer
cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)

err := cmd.Run()
outStr, errStr := stdoutBuf.String(), stderrBuf.String()

err = cmd.Start()
loading.Start("Running command...")
if err != nil {
fmt.Println(err)
}

scanner := bufio.NewScanner(stdout)
loading.Stop()
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
return outStr, errStr, err
}

cmd.Wait()
return outStr, errStr, nil
}

/*Execute a command and return the output*/
Expand Down