• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / kubebuilder / 24950431257

26 Apr 2026 06:43AM UTC coverage: 81.92%. First build
24950431257

Pull #5584

github

camilamacedo86
chore(alpha update/AutoUpdate): Changes to ensure better usage and allow granular workflow and permissions
Pull Request #5584: WIP: chore(alpha update/AutoUpdate): Changes to ensure better usage and allow granular workflow and permissions

0 of 52 new or added lines in 2 files covered. (0.0%)

7707 of 9408 relevant lines covered (81.92%)

73.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.94
/pkg/plugins/optional/autoupdate/v1alpha/edit.go
1
/*
2
Copyright 2025 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package v1alpha
18

19
import (
20
        "fmt"
21
        log "log/slog"
22

23
        "github.com/spf13/pflag"
24

25
        "sigs.k8s.io/kubebuilder/v4/pkg/config"
26
        "sigs.k8s.io/kubebuilder/v4/pkg/machinery"
27
        "sigs.k8s.io/kubebuilder/v4/pkg/plugin"
28
        "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/autoupdate/v1alpha/scaffolds"
29
)
30

31
var _ plugin.EditSubcommand = &editSubcommand{}
32

33
type editSubcommand struct {
34
        config      config.Config
35
        useGHModels bool
36
        openGHIssue bool
37
        openGHPR    bool
38
        force       bool
39
        flagSet     *pflag.FlagSet
40

41
        // Merged config after Scaffold() - used in PostScaffold()
42
        mergedConfig PluginConfig
43
}
44

45
func (p *editSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) {
×
46
        subcmdMeta.Description = metaDataDescription
×
47

×
NEW
48
        subcmdMeta.Examples = fmt.Sprintf(`  # Edit a common project with this plugin (default: creates both Issues and PRs)
×
49
  %[1]s edit --plugins=%[2]s
×
50

×
51
  # Edit a common project with GitHub Models enabled (requires repo permissions)
×
52
  %[1]s edit --plugins=%[2]s --use-gh-models
×
NEW
53

×
NEW
54
  # Edit to create only PRs (no issue notifications)
×
NEW
55
  %[1]s edit --plugins=%[2]s --open-gh-issue=false
×
NEW
56

×
NEW
57
  # Edit to create only Issues (no PRs)
×
NEW
58
  %[1]s edit --plugins=%[2]s --open-gh-pr=false
×
59
`, cliMeta.CommandName, plugin.KeyFor(Plugin{}))
×
60
}
×
61

62
func (p *editSubcommand) BindFlags(fs *pflag.FlagSet) {
×
NEW
63
        p.flagSet = fs
×
64
        fs.BoolVar(&p.useGHModels, "use-gh-models", false,
×
65
                "If set, enable GitHub Models AI summary in the scaffolded workflow (requires GitHub Models permissions)")
×
NEW
66
        fs.BoolVar(&p.openGHIssue, "open-gh-issue", true,
×
NEW
67
                "By default, create GitHub Issues to notify about updates. Disable with --open-gh-issue=false")
×
NEW
68
        fs.BoolVar(&p.openGHPR, "open-gh-pr", true,
×
NEW
69
                "By default, create GitHub Pull Requests with the update changes. Disable with --open-gh-pr=false")
×
NEW
70
        fs.BoolVar(&p.force, "force", false,
×
NEW
71
                "If set, overwrite existing workflow file if present (manual edits will be lost)")
×
72
}
×
73

74
func (p *editSubcommand) InjectConfig(c config.Config) error {
2✔
75
        p.config = c
2✔
76
        return nil
2✔
77
}
2✔
78

79
func (p *editSubcommand) PreScaffold(machinery.Filesystem) error {
2✔
80
        if len(p.config.GetCliVersion()) == 0 {
3✔
81
                return fmt.Errorf(
1✔
82
                        "you must manually upgrade your project to a version that records the CLI version in PROJECT (`cliVersion`) " +
1✔
83
                                "to allow the `alpha update` command to work properly before using this plugin.\n" +
1✔
84
                                "More info: https://book.kubebuilder.io/migrations",
1✔
85
                )
1✔
86
        }
1✔
87
        return nil
1✔
88
}
89

90
func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
×
NEW
91
        // Validate that --use-gh-models requires --open-gh-pr
×
NEW
92
        // AI summaries only work with PRs
×
NEW
93
        if p.useGHModels && !p.openGHPR {
×
NEW
94
                return fmt.Errorf(
×
NEW
95
                        "the --use-gh-models flag requires --open-gh-pr=true " +
×
NEW
96
                                "(AI summaries only work with Pull Requests)")
×
NEW
97
        }
×
98

99
        // Merge with existing config: only update fields for flags that were explicitly set
NEW
100
        cfg := PluginConfig{
×
NEW
101
                // Set defaults for new projects
×
NEW
102
                OpenGHIssue: true,
×
NEW
103
                OpenGHPR:    true,
×
NEW
104
        }
×
NEW
105

×
NEW
106
        // Read existing config if it exists
×
NEW
107
        key := plugin.GetPluginKeyForConfig(p.config.GetPluginChain(), Plugin{})
×
NEW
108
        _ = p.config.DecodePluginConfig(key, &cfg)
×
NEW
109

×
NEW
110
        // Only update fields for flags that were explicitly set by the user
×
NEW
111
        if p.flagSet.Changed("use-gh-models") {
×
NEW
112
                cfg.UseGHModels = p.useGHModels
×
NEW
113
        }
×
NEW
114
        if p.flagSet.Changed("open-gh-issue") {
×
NEW
115
                cfg.OpenGHIssue = p.openGHIssue
×
NEW
116
        }
×
NEW
117
        if p.flagSet.Changed("open-gh-pr") {
×
NEW
118
                cfg.OpenGHPR = p.openGHPR
×
NEW
119
        }
×
120

NEW
121
        if err := insertPluginMetaToConfig(p.config, cfg); err != nil {
×
122
                return fmt.Errorf("error inserting project plugin meta to configuration: %w", err)
×
123
        }
×
124

125
        // Store merged config for PostScaffold()
NEW
126
        p.mergedConfig = cfg
×
NEW
127

×
NEW
128
        scaffolder := scaffolds.NewInitScaffolder(cfg.UseGHModels, cfg.OpenGHIssue, cfg.OpenGHPR, p.force)
×
129
        scaffolder.InjectFS(fs)
×
130
        if err := scaffolder.Scaffold(); err != nil {
×
131
                return fmt.Errorf("error scaffolding edit subcommand: %w", err)
×
132
        }
×
133

134
        return nil
×
135
}
136

137
func (p *editSubcommand) PostScaffold() error {
×
138
        // Inform users about GitHub Models if they didn't enable it
×
NEW
139
        // Note: AI summaries only work when PRs are enabled
×
NEW
140
        if !p.mergedConfig.UseGHModels && p.mergedConfig.OpenGHPR {
×
NEW
141
                log.Info("Consider enabling GitHub Models to get an AI summary in PRs")
×
142
                log.Info("Use the --use-gh-models flag if your project/organization has permission to use GitHub Models")
×
143
        }
×
144
        return nil
×
145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc