• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heathcliff26 / gh-utility / 41232047967

31 Oct 2026 06:59PM UTC coverage: 83.565% (+2.7%) from 80.819%
41232047967

Pull #56

github

web-flow
Merge 2e02faccd into 5d5d2752a
Pull Request #56: refactor: Use flag values directly instead of via get function

25 of 45 new or added lines in 4 files covered. (55.56%)

661 of 791 relevant lines covered (83.57%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/cmd/commit/cmd.go
1
package commit
2

3
import (
4
        "os"
5

6
        "github.com/heathcliff26/gh-utility/pkg/client"
7
        "github.com/heathcliff26/gh-utility/pkg/pullrequest"
8
        "github.com/heathcliff26/gh-utility/pkg/utils"
9
        "github.com/spf13/cobra"
10
)
11

12
const (
13
        repositoryFlag = "repository"
14
        branchFlag     = "branch"
15
        messageFlag    = "message"
16
        endpointFlag   = "endpoint"
17
)
18

19
// Create a new clone command
20
func NewCommand() *cobra.Command {
21
        cmd := &cobra.Command{
1 ✔
22
                Use:   "commit",
1 ✔
23
                Short: "Push a new commit to the given branch using force push",
1 ✔
24
        }
1 ✔
25

26
        path := cmd.Flags().StringP(repositoryFlag, "r", ".", "Path to the git repository")
1 ✔
27

1 ✔
28
        branch := cmd.Flags().StringP(branchFlag, "b", "", "Branch to push to, will be created if it does not exist")
1 ✔
29
        _ = cmd.MarkFlagRequired(branchFlag)
1 ✔
30

1 ✔
31
        message := cmd.Flags().StringP(messageFlag, "m", "", "Commit message")
1 ✔
32
        _ = cmd.MarkFlagRequired(messageFlag)
1 ✔
33

1 ✔
34
        endpoint := cmd.Flags().String(endpointFlag, client.DefaultEndpoint, "GitHub API endpoint")
1 ✔
35

1 ✔
36
        cmd.Run = func(cmd *cobra.Command, _ []string) {
1 ✔
NEW
37
                err := run(cmd, *path, *branch, *message, *endpoint)
×
NEW
38
                if err != nil {
×
NEW
39
                        cmd.PrintErrln(cmd.ErrPrefix(), err)
×
NEW
40
                        os.Exit(1)
×
NEW
41
                }
×
42
        }
43

44
        return cmd
1 ✔
45
}
46

47
func run(cmd *cobra.Command, path, branch, msg, endpoint string) error {
48
        c := client.NewClient(endpoint)
1 ✔
49

1 ✔
50
        tree, commit, err := pullrequest.Commit(c, path, msg, branch, utils.GetToken())
1 ✔
51
        if tree == "" && commit == "" && err == nil {
1 ✔
52
                cmd.Println("No changes detected, exiting")
1 ✔
53
        } else {
1 ✔
54
                cmd.Printf("Tree: %s\nCommit: %s\n", tree, commit)
1 ✔
55
        }
1 ✔
56
        return err
1 ✔
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc