diff options
author | Franck Cuny <franck@fcuny.net> | 2024-03-20 19:00:15 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2024-03-20 19:03:03 -0700 |
commit | 496ee376a75798f2a1af247e6934138cad0a84e2 (patch) | |
tree | 94528bf55ae2552ee47bd61cf35239c07b092d56 /internal/git | |
parent | chore: update flake (diff) | |
download | world-496ee376a75798f2a1af247e6934138cad0a84e2.tar.gz |
`ghalogs` get the logs of a GHA workflow run
Add a few internal packages to get the root of the git repository and to create clickable links in the terminal.
Diffstat (limited to 'internal/git')
-rw-r--r-- | internal/git/main.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/git/main.go b/internal/git/main.go new file mode 100644 index 0000000..67e7d4d --- /dev/null +++ b/internal/git/main.go @@ -0,0 +1,22 @@ +package git + +import ( + "fmt" + "os/exec" + "strings" +) + +func Root() (string, error) { + cmd := exec.Command("git", "rev-parse", "--show-toplevel") + output, err := cmd.Output() + if err != nil { + return "", fmt.Errorf("failed to get git repository: %s", err) + } + + // The output includes the full path to the repository. To get just the name, + // we can split the path by "/" and take the last part. + pathParts := strings.Split(strings.TrimSpace(string(output)), "/") + repoName := pathParts[len(pathParts)-1] + + return repoName, nil +} |