gitgraph

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gitgraph is mermaid git graph diagram builder.

Ref. https://mermaid.js.org/syntax/gitgraph.html

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchOption

type BranchOption func(*branchConfig)

BranchOption sets branch options.

func WithBranchOrder

func WithBranchOrder(order int) BranchOption

WithBranchOrder sets the branch order. Order must be zero or greater.

type CherryPickOption

type CherryPickOption func(*cherryPickConfig)

CherryPickOption sets cherry-pick options.

func WithCherryPickParent

func WithCherryPickParent(parentID string) CherryPickOption

WithCherryPickParent sets the cherry-pick parent commit id.

type CommitOption

type CommitOption func(*commitConfig)

CommitOption sets commit options.

func WithCommitID

func WithCommitID(id string) CommitOption

WithCommitID sets the commit id.

func WithCommitTag

func WithCommitTag(tag string) CommitOption

WithCommitTag sets the commit tag.

func WithCommitType

func WithCommitType(cType CommitType) CommitOption

WithCommitType sets the commit type.

type CommitType

type CommitType string

CommitType is the commit style in git graph.

const (
	// CommitTypeNormal is default commit style.
	CommitTypeNormal CommitType = "NORMAL"
	// CommitTypeReverse is reverse commit style.
	CommitTypeReverse CommitType = "REVERSE"
	// CommitTypeHighlight is highlight commit style.
	CommitTypeHighlight CommitType = "HIGHLIGHT"
)

type Diagram

type Diagram struct {
	// contains filtered or unexported fields
}

Diagram is a git graph diagram builder.

Example

ExampleDiagram skips this test on Windows. The newline codes in the comment section where the expected values are written are represented as '\n', causing failures when testing on Windows.

package main

import (
	"io"
	"os"

	md "github.com/nao1215/markdown"
	"github.com/nao1215/markdown/mermaid/gitgraph"
)

func main() {
	diagram := gitgraph.NewDiagram(
		io.Discard,
		gitgraph.WithTitle("Release Flow"),
	).
		Commit(gitgraph.WithCommitID("init"), gitgraph.WithCommitTag("v0.1.0")).
		Branch("develop").
		Checkout("develop").
		Commit(gitgraph.WithCommitType(gitgraph.CommitTypeHighlight)).
		Checkout("main").
		Merge("develop", gitgraph.WithCommitTag("v1.0.0")).
		String()

	_ = md.NewMarkdown(os.Stdout).
		H2("Git Graph").
		CodeBlocks(md.SyntaxHighlightMermaid, diagram).
		Build()

}
Output:
## Git Graph
```mermaid
---
title: Release Flow
---
gitGraph
    commit id: "init" tag: "v0.1.0"
    branch develop
    checkout develop
    commit type: HIGHLIGHT
    checkout main
    merge develop tag: "v1.0.0"
```

func NewDiagram

func NewDiagram(w io.Writer, opts ...Option) *Diagram

NewDiagram returns a new Diagram.

func (*Diagram) Branch

func (d *Diagram) Branch(name string, opts ...BranchOption) *Diagram

Branch adds a branch command to the git graph.

func (*Diagram) Build

func (d *Diagram) Build() error

Build writes the git graph diagram body to the output destination.

func (*Diagram) Checkout

func (d *Diagram) Checkout(name string) *Diagram

Checkout adds a checkout command to the git graph.

func (*Diagram) CherryPick

func (d *Diagram) CherryPick(id string, opts ...CherryPickOption) *Diagram

CherryPick adds a cherry-pick command to the git graph.

func (*Diagram) Commit

func (d *Diagram) Commit(opts ...CommitOption) *Diagram

Commit adds a commit command to the git graph.

func (*Diagram) Error

func (d *Diagram) Error() error

Error returns the error that occurred during the git graph diagram building.

func (*Diagram) LF

func (d *Diagram) LF() *Diagram

LF adds a line feed to the git graph.

func (*Diagram) Merge

func (d *Diagram) Merge(branch string, opts ...CommitOption) *Diagram

Merge adds a merge command to the git graph.

func (*Diagram) Reset

func (d *Diagram) Reset(id string) *Diagram

Reset adds a reset command to the git graph.

func (*Diagram) String

func (d *Diagram) String() string

String returns the git graph diagram body.

type Option

type Option func(*config)

Option sets the options for the Diagram struct.

func WithTitle

func WithTitle(title string) Option

WithTitle sets the title configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL