Skip to content

4 Public Methods

DigiLive edited this page Oct 2, 2022 · 2 revisions

GitChangelog

The library contains the following public methods.

__construct($repoPath = null)

Invoked automatically when instantiating. It will pre-fetch all tags of the repository. Specifying the location of the ".git" directory turns off the repository discovery.

addLabel(...$labels)

If you've set a bunch of labels before, and you want to add one or more labels, you can invoke method GitChangeLog::addLabel(...$labels).

Each argument you pass represents a label to be added.
You can do the same by passing an array of labels as an argument if you use the splat operator.

fetchCommitData($force = false): array

Invoke this method to fetch the repository's commit data.

The method returns an array containing the fetched data as follows:

[
    'Tag' => [
        'date'         => 'Tag Date',
        'uniqueTitles' => ['commitTitle1', ...],
        'hashes'       => ['commitHash1', ...]
    ]
]

The first call to this method will fetch the data from the repository and cache it.
Subsequent calls will not overwrite the cached data unless the parameter is set to true.

fetchTags($force = false): array

Invoke this method to fetch all tags from the git repository.

The method returns an array containing the repository's tags where value null represents the HEAD revision of the repository.

The fist call to this method will fetch the data from the repository and cache it.
Subsequent calls will not overwrite the cached data unless the parameter is set to true.

get(bool $append): string

Get the content of the generated changelog.

If the parameter is set to true, the changelog is appended by the content of property GitChangelog::$baseContent.

removeLabel(string ...$labels): void

Remove a label from the filter.

Declare a value as parameter for each label you want to remove.
You can also pass an array of labels, using the splat operator.

E.g. ('label1', 'label2') or (...['label1', 'label2'])

save(string $filePath): void

Save the generated changelog to a file.

When property GitChangelog::$baseContent is set, the content of the saved file consists of the generated changelog, appended by the base content.

setBaseContent(string $content): void

Set base content for the generated changelog.

If the argument resolves to a valid filepath, the contents of this file is used as base content. Otherwise, the argument's value is considered to be the base content.

setFromTag($tag = null): void

Set the oldest git tag to include in the changelog.

Omit or set to null to include the oldest tag into the changelog.

Note: After setting a tag, you should re-fetch the tags from the repository: GitChangelog::fetchTags(true)

setLabels(...$labels): void

Set filter labels.

This method clears the existing labels and adds the parameter values as the new labels.
Declare a value as parameter for each label you want to set.
You can also pass an array of labels, using the splat operator.
E.g. ('label1', 'label2') or (...['label1', 'label2'])

setOptions($name, $value = null): void

A single option can be set by passing the name and value as arguments for this method.

Alternatively, multiple options can be set in a single call by passing an array as the only argument. The array's key-value pairs represent an option name-value pair.

E.g. ['logHeader' => 'My Changelog', 'noChangesMessage' => 'All the same.']

Note: After setting option 'tagOrderBy', you should re-fetch the tags from the repository: GitChangelog::fetchTags(true)

setToTag($tag = null): void

Set the newest git tag to include in the changelog.

Omit the parameter's value or set it to '' or null to include the HEAD revision.

Note: After setting a tag, you should re-fetch the tags from the repository: GitChangelog::fetchTags(true)

Renderers

build(): void

Generate the changelog.

setFormat($type, $format): void

Set the format of the tags or commit titles in the changelog.

Type Default Value Description
tag '## {tag} ({date})' Format of tag strings.
{tag} is replaced by the repository tag.
{date} is replaced by the corresponding tag date.
title '* {title} {hashes}' Format of commit titles.
{title} is replaced by the repository commit title.
{hashes} is replaced by the corresponding commit hashes.

setPattern($type, $pattern): void

Set the pattern of an issue or merge request.

If set, commit titles are searched for the defined patterns and convert these into links.
Patterns are expected to be regular expressions without delimiters.

NOTE: The expression must contain exactly one capturing group which would capture the id of an issue or merge-request. This captured id is formatted into a link if an url is set for it.

Type Default Value Description
issue '/a^/' Regex pattern of an issue string.
mergeRequest '/a^/' Regex pattern of a merge-request string (Also known as pull-request).

To reset the pattern back to its default value, set the value to null.

setUrl($type, $url): void

Set the urls of the webinterface of the provider's repository.

If set, hashes and patterns (see above) found in a commit title, are converted into links.

Type Default Value Description
commit null Url to the commit view of the provider's repository.
If set, hashes of a commit title are converted into links which refer to the corresponding commit.
{commit} is replaced by the hash id of the commit.
issue null Url to the issue-tracker of the provider's repository.
If set, issue references in a commit title are converted into links which refer to the corresponding issue at the tracker.
{issue} is replaced by the issue number.
mergeRequest null Url to the merge-request view (Also known as pull request).
If set, merge-request references in a commit title are converted into links which refer to the corresponding merge-request at the web interface.
{mergeRequest} is replaced by the merge/pull request id.