Documentation
¶
Index ¶
- func AddHeader(filePath string, header string) error
- func AddLicenseFile(dirPath string, spdxID string) (string, error)
- func EnsureCorrectName(filePath string) (string, error)
- func FindLicenseFiles(dirPath string) ([]string, error)
- func GetRepoFirstCommitYear(workingDir string) (int, error)
- func GetRepoLastCommitYear(workingDir string) (int, error)
- func GetRepoRoot(workingDir string) (string, error)
- func HasCopyright(filePath string) (bool, error)
- func HasMatchingCopyright(filePath string, copyrightStatement string, caseSensitive bool) (bool, error)
- func InitializeGitCache(repoRoot string) error
- func NeedsUpdate(filePath string, targetHolder string, configYear int, forceCurrentYear bool) (bool, error)
- func NeedsUpdateWithCache(filePath string, targetHolder string, configYear int, forceCurrentYear bool, ...) (bool, error)
- func UpdateCopyrightHeader(filePath string, targetHolder string, configYear int, forceCurrentYear bool) (bool, error)
- func UpdateCopyrightHeaderWithCache(filePath string, targetHolder string, configYear int, forceCurrentYear bool, ...) (bool, error)
- type CopyrightInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHeader ¶
AddHeader prepends a given string to a file. It will automatically handle newline characters
func AddLicenseFile ¶
AddLicenseFile creates a file named "LICENSE" in the target directory pre-populated with license text based on the SPDX Identifier you supply. Returns the fully qualified path to the license file it created
NOTE: this function will NOT add a copyright statement for you. You must manually call AddHeader() afterward if you wish to have copyright headers
func EnsureCorrectName ¶
EnsureCorrectName fixes a malformed license file name and returns the new (corrected) file path E.g., "license.txt" --> "LICENSE"
func FindLicenseFiles ¶
FindLicenseFiles returns a list of filepaths for licenses in a given directory
func GetRepoFirstCommitYear ¶ added in v0.23.0
GetRepoFirstCommitYear returns the year of the first commit in the repository
func GetRepoLastCommitYear ¶ added in v0.23.0
GetRepoLastCommitYear returns the year of the last commit in the repository
func GetRepoRoot ¶ added in v0.25.0
GetRepoRoot finds the git repository root from a given directory
func HasCopyright ¶
HasCopyright reports whether or not a file contains a copyright statement It makes no promises as to the validity of the copyright statement, however! If you wish to validate the contents of the statement, use hasValidCopyright
func HasMatchingCopyright ¶
func HasMatchingCopyright(filePath string, copyrightStatement string, caseSensitive bool) (bool, error)
HasMatchingCopyright takes an explicit copyright statement and validates that a given file contains that string in the header (first 1k chars)
func InitializeGitCache ¶ added in v0.25.0
func NeedsUpdate ¶ added in v0.23.0
func NeedsUpdate(filePath string, targetHolder string, configYear int, forceCurrentYear bool) (bool, error)
NeedsUpdate checks if a file would be updated without actually modifying it If forceCurrentYear is true, forces end year to current year regardless of git history Returns true if the file has copyrights matching targetHolder that need year updates
func NeedsUpdateWithCache ¶ added in v0.25.0
func NeedsUpdateWithCache(filePath string, targetHolder string, configYear int, forceCurrentYear bool, repoFirstCommitYear int, repoRoot string) (bool, error)
NeedsUpdateWithCache checks if a file would be updated without actually modifying it If forceCurrentYear is true, forces end year to current year regardless of git history repoFirstYear and repoRoot can be provided to avoid repeated git lookups when processing multiple files Returns true if the file has copyrights matching targetHolder that need year updates
func UpdateCopyrightHeader ¶ added in v0.23.0
func UpdateCopyrightHeader(filePath string, targetHolder string, configYear int, forceCurrentYear bool) (bool, error)
UpdateCopyrightHeader updates all copyright headers in a file if needed If forceCurrentYear is true, forces end year to current year regardless of git history Returns true if the file was modified
func UpdateCopyrightHeaderWithCache ¶ added in v0.25.0
func UpdateCopyrightHeaderWithCache(filePath string, targetHolder string, configYear int, forceCurrentYear bool, repoFirstYear int, repoRoot string) (bool, error)
UpdateCopyrightHeaderWithCache updates all copyright headers in a file if needed If forceCurrentYear is true, forces end year to current year regardless of git history repoFirstYear and repoRoot can be provided to avoid repeated git lookups when processing multiple files Returns true if the file was modified
Types ¶
type CopyrightInfo ¶ added in v0.23.0
type CopyrightInfo struct {
LineNumber int
OriginalLine string
Holder string
StartYear int
EndYear int
Prefix string // Comment prefix (e.g., "// ", "# ")
TrailingText string // Any text after the years
PrefixIndex int // Byte index in the line where the comment prefix starts (for inline comments)
}
CopyrightInfo holds parsed copyright information from a file