Record Class VcsState

java.lang.Object
java.lang.Record
network.ike.plugin.ws.vcs.VcsState
Record Components:
timestamp - UTC timestamp of the action
machine - short hostname of the machine that performed the action
branch - the branch name at the time of the action
sha - the 8-character short SHA at the time of the action
action - the action performed (e.g., VcsState.Action.COMMIT)

public record VcsState(String timestamp, String machine, String branch, String sha, VcsState.Action action) extends Record
The VCS state file (.ike/vcs-state) records the last VCS action performed in a repository. Written by git hooks and plugin goals, delivered between machines by Syncthing.

Format is a plain properties file — trivial to parse in both bash (grep/cut) and Java (Properties.load).

  • Constructor Details

    • VcsState

      public VcsState(String timestamp, String machine, String branch, String sha, VcsState.Action action)
      Creates an instance of a VcsState record class.
      Parameters:
      timestamp - the value for the timestamp record component
      machine - the value for the machine record component
      branch - the value for the branch record component
      sha - the value for the sha record component
      action - the value for the action record component
  • Method Details

    • readFrom

      public static Optional<VcsState> readFrom(Path dir)
      Read the VCS state file from the given directory.
      Parameters:
      dir - the repository root directory
      Returns:
      the state if the file exists and is readable, empty otherwise
    • writeTo

      public static void writeTo(Path dir, VcsState state) throws IOException
      Write the VCS state file to the given directory.
      Parameters:
      dir - the repository root directory (must contain .ike/)
      state - the state to write
      Throws:
      IOException - if the file cannot be written
    • create

      public static VcsState create(String branch, String sha, VcsState.Action action)
      Create a VcsState with the current timestamp and local hostname.
      Parameters:
      branch - the current branch name
      sha - the current HEAD SHA (8-character short form)
      action - the action being performed
      Returns:
      a new VcsState
    • isIkeManaged

      public static boolean isIkeManaged(Path dir)
      Check whether the .ike/ directory exists in the given path, indicating the repo is IKE-managed.
      Parameters:
      dir - the repository root directory
      Returns:
      true if the repo has an .ike/ directory
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • timestamp

      public String timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component
    • machine

      public String machine()
      Returns the value of the machine record component.
      Returns:
      the value of the machine record component
    • branch

      public String branch()
      Returns the value of the branch record component.
      Returns:
      the value of the branch record component
    • sha

      public String sha()
      Returns the value of the sha record component.
      Returns:
      the value of the sha record component
    • action

      public VcsState.Action action()
      Returns the value of the action record component.
      Returns:
      the value of the action record component