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

kubernetes-sigs / kubebuilder / 25163292388

30 Apr 2026 11:37AM UTC coverage: 82.042% (-0.3%) from 82.313%
25163292388

Pull #5584

github

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

1 of 39 new or added lines in 2 files covered. (2.56%)

1 existing line in 1 file now uncovered.

7707 of 9394 relevant lines covered (82.04%)

73.43 hits per line

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

17.81
/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
        flagSet     *pflag.FlagSet
39

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

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

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

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

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

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

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

71
func (p *editSubcommand) InjectConfig(c config.Config) error {
2✔
72
        p.config = c
2✔
73
        return nil
2✔
74
}
2✔
75

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

87
func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
×
NEW
88
        var cfg PluginConfig
×
NEW
89

×
NEW
90
        // Use flag values (includes Cobra defaults)
×
NEW
91
        cfg.UseGHModels = p.useGHModels
×
NEW
92
        cfg.OpenGHIssue = p.openGHIssue
×
NEW
93
        cfg.OpenGHPR = p.openGHPR
×
NEW
94

×
NEW
95
        // Validate the merged config: --use-gh-models requires --open-gh-pr
×
NEW
96
        // AI summaries only work with PRs
×
NEW
97
        if cfg.UseGHModels && !cfg.OpenGHPR {
×
NEW
98
                return fmt.Errorf(
×
NEW
99
                        "the --use-gh-models flag requires --open-gh-pr=true " +
×
NEW
100
                                "(AI summaries only work with Pull Requests)")
×
NEW
101
        }
×
102

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

107
        // Store merged config for PostScaffold()
NEW
108
        p.mergedConfig = cfg
×
NEW
109

×
NEW
110
        // Always overwrite the workflow file to keep it in sync with configuration
×
NEW
111
        scaffolder := scaffolds.NewInitScaffolder(cfg.UseGHModels, cfg.OpenGHIssue, cfg.OpenGHPR)
×
112
        scaffolder.InjectFS(fs)
×
113
        if err := scaffolder.Scaffold(); err != nil {
×
114
                return fmt.Errorf("error scaffolding edit subcommand: %w", err)
×
115
        }
×
116

117
        return nil
×
118
}
119

120
func (p *editSubcommand) PostScaffold() error {
×
121
        // Inform users about GitHub Models if they didn't enable it
×
NEW
122
        // Note: AI summaries only work when PRs are enabled
×
NEW
123
        if !p.mergedConfig.UseGHModels && p.mergedConfig.OpenGHPR {
×
NEW
124
                log.Info("Consider enabling GitHub Models to get an AI summary in PRs")
×
125
                log.Info("Use the --use-gh-models flag if your project/organization has permission to use GitHub Models")
×
126
        }
×
127
        return nil
×
128
}
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