autorest

package
v0.0.0-...-113f7ca Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProfileGeneration = "go generate ./profiles"
	ProfileFormat     = "gofmt -w ./profiles"
)
View Source
const (
	// NormalizedSpecRoot this is the prefix for readme
	NormalizedSpecRoot = "/_/azure-rest-api-specs/"

	// NormalizedSDKRoot this is the prefix for readme
	NormalizedSDKRoot = "/_/azure-sdk-for-go/"

	// MetadataFilename ...
	MetadataFilename = "_meta.json"
)
View Source
const (
	// ChangelogFilename ...
	ChangelogFilename = "CHANGELOG.md"
)

Variables

This section is empty.

Functions

func AdditionalOptions

func AdditionalOptions(arguments []model.Option) []model.Option

AdditionalOptions removes flags that may change over scenarios

func AdditionalOptionsToString

func AdditionalOptionsToString(arguments []model.Option) []string

AdditionalOptionsToString removes flags that may change over scenarios and cast them to strings

func CanIncludeInMinor

func CanIncludeInMinor(r ChangelogResult) bool

func CollectGenerationMetadata

func CollectGenerationMetadata(root string) (map[string]GenerationMetadata, error)

CollectGenerationMetadata iterates every track 1 go sdk package under root, and collect all the GenerationMetadata into a map using the absolute path of the package as keys

func FormatPackage

func FormatPackage(dir string) error

FormatPackage formats the given package using gofmt

func GetAdditionalOptions

func GetAdditionalOptions(metadata GenerationMetadata) model.Options

func GetChangelogForPackage

func GetChangelogForPackage(lhs, rhs *exports.Content) (*model.Changelog, error)

GetChangelogForPackage generates the changelog report with the given two Contents

func GetLinesBetween

func GetLinesBetween(lines []string, versionRange []VersionTitleLine) ([]string, []string, []string)

func IsPreviewPackage

func IsPreviewPackage(pkgName string) bool

func ReadBatchTags

func ReadBatchTags(reader io.Reader) ([]string, error)

ReadBatchTags reads from a io.Reader of readme.go.md, parses the `multiapi` section and produces a slice of tags

func RegenerateProfiles

func RegenerateProfiles(sdkRoot string) error

func ValidateMetadata

func ValidateMetadata(validators []MetadataValidateFunc, tag string, metadata model.Metadata) []error

ValidateMetadata validates the tag and metadata using the given validators

func WriteChangelogFile

func WriteChangelogFile(title string, result ChangelogResult) (string, error)

WriteChangelogFile writes the changelog to the disk

func WriteMetadataFile

func WriteMetadataFile(packagePath string, metadata GenerationMetadata) (string, error)

WriteMetadataFile writes the metadata to the disk

Types

type ChangelogContext

type ChangelogContext interface {
	SDKRoot() string
	RepoContent() map[string]exports.Content
}

ChangelogContext describes all necessary data that would be needed in the processing of changelogs

type ChangelogProcessError

type ChangelogProcessError struct {
	Errors []error
}

ChangelogProcessError describes the errors during the processing

func (*ChangelogProcessError) Error

func (e *ChangelogProcessError) Error() string

Error ...

type ChangelogProcessor

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

ChangelogProcessor processes the metadata and output changelog with the desired format

func NewChangelogProcessorFromContext

func NewChangelogProcessorFromContext(ctx ChangelogContext) *ChangelogProcessor

NewChangelogProcessorFromContext returns a new ChangelogProcessor

func (*ChangelogProcessor) GenerateChangelog

func (p *ChangelogProcessor) GenerateChangelog(packageFullPath, tag string) (*ChangelogResult, error)

GenerateChangelog generates a changelog for one package

func (*ChangelogProcessor) Process

func (p *ChangelogProcessor) Process(metadataMap map[string]model.Metadata) ([]ChangelogResult, error)

Process generates the changelogs using the input metadata map. Please ensure the input metadata map does not contain any package that is not under the sdk root, otherwise this might give weird results.

