Presubmit.Query (presubmit v0.2.2)

Copy Markdown View Source

Functions that read facts out of a Presubmit.Commit for use in assertions or directly in tests.

Queries return data; the assertion verbs are built on top of them. Path-level queries work on any file; the Elixir-level ones read the structural diff (Presubmit.Source.Diff) and adapter models (Presubmit.Source.models/2).

The Elixir-level queries also accept :shipped as their pattern: the files the project compiles when it is a dependency (Presubmit.MixFile.shipped_source/1), read from the side of the change each fact comes from. An added function counts when the after tree ships its file, and a removed one when the before tree did.

Summary

Types

A path pattern, or :shipped for the files the project ships (see the moduledoc).

Functions

Paths of files added by the commit.

Lines added by the commit as {path, line_number, text}, for files matching pattern. Line numbers refer to the after tree.

Total lines added across the commit.

Paths in the after tree matching pattern, sorted.

Paths in the before tree matching pattern, sorted.

Whether any function's body changed or any function was added or removed, in files matching pattern.

Changes whose status is one of statuses and whose path matches pattern.

Total lines removed across the commit.

The structural diff of the commit's Elixir source.

Whether path exists in the after tree.

Whether the commit only changes whitespace: no files added, removed, or renamed, and every modified file's non-whitespace bytes are unchanged.

Functions added, removed, and body-changed in files matching pattern. A body change is matched against the function's file after the change.

Functions the commit adds in files matching pattern, public and private.

Functions the commit removes from files matching pattern, public and private.

Whether this change set carries a commit message.

The parsed message, raising Presubmit.NoMessageError if there is none.

Paths of files whose contents changed in place.

Facts for every module the commit adds in files matching pattern.

Modules the commit defines in files matching pattern that did not exist before (renames excluded).

Modules that existed before the commit and do not after (renames excluded).

{old, new} module names for modules the commit renamed.

Whether the commit adds or removes any API function the project ships.

API functions (public, not @doc false) the commit adds to and removes from the code the project ships, as {module, name, arity}.

Paths of files deleted by the commit.

Lines removed by the commit as {path, line_number, text}. Line numbers refer to the before tree and the path is the before path.

{old_path, new_path} pairs for renamed files; pattern matches either side.

The subject line.

Every path the commit touches, matching pattern.

Whether the commit touches any path matching pattern.

Values of the trailer key (case-insensitive).

All trailers as {key, value} pairs.

Elixir files the commit could not parse, with the parser's reason.

Types

pattern()

@type pattern() :: Presubmit.Pattern.t()

source_pattern()

@type source_pattern() :: Presubmit.Pattern.t() | :shipped

A path pattern, or :shipped for the files the project ships (see the moduledoc).

Functions

added(commit, pattern \\ nil)

@spec added(Presubmit.Commit.t(), pattern()) :: [String.t()]

Paths of files added by the commit.

added_lines(commit, pattern \\ nil)

@spec added_lines(Presubmit.Commit.t(), pattern()) :: [
  {String.t(), pos_integer(), String.t()}
]

Lines added by the commit as {path, line_number, text}, for files matching pattern. Line numbers refer to the after tree.

additions(commit)

@spec additions(Presubmit.Commit.t()) :: non_neg_integer()

Total lines added across the commit.

after_paths(commit, pattern \\ nil)

@spec after_paths(Presubmit.Commit.t(), pattern()) :: [String.t()]

Paths in the after tree matching pattern, sorted.

before_paths(commit, pattern \\ nil)

@spec before_paths(Presubmit.Commit.t(), pattern()) :: [String.t()]

Paths in the before tree matching pattern, sorted.

behaviour_changed?(commit, pattern \\ nil)

@spec behaviour_changed?(Presubmit.Commit.t(), source_pattern()) :: boolean()

Whether any function's body changed or any function was added or removed, in files matching pattern.

Docs, specs, attributes, and formatting do not count, which makes this the right trigger for "code changes need test changes".

changes(commit, statuses, pattern \\ nil)

Changes whose status is one of statuses and whose path matches pattern.

deletions(commit)

@spec deletions(Presubmit.Commit.t()) :: non_neg_integer()

Total lines removed across the commit.

elixir_diff(commit)

