Skip to content

Commit 86296c5

Browse files
dyanmic lua-based pr automations
1 parent 077dbbc commit 86296c5

File tree

16 files changed

+283
-2
lines changed

16 files changed

+283
-2
lines changed

assets/src/generated/graphql.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6635,6 +6635,8 @@ export type PrAutomation = {
66356635
darkIcon?: Maybe<Scalars['String']['output']>;
66366636
deletes?: Maybe<PrDeleteSpec>;
66376637
documentation?: Maybe<Scalars['String']['output']>;
6638+
/** location in git for external templates and scripts */
6639+
git?: Maybe<GitRef>;
66386640
/** an icon url to use for this catalog */
66396641
icon?: Maybe<Scalars['String']['output']>;
66406642
id: Scalars['ID']['output'];
@@ -6643,6 +6645,8 @@ export type PrAutomation = {
66436645
insertedAt?: Maybe<Scalars['DateTime']['output']>;
66446646
/** labels to apply to the created prs */
66456647
labels?: Maybe<Array<Maybe<Scalars['String']['output']>>>;
6648+
/** a set of lua scripts to use to preprocess the PR automation */
6649+
lua?: Maybe<PrLuaSpec>;
66466650
message: Scalars['String']['output'];
66476651
/** the name for this automation */
66486652
name: Scalars['String']['output'];
@@ -6684,6 +6688,8 @@ export type PrAutomationAttributes = {
66846688
darkIcon?: InputMaybe<Scalars['String']['input']>;
66856689
deletes?: InputMaybe<PrAutomationDeleteSpecAttributes>;
66866690
documentation?: InputMaybe<Scalars['String']['input']>;
6691+
/** location in git for external templates and scripts */
6692+
git?: InputMaybe<GitRefAttributes>;
66876693
/** the governance controller to use for this pr */
66886694
governanceId?: InputMaybe<Scalars['ID']['input']>;
66896695
/** an icon url to use for this catalog */
@@ -6692,6 +6698,8 @@ export type PrAutomationAttributes = {
66926698
identifier?: InputMaybe<Scalars['String']['input']>;
66936699
/** labels to apply to created prs */
66946700
labels?: InputMaybe<Array<InputMaybe<Scalars['String']['input']>>>;
6701+
/** a specification for sourcing lua scripts to preprocess the PR automation */
6702+
lua?: InputMaybe<PrLuaSpecAttributes>;
66956703
message?: InputMaybe<Scalars['String']['input']>;
66966704
name?: InputMaybe<Scalars['String']['input']>;
66976705
/** whether to generate a patch for this pr instead of a full pr */
@@ -6896,6 +6904,23 @@ export type PrGovernanceConfigurationAttributes = {
68966904
webhook?: InputMaybe<GovernanceWebhookAttributes>;
68976905
};
68986906

6907+
/** a specification for sourcing lua scripts to preprocess the PR automation */
6908+
export type PrLuaSpec = {
6909+
__typename?: 'PrLuaSpec';
6910+
/** a folder with lua library code and scripts to use */
6911+
folder?: Maybe<Scalars['String']['output']>;
6912+
/** file of a flat script to use */
6913+
script?: Maybe<Scalars['String']['output']>;
6914+
};
6915+
6916+
/** a specification for sourcing lua scripts to preprocess the PR automation */
6917+
export type PrLuaSpecAttributes = {
6918+
/** a folder with lua library code and scripts to use */
6919+
folder?: InputMaybe<Scalars['String']['input']>;
6920+
/** file of a flat script to use */
6921+
script?: InputMaybe<Scalars['String']['input']>;
6922+
};
6923+
68996924
export enum PrRole {
69006925
Cluster = 'CLUSTER',
69016926
Cost = 'COST',
406 KB
Binary file not shown.
406 KB
Binary file not shown.

charts/controller/crds/deployments.plural.sh_prautomations.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,26 @@ spec:
425425
Documentation provides detailed explanation of what this automation does,
426426
when to use it, and any prerequisites or considerations.
427427
type: string
428+
git:
429+
description: Git location to source external files from.
430+
properties:
431+
files:
432+
description: Optional files to add to the manifests for this service
433+
items:
434+
type: string
435+
type: array
436+
folder:
437+
description: Folder is the folder in the Git repository where
438+
the manifests are located.
439+
type: string
440+
ref:
441+
description: Ref is the Git reference (branch, tag, or commit)
442+
to use.
443+
type: string
444+
required:
445+
- folder
446+
- ref
447+
type: object
428448
icon:
429449
description: |-
430450
Icon provides a URL to an icon image to visually represent this automation
@@ -440,6 +460,17 @@ spec:
440460
items:
441461
type: string
442462
type: array
463+
lua:
464+
description: Lua specification to source lua scripts to preprocess
465+
the PR automation.
466+
properties:
467+
folder:
468+
description: Folder with lua library code and scripts to use
469+
type: string
470+
script:
471+
description: File of a flat script to use
472+
type: string
473+
type: object
443474
message:
444475
description: |-
445476
Message defines the commit message template that will be used in the generated PR.

go/client/models_gen.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/controller/api/v1alpha1/prautomation_types.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ type PrAutomationSpec struct {
159159
// +kubebuilder:validation:Optional
160160
RepositoryRef *corev1.ObjectReference `json:"repositoryRef,omitempty"`
161161

162+
// Git location to source external files from.
163+
// +kubebuilder:validation:Optional
164+
Git *GitRef `json:"git,omitempty"`
165+
162166
// ServiceRef references a specific service that this PR automation acts upon.
163167
// +kubebuilder:validation:Optional
164168
ServiceRef *corev1.ObjectReference `json:"serviceRef,omitempty"`
@@ -207,6 +211,10 @@ type PrAutomationSpec struct {
207211
// +kubebuilder:validation:Optional
208212
Deletes *PrAutomationDeleteConfiguration `json:"deletes,omitempty"`
209213

214+
// Lua specification to source lua scripts to preprocess the PR automation.
215+
// +kubebuilder:validation:Optional
216+
Lua *PrAutomationLuaConfiguration `json:"lua,omitempty"`
217+
210218
// Reconciliation settings for this resource.
211219
// Controls drift detection and reconciliation intervals.
212220
// +kubebuilder:validation:Optional
@@ -632,3 +640,21 @@ func (in *PrAutomationSecretEntry) Attributes() *console.PrSecretEntryAttributes
632640
Autogenerate: in.Autogenerate,
633641
}
634642
}
643+
644+
type PrAutomationLuaConfiguration struct {
645+
// File of a flat script to use
646+
// +kubebuilder:validation:Optional
647+
Script *string `json:"script,omitempty"`
648+
649+
// Folder with lua library code and scripts to use
650+
// +kubebuilder:validation:Optional
651+
Folder *string `json:"folder,omitempty"`
652+
}
653+
654+
func (in *PrAutomationLuaConfiguration) Attributes() *console.PrLuaSpecAttributes {
655+
if in == nil {
656+
return nil
657+
}
658+
659+
return &console.PrLuaSpecAttributes{Script: in.Script, Folder: in.Folder}
660+
}

go/controller/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/controller/config/crd/bases/deployments.plural.sh_prautomations.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,26 @@ spec:
425425
Documentation provides detailed explanation of what this automation does,
426426
when to use it, and any prerequisites or considerations.
427427
type: string
428+
git:
429+
description: Git location to source external files from.
430+
properties:
431+
files:
432+
description: Optional files to add to the manifests for this service
433+
items:
434+
type: string
435+
type: array
436+
folder:
437+
description: Folder is the folder in the Git repository where
438+
the manifests are located.
439+
type: string
440+
ref:
441+
description: Ref is the Git reference (branch, tag, or commit)
442+
to use.
443+
type: string
444+
required:
445+
- folder
446+
- ref
447+
type: object
428448
icon:
429449
description: |-
430450
Icon provides a URL to an icon image to visually represent this automation
@@ -440,6 +460,17 @@ spec:
440460
items:
441461
type: string
442462
type: array
463+
lua:
464+
description: Lua specification to source lua scripts to preprocess
465+
the PR automation.
466+
properties:
467+
folder:
468+
description: Folder with lua library code and scripts to use
469+
type: string
470+
script:
471+
description: File of a flat script to use
472+
type: string
473+
type: object
443474
message:
444475
description: |-
445476
Message defines the commit message template that will be used in the generated PR.

go/controller/internal/controller/prautomation_attributes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ func (in *PrAutomationReconciler) Attributes(ctx context.Context, pra *v1alpha1.
6262
BranchPrefix: pra.Spec.BranchPrefix,
6363
Icon: pra.Spec.Icon,
6464
DarkIcon: pra.Spec.DarkIcon,
65+
Git: pra.Spec.Git.Attributes(),
6566
Updates: pra.Spec.Updates.Attributes(),
6667
Creates: pra.Spec.Creates.Attributes(),
6768
Deletes: pra.Spec.Deletes.Attributes(),
69+
Lua: pra.Spec.Lua.Attributes(),
6870
Addon: pra.Spec.Addon,
6971
ClusterID: clusterID,
7072
ServiceID: serviceID,

lib/console/deployments/pr/dispatcher.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,20 @@ defmodule Console.Deployments.Pr.Dispatcher do
128128
impl.pr_info(url)
129129
end
130130

131-
defp external_git(%PrAutomation{repository: %GitRepository{} = git, creates: %{git: %{ref: _, folder: _} = ref}}) do
131+
defp external_git(%PrAutomation{repository: %GitRepository{} = git, git: %{ref: _, folder: _} = ref}),
132+
do: external_git(git, ref)
133+
defp external_git(%PrAutomation{repository: %GitRepository{} = git, creates: %{git: %{ref: _, folder: _} = ref}}),
134+
do: external_git(git, ref)
135+
defp external_git(_), do: {:ok, nil}
136+
137+
defp external_git(%GitRepository{} = git, %{ref: _, folder: _} = ref) do
132138
with {:ok, dir} <- Briefly.create(directory: true),
133139
{:ok, f} <- Discovery.fetch(git, ref),
134140
{:ok, contents} <- Tar.tar_stream(f),
135141
:ok <- Console.dump_folder(dir, contents),
136142
do: {:ok, dir}
137143
end
138-
defp external_git(_), do: {:ok, nil}
144+
defp external_git(_, _), do: {:ok, nil}
139145

140146
defp resolve_repo("mgmt") do
141147
case Settings.cached() do

0 commit comments

Comments
 (0)