type ChangelogResult

type ChangelogResult struct {
	Tag             string
	PackageName     string
	PackageFullPath string
	Changelog       model.Changelog
}

ChangelogResult describes the result of the generated changelog for one package

func (ChangelogResult) ToMarkdown

func (r ChangelogResult) ToMarkdown() string

ToMarkdown convert this ChangelogResult to markdown string

func (ChangelogResult) Write

func (r ChangelogResult) Write(writer io.Writer) error

Write writes this ChangelogResult to the specified writer in markdown format

type GenerateContext

type GenerateContext interface {
	SDKRoot() string
	SpecRoot() string
	RepoContent() map[string]exports.Content
}

GenerateContext describes the context that would be used in an autorest generation task

type GenerateError

type GenerateError struct {
	Options model.Options
	Message string
}

GenerateError ...

func (*GenerateError) Error

func (e *GenerateError) Error() string

Error ...

type GenerateInput

type GenerateInput struct {
	// Readme is the relative path of the readme file to the root directory of azure-sdk-for-go
	Readme string
	// Tag is the readme tag to be generated
	Tag string
	// CommitHash is the head commit hash of azure-rest-api-specs
	CommitHash string
	// Options specifies the options that this generation task will be using
	Options model.Options
}

GenerateInput describes the input information for a package generation

type GenerateOptions

type GenerateOptions struct {
	// MetadataOutputRoot specifies the root directory of all the metadata goes.
	// Metadata will be generated to a temp directory if not specified.
	// The metadataOutput directory will not be removed after the generation succeeded
	MetadataOutputRoot string
	// Stderr ...
	Stderr io.Writer
	// Stdout ...
	Stdout io.Writer
	// AutoRestLogPrefix ...
	AutoRestLogPrefix string
	// ChangelogTitle
	ChangelogTitle string
	// Validators ...
	Validators []MetadataValidateFunc
}

GenerateOptions describes the options for a package generation

type GenerateResult

type GenerateResult struct {
	// MetadataOutputRoot stores the metadata output root which is the same as in options, or randomly generated if not specified in options
	MetadataOutputRoot string
	// Metadata is the GenerationMetadata of the generated package
	Metadata GenerationMetadata
	// Package is the changelog information of the generated package
	Package ChangelogResult
}

GenerateResult describes the result of a generation task

func GeneratePackage

func GeneratePackage(ctx GenerateContext, input GenerateInput, options GenerateOptions) (*GenerateResult, error)

GeneratePackage is a wrapper function of the autorest execution task

type GenerationMetadata

type GenerationMetadata struct {
	// AutorestVersion is the version of autorest.core
	AutorestVersion string `json:"autorest,omitempty"`
	// CommitHash is the commit hash of azure-rest-api-specs from which this SDK package is generated
	CommitHash string `json:"commit,omitempty"`
	// Readme is the normalized path of the readme file from which this SDK package is generated. It should be in this pattern: /_/azure-rest-api-specs/{relative_path}
	Readme string `json:"readme,omitempty"`
	// Tag is the tag from which this SDK package is generated
	Tag string `json:"tag,omitempty"`
	// CodeGenVersion is the version of autorest.go using when this package is generated
	CodeGenVersion string `json:"use,omitempty"`
	// RepositoryURL is the URL of the azure-rest-api-specs. This should always be a constant "https://github.com/Azure/azure-rest-api-specs.git"
	RepositoryURL string `json:"repository_url,omitempty"`
	// AutorestCommand is the full command that generates this package
	AutorestCommand string `json:"autorest_command,omitempty"`
	// AdditionalProperties is a map of addition information in this metadata
	AdditionalProperties GenerationMetadataAdditionalProperties `json:"additional_properties,omitempty"`
}

GenerationMetadata contains all the metadata that has been used when generating a track 1 package

func GetGenerationMetadata

func GetGenerationMetadata(pkg track1.Package) (*GenerationMetadata, error)

