package workflow import "strings" // Instructions are the layers resolved outside the run: the instance's, then // the task's organisation's. type Instructions struct { Instance string `json:"instance,omitempty"` Organisation string `json:"organisation,omitempty"` } // instructions renders every set layer, broadest first, so a narrower layer // reads as refining the one above it. func (tc *TaskContext) instructions() string { layers := []struct{ name, text string }{ {"Instance", tc.Instructions.Instance}, {"Organisation", tc.Instructions.Organisation}, {"Workflow", tc.workflowInterface().Instructions}, {"Repository", tc.Repo.Instructions}, } var b strings.Builder for _, layer := range layers { text := strings.TrimSpace(layer.text) if text == "" { continue } if b.Len() == 0 { b.WriteString("## Instructions\n") } b.WriteString("\n### " + layer.name + "\n\n" + text + "\n") } return b.String() } // withInstructions puts the instructions ahead of a stage's own rules. func (tc *TaskContext) withInstructions(rules string) string { instructions := tc.instructions() switch { case instructions == "": return rules case rules == "": return instructions } return instructions + "\n" + rules }