Skip to content

Commit

Permalink
Commit via API
Browse files Browse the repository at this point in the history
Co-Authored-By: Robin Breathe <[email protected]>
  • Loading branch information
isometry and isometry authored Dec 4, 2024
1 parent 6d22fac commit 0e77ce6
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package cmd

import (
"fmt"

"github.com/apex/log"
"github.com/go-git/go-git/v5"
"github.com/shurcooL/githubv4"
"github.com/spf13/cobra"
)

var statusCmd = &cobra.Command{
Use: "status [flags]",
Short: "status",
Args: cobra.NoArgs,
RunE: runStatusCmd,
}

func init() {
rootCmd.AddCommand(statusCmd)
}

func runStatusCmd(cmd *cobra.Command, args []string) (err error) {
defer log.Trace("commit").Stop(&err)

if localRepo == nil {
return fmt.Errorf("the commit action is only valid within a repo with GitHub remote")
}

worktree, err := localRepo.Repository.Worktree()
if err != nil {
return err
}

worktreeStatus, err := worktree.Status()
if err != nil {
return err
}

idx, err := localRepo.Repository.Storer.Index()
if err != nil {
return err
}
for _, e := range idx.Entries {
log.Debugf("index entry: %+v (stage: %+v)\n", e, e.Stage)
}

additions := []githubv4.FileAddition{}
deletions := []githubv4.FileDeletion{}

for path, status := range worktreeStatus {
log.Debugf("%c%c %s\n", status.Staging, status.Worktree, path)
switch status.Staging {
case git.Added, git.Modified:
additions = append(additions, githubv4.FileAddition{
Path: githubv4.String(path),
})
}
}

fmt.Printf("additions: %+v\n", additions)
fmt.Printf("deletions: %+v\n", deletions)

// changes := githubv4.FileChanges{
// Additions: &additions
// Deletions: &deletions
// }

// ctx := context.Background()

// client, err := auth.NewTokenClient(ctx)
// if err != nil {
// return err
// }

// owner := viper.GetString("owner")
// repo := viper.GetString("repo")
// branch := viper.GetString("branch")
// message := viper.GetString("message")

// branchRef, _, err := client.Git.GetRef(ctx, owner, repo, fmt.Sprintf("heads/%s", branch))
// if err != nil {
// return err
// }

return nil
}

0 comments on commit 0e77ce6

Please sign in to comment.