template

package module
v0.0.0-...-b581e17 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: MIT Imports: 5 Imported by: 0

README

drone-template-lib

library for generating templates in drone plugin developing

Usage

Official Golang Library is used, if you are not familiar with that, please visit https://godoc.org/text/template


import (
 "github.com/f1shl3gs/drone-template"
)

func YourFunction() {
    key, err := template.Execute("the repo name is {{ .Repo.Name }}")
    // handle error
    // do something 
}

functions

  • date: convert unix timestamp to date, timezone(eg: 'Asia/Shanghai') and format is optional
    • timestamp: required, unix second
    • timezone: optional, eg: 'Asia/Shanghai'
    • format: optional, if format specified, timezone become required, empty value equal to "Local"
  • now: generate a date string of now
    • timezone: optional, eg: 'Asia/Shanghai'
    • format: optional, if format specified, timezone become required, empty value equal to "Local"
quote

line break might break json format(https://github.com/drone-plugins/drone-webhook/issues/34), you can fix it by quote which is a built-in function of text/template

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(text string) (string, error)

Types

type Build

type Build struct {
	// msic
	Tag          string `envconfig:"DRONE_TAG"`
	Branch       string `envconfig:"DRONE_BRANCH"`
	SourceBranch string `envconfig:"DRONE_SOURCE_BRANCH"`
	TargetBranch string `envconfig:"DRONE_TARGET_BRANCH"`
	DeployTo     string `envconfig:"DRONE_DEPLOY_TO"`

	// build info
	Link     string `envconfig:"DRONE_BUILD_LINK"`
	Number   string `envconfig:"DRONE_BUILD_NUMBER"`
	Event    string `envconfig:"DRONE_BUILD_EVENT"`
	Status   string `envconfig:"DRONE_BUILD_STATUS"`
	Action   string `envconfig:"DRONE_BUILD_ACTION"`
	Created  int64  `envconfig:"DRONE_BUILD_CREATED"`
	Started  int64  `envconfig:"DRONE_BUILD_STARTED"`
	Finished int64  `envconfig:"DRONE_BUILD_FINISHED"`
}

prefix: DRONE_BUILD

type Commit

type Commit struct {
	Sha          string `envconfig:"DRONE_COMMIT_SHA"`
	Before       string `envconfig:"DRONE_COMMIT_BEFORE"`
	After        string `envconfig:"DRONE_COMMIT_AFTER"`
	Ref          string `envconfig:"DRONE_COMMIT_REF"`
	Branch       string `envconfig:"DRONE_COMMIT_BRANCH"`
	Link         string `envconfig:"DRONE_COMMIT_LINK"`
	Message      string `envconfig:"DRONE_COMMIT_MESSAGE"`
	Author       string `envconfig:"DRONE_COMMIT_AUTHOR"`
	AuthorEmail  string `envconfig:"DRONE_COMMIT_AUTHOR_EMAIL"`
	AuthorAvatar string `envconfig:"DRONE_COMMIT_AUTHOR_AVATAR"`
	AuthorName   string `envconfig:"DRONE_COMMIT_AUTHOR_NAME"`
	BuildLink    string `envconfig:"DRONE_COMMIT_BUILD_LINK"`
}

prefix: DRONE_COMMIT

type Metadata

type Metadata struct {
	Repo
	Build
	Commit
	Stage
	System
}

type Repo

type Repo struct {
	Owner string `envconfig:"DRONE_REPO_OWNER"`
	Name  string `envconfig:"DRONE_REPO_NAME"`
}

prefix: DRONE_REPO

type Runner

type Runner struct {
	Machine  string `envconfig:"DRONE_MACHINE"`
	Host     string `envconfig:"DRONE_RUNNER_HOST"`
	Hostname string `envconfig:"DRONE_RUNNER_HOSTNAME"`
	Platform string `envconfig:"DRONE_RUNNER_PLATFORM"`
}

type Stage

type Stage struct {
	Kind      string   `envconfig:"DRONE_STAGE_KIND"`
	Name      string   `envconfig:"DRONE_STAGE_NAME"`
	Number    int      `envconfig:"DRONE_STAGE_NUMBER"`
	Machine   string   `envconfig:"DRONE_STAGE_MACHINE"`
	OS        string   `envconfig:"DRONE_STAGE_OS"`
	Arch      string   `envconfig:"DRONE_STAGE_ARCH"`
	Variant   string   `envconfig:"DRONE_STAGE_VARIANT"`
	DependsOn []string `envconfig:"DRONE_STAGE_DEPENDS_ON"`
}

prefix: DRONE_STAGE

type System

type System struct {
	Proto    string `envconfig:"DRONE_SYSTEM_PROTO"`
	Host     string `envconfig:"DRONE_SYSTEM_HOST"`
	Hostname string `envconfig:"DRONE_SYSTEM_HOSTNAME"`
	Version  string `envconfig:"DRONE_SYSTEM_VERSION"`
}

prefix: DRONE_SYSTEM

Jump to

Keyboard shortcuts

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