| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 |
# you may not use this file except in compliance with the License. |
| 3 |
# You may obtain a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from dataclasses import dataclass |
| 14 |
|
| 15 |
from .loc_loader import LocDict |
| 16 |
from .position import Pos |
| 17 |
|
| 18 |
|
| 19 |
job_contents_keys = { |
| 20 |
# Same as for macros. |
| 21 |
"parameters", |
| 22 |
"properties", |
| 23 |
"builders", |
| 24 |
"wrappers", |
| 25 |
"triggers", |
| 26 |
"publishers", |
| 27 |
"scm", |
| 28 |
"pipeline-scm", |
| 29 |
"reporters", |
| 30 |
# General. |
| 31 |
"description", |
| 32 |
"project-type", |
| 33 |
"folder", |
| 34 |
"node", |
| 35 |
"jdk", |
| 36 |
"actions", |
| 37 |
"disabled", |
| 38 |
"display-name", |
| 39 |
"block-downstream", |
| 40 |
"block-upstream", |
| 41 |
"auth-token", |
| 42 |
"concurrent", |
| 43 |
"workspace", |
| 44 |
"child-workspace", |
| 45 |
"quiet-period", |
| 46 |
"retry-count", |
| 47 |
"logrotate", |
| 48 |
"raw", |
| 49 |
# Builders. |
| 50 |
"prebuilders", |
| 51 |
"postbuilders", |
| 52 |
# HipChat. |
| 53 |
"hipchat", |
| 54 |
# Notificatoins. |
| 55 |
"notifications", |
| 56 |
# project Flow. |
| 57 |
"dsl", |
| 58 |
"needs-workspace", |
| 59 |
"dsl-file", |
| 60 |
# GithubOrganization. |
| 61 |
"prune-dead-branches", |
| 62 |
"days-to-keep", |
| 63 |
"number-to-keep", |
| 64 |
"periodic-folder-trigger", |
| 65 |
"github-org", |
| 66 |
"script-path", |
| 67 |
# Matrix. |
| 68 |
"execution-strategy", |
| 69 |
"yaml-strategy", |
| 70 |
"p4-strategy", |
| 71 |
"axes", |
| 72 |
# Maven. |
| 73 |
"maven", |
| 74 |
"per-module-email", |
| 75 |
# WorkflowMultiBranch. |
| 76 |
"sandbox", |
| 77 |
"script-id", |
| 78 |
"script-path", |
| 79 |
"prune-dead-branches", |
| 80 |
"days-to-keep", |
| 81 |
"number-to-keep", |
| 82 |
"abort-builds", |
| 83 |
"periodic-folder-trigger", |
| 84 |
# Pipeline. |
| 85 |
"dsl", |
| 86 |
"sandbox", |
| 87 |
# project Workflow. |
| 88 |
"dsl", |
| 89 |
"sandbox", |
| 90 |
} |
| 91 |
|
| 92 |
view_contents_keys = { |
| 93 |
# Common. |
| 94 |
"description", |
| 95 |
"filter-executors", |
| 96 |
"filter-queue", |
| 97 |
# All |
| 98 |
# <nothing> |
| 99 |
# List. |
| 100 |
"job-name", |
| 101 |
"job-filters", |
| 102 |
"width", |
| 103 |
"alignment", |
| 104 |
"columns", |
| 105 |
"regex", |
| 106 |
"recurse", |
| 107 |
# Sectioned. |
| 108 |
"sections", |
| 109 |
# SectionedText. |
| 110 |
"width", |
| 111 |
"alignment", |
| 112 |
"text", |
| 113 |
"style", |
| 114 |
# DeliveryPipeline. |
| 115 |
"aggregated-changes-grouping-pattern", |
| 116 |
"allow-abort", |
| 117 |
"allow-manual-triggers", |
| 118 |
"allow-pipeline-start", |
| 119 |
"allow-rebuild", |
| 120 |
"link-relative", |
| 121 |
"link-to-console-log", |
| 122 |
"max-number-of-visible-pipelines", |
| 123 |
"name", |
| 124 |
"no-of-columns", |
| 125 |
"no-of-pipelines", |
| 126 |
"paging-enabled", |
| 127 |
"show-absolute-date-time", |
| 128 |
"show-aggregated-changes", |
| 129 |
"show-aggregated-pipeline", |
| 130 |
"show-avatars", |
| 131 |
"show-changes", |
| 132 |
"show-description", |
| 133 |
"show-promotions", |
| 134 |
"show-static-analysis-results", |
| 135 |
"show-test-results", |
| 136 |
"show-total-build-time", |
| 137 |
"update-interval", |
| 138 |
"sorting", |
| 139 |
"components", |
| 140 |
"regexps", |
| 141 |
# Nested. |
| 142 |
"views", |
| 143 |
"default-view", |
| 144 |
"columns", |
| 145 |
# Pipeline. |
| 146 |
"first-job", |
| 147 |
"name", |
| 148 |
"no-of-displayed-builds", |
| 149 |
"title", |
| 150 |
"link-style", |
| 151 |
"css-Url", |
| 152 |
"latest-job-only", |
| 153 |
"manual-trigger", |
| 154 |
"show-parameters", |
| 155 |
"parameters-in-headers", |
| 156 |
"start-with-parameters", |
| 157 |
"refresh-frequency", |
| 158 |
"definition-header", |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
def split_contents_params(data, contents_keys): |
| 163 |
contents = data.copy_with( |
| 164 |
{key: value for key, value in data.items() if key in contents_keys} |
| 165 |
) |
| 166 |
params = data.copy_with( |
| 167 |
{key: value for key, value in data.items() if key not in contents_keys} |
| 168 |
) |
| 169 |
return (contents, params) |
| 170 |
|
| 171 |
|
| 172 |
@dataclass |
| 173 |
class Defaults: |
| 174 |
name: str |
| 175 |
pos: Pos |
| 176 |
params: dict |
| 177 |
contents: dict # Values that go to job contents. |
| 178 |
|
| 179 |
@classmethod |
| 180 |
def add(cls, config, roots, data, pos): |
| 181 |
d = data.copy() |
| 182 |
name = d.pop_required_loc_string("name") |
| 183 |
contents, params = split_contents_params( |
| 184 |
d, job_contents_keys | view_contents_keys |
| 185 |
) |
| 186 |
defaults = cls(name, pos, params, contents) |
| 187 |
roots.defaults[name] = defaults |
| 188 |
|
| 189 |
@classmethod |
| 190 |
def empty(cls): |
| 191 |
return Defaults("empty", pos=None, params={}, contents={}) |
| 192 |
|
| 193 |
def merged_with_global(self, global_): |
| 194 |
return Defaults( |
| 195 |
name=f"{self.name}-merged-with-global", |
| 196 |
pos=self.pos, |
| 197 |
params=LocDict.merge(global_.params, self.params), |
| 198 |
contents=LocDict.merge(global_.contents, self.contents), |
| 199 |
) |