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

kubernetes-sigs / kubebuilder / 23995721683

05 Apr 2026 06:09AM UTC coverage: 79.487% (-0.4%) from 79.854%
23995721683

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 46 new or added lines in 2 files covered. (0.0%)

2 existing lines in 2 files now uncovered.

6223 of 7829 relevant lines covered (79.49%)

37.42 hits per line

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

20.97
/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
        onlyIssue   bool
37
        force       bool
38
}
39

40
func (p *editSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) {
×
41
        subcmdMeta.Description = metaDataDescription
×
42

×
NEW
43
        subcmdMeta.Examples = fmt.Sprintf(`  # Edit a common project with this plugin (creates PRs by default)
×
44
  %[1]s edit --plugins=%[2]s
×
45

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

×
NEW
49
  # Edit a common project to create GitHub Issues instead of PRs
×
NEW
50
  %[1]s edit --plugins=%[2]s --only-issue
×
51
`, cliMeta.CommandName, plugin.KeyFor(Plugin{}))
×
52
}
×
53

54
func (p *editSubcommand) BindFlags(fs *pflag.FlagSet) {
×
55
        fs.BoolVar(&p.useGHModels, "use-gh-models", false,
×
56
                "enable GitHub Models AI summary in the scaffolded workflow (requires GitHub Models permissions)")
×
NEW
57
        fs.BoolVar(&p.onlyIssue, "only-issue", false,
×
NEW
58
                "create GitHub Issues instead of Pull Requests (default is to create PRs)")
×
NEW
59
        fs.BoolVar(&p.force, "force", false,
×
NEW
60
                "overwrite existing workflow file if present (manual edits will be lost)")
×
UNCOV
61
}
×
62

63
func (p *editSubcommand) InjectConfig(c config.Config) error {
2✔
64
        p.config = c
2✔
65
        return nil
2✔
66
}
2✔
67

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

79
func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
×
NEW
80
        // Validate that --use-gh-models is not used with --only-issue
×
NEW
81
        // AI summaries only work with PRs, not with Issues
×
NEW
82
        if p.useGHModels && p.onlyIssue {
×
NEW
83
                return fmt.Errorf(
×
NEW
84
                        "the --use-gh-models flag cannot be used with --only-issue " +
×
NEW
85
                                "(AI summaries only work with Pull Requests)")
×
NEW
86
        }
×
87

NEW
88
        if err := insertPluginMetaToConfig(p.config, PluginConfig{
×
NEW
89
                UseGHModels: p.useGHModels,
×
NEW
90
                OnlyIssue:   p.onlyIssue,
×
NEW
91
        }); err != nil {
×
92
                return fmt.Errorf("error inserting project plugin meta to configuration: %w", err)
×
93
        }
×
94

NEW
95
        scaffolder := scaffolds.NewInitScaffolder(p.useGHModels, p.onlyIssue, p.force)
×
96
        scaffolder.InjectFS(fs)
×
97
        if err := scaffolder.Scaffold(); err != nil {
×
98
                return fmt.Errorf("error scaffolding edit subcommand: %w", err)
×
99
        }
×
100

101
        return nil
×
102
}
103

104
func (p *editSubcommand) PostScaffold() error {
×
105
        // Inform users about GitHub Models if they didn't enable it
×
NEW
106
        // Note: AI summaries only work in PR mode (not with --only-issue)
×
NEW
107
        if !p.useGHModels && !p.onlyIssue {
×
NEW
108
                log.Info("Consider enabling GitHub Models to get an AI summary in PRs")
×
109
                log.Info("Use the --use-gh-models flag if your project/organization has permission to use GitHub Models")
×
110
        }
×
111
        return nil
×
112
}
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