@spec elixir_diff(Presubmit.Commit.t()) :: Presubmit.Source.Diff.t()

The structural diff of the commit's Elixir source.

exists?(commit, path)

@spec exists?(Presubmit.Commit.t(), String.t()) :: boolean()

Whether path exists in the after tree.

formatting_only?(commit)

@spec formatting_only?(Presubmit.Commit.t()) :: boolean()

Whether the commit only changes whitespace: no files added, removed, or renamed, and every modified file's non-whitespace bytes are unchanged.

function_changes(commit, pattern \\ nil)

Functions added, removed, and body-changed in files matching pattern. A body change is matched against the function's file after the change.

functions_added(commit, pattern \\ nil)

Functions the commit adds in files matching pattern, public and private.

functions_removed(commit, pattern \\ nil)

Functions the commit removes from files matching pattern, public and private.

has_message?(commit)

@spec has_message?(Presubmit.Commit.t()) :: boolean()

Whether this change set carries a commit message.

message!(commit)

@spec message!(Presubmit.Commit.t()) :: Presubmit.Message.t()

The parsed message, raising Presubmit.NoMessageError if there is none.

modified(commit, pattern \\ nil)

@spec modified(Presubmit.Commit.t(), pattern()) :: [String.t()]

Paths of files whose contents changed in place.

module_facts_added(commit, pattern \\ nil)

@spec module_facts_added(Presubmit.Commit.t(), source_pattern()) :: [
  Presubmit.Source.Facts.Module.t()
]

Facts for every module the commit adds in files matching pattern.

modules_added(commit, pattern \\ nil)

@spec modules_added(Presubmit.Commit.t(), source_pattern()) :: [module()]

Modules the commit defines in files matching pattern that did not exist before (renames excluded).

modules_removed(commit, pattern \\ nil)

@spec modules_removed(Presubmit.Commit.t(), source_pattern()) :: [module()]

Modules that existed before the commit and do not after (renames excluded).

modules_renamed(commit)

@spec modules_renamed(Presubmit.Commit.t()) :: [{module(), module()}]

{old, new} module names for modules the commit renamed.

public_api_changed?(commit)

@spec public_api_changed?(Presubmit.Commit.t()) :: boolean()

Whether the commit adds or removes any API function the project ships.

public_api_diff(commit)

@spec public_api_diff(Presubmit.Commit.t()) :: %{
  added: [{module(), atom(), arity()}],
  removed: [{module(), atom(), arity()}]
}

API functions (public, not @doc false) the commit adds to and removes from the code the project ships, as {module, name, arity}.

Only files matching :shipped count (see the moduledoc), so test support and fixtures compiled only under MIX_ENV=test are not public API. A function whose arity set changes shows up as removed at the old arity and added at the new one.

removed(commit, pattern \\ nil)

@spec removed(Presubmit.Commit.t(), pattern()) :: [String.t()]

Paths of files deleted by the commit.

removed_lines(commit, pattern \\ nil)

@spec removed_lines(Presubmit.Commit.t(), pattern()) :: [
  {String.t(), pos_integer(), String.t()}
]

Lines removed by the commit as {path, line_number, text}. Line numbers refer to the before tree and the path is the before path.

renamed(commit, pattern \\ nil)

@spec renamed(Presubmit.Commit.t(), pattern()) :: [{String.t(), String.t()}]

{old_path, new_path} pairs for renamed files; pattern matches either side.

subject(commit)

@spec subject(Presubmit.Commit.t()) :: String.t()

The subject line.

touched(commit, pattern \\ nil)

@spec touched(Presubmit.Commit.t(), pattern()) :: [String.t()]

Every path the commit touches, matching pattern.

Renames contribute both their old and new paths.

touches?(commit, pattern)

@spec touches?(Presubmit.Commit.t(), pattern()) :: boolean()

Whether the commit touches any path matching pattern.

trailer(commit, key)

@spec trailer(Presubmit.Commit.t(), String.t()) :: [String.t()]

Values of the trailer key (case-insensitive).

trailers(commit)

All trailers as {key, value} pairs.

unparsed(commit)

@spec unparsed(Presubmit.Commit.t()) :: [{String.t(), term()}]

Elixir files the commit could not parse, with the parser's reason.