GetGenerationMetadata gets the GenerationMetadata in one specific package

func (*GenerationMetadata) RelativeReadme

func (meta *GenerationMetadata) RelativeReadme() string

RelativeReadme returns the relative readme path

type GenerationMetadataAdditionalProperties

type GenerationMetadataAdditionalProperties struct {
	AdditionalOptions string `json:"additional_options,omitempty"`
}

GenerationMetadataAdditionalProperties contains all the additional options other than go-sdk-foler, tag, multiapi, use or the readme path

type Generator

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

Generator collects all the related context of an autorest generation

func NewGeneratorFromOptions

func NewGeneratorFromOptions(o model.Options) *Generator

NewGeneratorFromOptions returns a new Generator with the given model.Options

func (*Generator) Arguments

func (g *Generator) Arguments() []model.Option

Arguments returns the arguments which are using in the autorest command ('autorest' itself excluded)

func (*Generator) Generate

func (g *Generator) Generate() error

Generate executes the autorest generation. The error will be of type *GenerateError

func (*Generator) Run

func (g *Generator) Run() error

Run starts and waits the generation

func (*Generator) Start

func (g *Generator) Start() error

Start starts the generation

func (*Generator) StderrPipe

func (g *Generator) StderrPipe() (io.ReadCloser, error)

StderrPipe returns the stderr pipeline of the command

func (*Generator) StdoutPipe

func (g *Generator) StdoutPipe() (io.ReadCloser, error)

StdoutPipe returns the stdout pipeline of the command

func (*Generator) Wait

func (g *Generator) Wait() error

Wait waits for the generation to complete

func (*Generator) WithMetadataOutput

func (g *Generator) WithMetadataOutput(output string) *Generator

WithMetadataOutput appends a `metadata-output-folder` option to the autorest argument list

func (*Generator) WithMultiAPI

func (g *Generator) WithMultiAPI() *Generator

WithMultiAPI appends a multiapi flag to the autorest argument list

func (*Generator) WithOption

func (g *Generator) WithOption(option model.Option) *Generator

WithOption appends an model.Option to the argument list of the autorest generation

func (*Generator) WithReadme

func (g *Generator) WithReadme(readme string) *Generator

WithReadme appends a readme argument

func (*Generator) WithTag

func (g *Generator) WithTag(tag string) *Generator

WithTag appends a tag option to the autorest argument list

type MetadataProcessError

type MetadataProcessError struct {
	MetadataLocation string
	Errors           []error
}

MetadataProcessError ...

func (*MetadataProcessError) Error

func (e *MetadataProcessError) Error() string

Error ...

type MetadataProcessor

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

MetadataProcessor processes the metadata

func NewMetadataProcessorFromLocation

func NewMetadataProcessorFromLocation(metadataOutput string) *MetadataProcessor

NewMetadataProcessorFromLocation creates a new MetadataProcessor using the metadata output folder location

func (MetadataProcessor) Process

func (p MetadataProcessor) Process() (map[string]model.Metadata, error)

Process returns the metadata result: a map from tag to Metadata, and an error if there is anything that could not be processed. the error returned must be of type *MetadataProcessError

type MetadataValidateFunc

type MetadataValidateFunc func(tag string, metadata model.Metadata) error

MetadataValidateFunc is a function that validates a metadata is legal or not

type VersionTitleLine

type VersionTitleLine struct {
	LineNumber int
	Version    string
}

func FindVersionTitles

func FindVersionTitles(lines []string, n int) []VersionTitleLine

type Writer

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

func NewWriterFromFile

func NewWriterFromFile(file string) *Writer

func (*Writer) WithVersion

func (w *Writer) WithVersion(version string) *Writer

func (*Writer) Write

func (w *Writer) Write(r *report.PkgsReport) error

Write writes the new version changelog to the changelog file, also modify the links in the previous version

func (*Writer) WriteReport

func (w *Writer) WriteReport(r *report.PkgsReport) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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