GitModule (LowEndInsight v0.13.1)

Copy Markdown View Source

Collections of functions for interacting with the git command to perform queries.

Summary

Functions

clone_repo/2: clones the repo

get_commit_dates/1: returns a list of unix timestamps representing commit times

get_commits_with_trailers/1: returns a list of maps with author_email and body for all commits. Used for detecting AI co-author trailers.

get_contributions_map/1: returns a map of contributions per git user note: this map is unfiltered, dupes aren't identified

get_contributors_count/1: returns the number of contributors for a given Git repo

get_default_branch/1: returns the default branch of the remote repo

get_last_n_commits/2: returns a list of lines generated from the diff of two commits

get_current_hash/1: returns the hash of the repo's HEAD

get_last_2_delta/1: returns the lines changed, files changed, additions and deletions in the last commit

get_last_commit_date/1: returns the date of the last commit

get_last_contribution_date_by_contributor/1: returns the date of the last author or commit whichever is more recent.

get_last_n_commits/1: returns a list of the short hashes of the last n commits

get_last_substantive_commit_date/2: the date of the most recent commit that says something about the project being maintained (#244).

get_recent_changes/1: returns the percentage of changed lines in the last commit by the total lines in the repo

get_repo/1: gets a repo by path, returns Repository struct

get_tag_and_commit_dates/1: returns a list of lists of unix timestamps representing commit times with each lsit belonging to a different tag

get_total_commit_count/2: returns the count of commits for a provided branch

get_total_lines/1: returns the total lines and files contained in a repo as of the latest commit

Functions

clone_repo(url, tmp_path)

@spec clone_repo(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}

clone_repo/2: clones the repo

delete_repo(repo)

@spec delete_repo(
  atom()
  | %{
      :path =>
        binary()
        | maybe_improper_list(
            binary() | maybe_improper_list(any(), binary() | []) | char(),
            binary() | []
          ),
      optional(any()) => any()
    }
) :: [binary()]

Callback implementation for GitModule.Behaviour.delete_repo/1.

get_clean_contributions_map(repo)

@spec get_clean_contributions_map(Lei.Git.Repository.t()) :: {:ok, list()}

Callback implementation for GitModule.Behaviour.get_clean_contributions_map/1.

get_commit_dates(repo)

@spec get_commit_dates(Lei.Git.Repository.t()) :: {:ok, [non_neg_integer()]}

get_commit_dates/1: returns a list of unix timestamps representing commit times

get_commits_with_trailers(repo)

@spec get_commits_with_trailers(Lei.Git.Repository.t()) :: {:ok, [map()]}

get_commits_with_trailers/1: returns a list of maps with author_email and body for all commits. Used for detecting AI co-author trailers.

get_contributions_map(repo)

@spec get_contributions_map(Lei.Git.Repository.t()) ::
  {:ok, [%{contributions: non_neg_integer(), name: String.t()}]}

get_contributions_map/1: returns a map of contributions per git user note: this map is unfiltered, dupes aren't identified

get_contributor_count(repo)

@spec get_contributor_count(Lei.Git.Repository.t()) :: {:ok, non_neg_integer()}

get_contributors_count/1: returns the number of contributors for a given Git repo

get_contributor_distribution(repo)

@spec get_contributor_distribution(Lei.Git.Repository.t()) ::
  {:ok, map(), non_neg_integer()}

Callback implementation for GitModule.Behaviour.get_contributor_distribution/1.

get_contributors(repo)

@spec get_contributors(Lei.Git.Repository.t()) :: {:ok, [Contributor.t()]}

Callback implementation for GitModule.Behaviour.get_contributors/1.

get_default_branch(repo)

@spec get_default_branch(Lei.Git.Repository.t()) :: {:ok, String.t()}

get_default_branch/1: returns the default branch of the remote repo

get_diff_2_commits(repo, list)

@spec get_diff_2_commits(Lei.Git.Repository.t(), [any()]) :: {:ok, [String.t()]} | []

get_last_n_commits/2: returns a list of lines generated from the diff of two commits

get_functional_contributors(repo)

@spec get_functional_contributors(Lei.Git.Repository.t()) ::
  {:ok, non_neg_integer(), [any()]}

Callback implementation for GitModule.Behaviour.get_functional_contributors/1.

get_hash(repo)

@spec get_hash(Lei.Git.Repository.t()) :: {:ok, String.t()}

get_current_hash/1: returns the hash of the repo's HEAD

get_last_2_delta(repo)

@spec get_last_2_delta(Lei.Git.Repository.t()) ::
  {:ok, non_neg_integer(), non_neg_integer(), non_neg_integer()}

get_last_2_delta/1: returns the lines changed, files changed, additions and deletions in the last commit

get_last_commit_date(repo)

@spec get_last_commit_date(Lei.Git.Repository.t()) :: {:ok, String.t()}

get_last_commit_date/1: returns the date of the last commit

get_last_contribution_date_by_contributor(repo, contributor)

get_last_contribution_date_by_contributor/1: returns the date of the last author or commit whichever is more recent.

get_last_n_commits(repo, n)

@spec get_last_n_commits(Lei.Git.Repository.t(), non_neg_integer()) :: {:ok, [any()]}

get_last_n_commits/1: returns a list of the short hashes of the last n commits

get_last_substantive_commit_date(repo, limit \\ 150)

@spec get_last_substantive_commit_date(Lei.Git.Repository.t(), pos_integer()) ::
  {:ok, String.t(), :found | :window_exhausted} | {:error, :no_commits}

get_last_substantive_commit_date/2: the date of the most recent commit that says something about the project being maintained (#244).

Bots and documentation-only commits reset the plain commit clock without representing any attention, so currency measured from them can report a healthy project that nobody has touched in a year. Lei.CommitSubstance holds the definition; this walks the log newest-first and stops at the first commit that meets it.

Returns {:ok, date, :found}, or {:ok, date, :window_exhausted} when none of the limit most recent commits was substantive. In that case date is the oldest commit examined: the true answer is older still, so the age derived from it is a lower bound. Understating staleness is the safe direction to be wrong in, and it beats inventing a figure we cannot see.

{:error, :no_commits} when the log yields nothing parseable.

get_recent_changes(repo)

@spec get_recent_changes(Lei.Git.Repository.t()) :: {:ok, number(), number()}

get_recent_changes/1: returns the percentage of changed lines in the last commit by the total lines in the repo

get_repo(path)

@spec get_repo(String.t()) :: {:ok, Lei.Git.Repository.t()} | {:error, String.t()}

get_repo/1: gets a repo by path, returns Repository struct

get_repo_size(repo)

@spec get_repo_size(Lei.Git.Repository.t()) :: {:ok, String.t()}

Callback implementation for GitModule.Behaviour.get_repo_size/1.

get_tag_and_commit_dates(repo)

@spec get_tag_and_commit_dates(Lei.Git.Repository.t()) :: {:ok, [[...]]}

get_tag_and_commit_dates/1: returns a list of lists of unix timestamps representing commit times with each lsit belonging to a different tag

get_top10_contributors_map(repo)

@spec get_top10_contributors_map(Lei.Git.Repository.t()) :: {:ok, [any()]}
get_top10_contributors_map/1: Gets the top 10 contributors and returns it
as a list of contributors with the commits list stripped from the map.

get_total_commit_count(repo)

get_total_commit_count/2: returns the count of commits for a provided branch

get_total_lines(repo)

@spec get_total_lines(Lei.Git.Repository.t()) ::
  {:ok, non_neg_integer(), non_neg_integer()}

get_total_lines/1: returns the total lines and files contained in a repo as of the latest commit