synapsecns/sanguine

View on GitHub
contrib/git-changes-action/detector/git/git.go

Summary

Maintainability
B
4 hrs
Test Coverage

Function getChangeTreeFromGit has 60 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func getChangeTreeFromGit(repoPath string, ghContext *actionscore.Context, head, base string) (tree.Tree, error) {
    // open the repository
    repository, err := git.PlainOpen(repoPath)
    if err != nil {
        return nil, fmt.Errorf("could not open repository %s: %w", repoPath, err)
Severity: Minor
Found in contrib/git-changes-action/detector/git/git.go - About 1 hr to fix

    Function getChangeTreeFromGit has 10 return statements (exceeds 4 allowed).
    Open

    func getChangeTreeFromGit(repoPath string, ghContext *actionscore.Context, head, base string) (tree.Tree, error) {
        // open the repository
        repository, err := git.PlainOpen(repoPath)
        if err != nil {
            return nil, fmt.Errorf("could not open repository %s: %w", repoPath, err)
    Severity: Major
    Found in contrib/git-changes-action/detector/git/git.go - About 1 hr to fix

      Function getChangeTreeFromGit has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
      Open

      func getChangeTreeFromGit(repoPath string, ghContext *actionscore.Context, head, base string) (tree.Tree, error) {
          // open the repository
          repository, err := git.PlainOpen(repoPath)
          if err != nil {
              return nil, fmt.Errorf("could not open repository %s: %w", repoPath, err)
      Severity: Minor
      Found in contrib/git-changes-action/detector/git/git.go - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function convertToSha has 7 return statements (exceeds 4 allowed).
      Open

      func convertToSha(repository *git.Repository, ref string) (res *plumbing.Hash, err error) {
          // already a sha
          _, err = hex.DecodeString(ref)
          if err == nil {
              return core.PtrTo(plumbing.NewHash(ref)), nil
      Severity: Major
      Found in contrib/git-changes-action/detector/git/git.go - About 45 mins to fix

        Function getHeadBase has 5 return statements (exceeds 4 allowed).
        Open

        func getHeadBase(repo *git.Repository) (head string, base string, err error) {
            co, err := repo.Head()
            if err != nil {
                return "", "", fmt.Errorf("could not get head: %w", err)
            }
        Severity: Major
        Found in contrib/git-changes-action/detector/git/git.go - About 35 mins to fix

          There are no issues that match your filters.

          Category
          Status