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

kubernetes-sigs / kubebuilder / 24002330166

05 Apr 2026 01:17PM UTC coverage: 79.487% (-0.4%) from 79.854%
24002330166

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

0.0
/pkg/plugins/optional/autoupdate/v1alpha/init.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.InitSubcommand = &initSubcommand{}
32

33
type initSubcommand struct {
34
        config      config.Config
35
        useGHModels bool
36
        onlyIssue   bool
37
        force       bool
38
}
39

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

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

×
46
  # Initialize with GitHub Models enabled (requires repo permissions)
×
47
  %[1]s init --plugins=%[2]s --use-gh-models
×
NEW
48

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

54
func (p *initSubcommand) 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 *initSubcommand) InjectConfig(c config.Config) error {
×
64
        p.config = c
×
65
        return nil
×
66
}
×
67

68
func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error {
×
NEW
69
        // Validate that --use-gh-models is not used with --only-issue
×
NEW
70
        // AI summaries only work with PRs, not with Issues
×
NEW
71
        if p.useGHModels && p.onlyIssue {
×
NEW
72
                return fmt.Errorf(
×
NEW
73
                        "the --use-gh-models flag cannot be used with --only-issue " +
×
NEW
74
                                "(AI summaries only work with Pull Requests)")
×
NEW
75
        }
×
76

NEW
77
        if err := insertPluginMetaToConfig(p.config, PluginConfig{
×
NEW
78
                UseGHModels: p.useGHModels,
×
NEW
79
                OnlyIssue:   p.onlyIssue,
×
NEW
80
        }); err != nil {
×
81
                return fmt.Errorf("error inserting project plugin meta to configuration: %w", err)
×
82
        }
×
83

NEW
84
        scaffolder := scaffolds.NewInitScaffolder(p.useGHModels, p.onlyIssue, p.force)
×
85
        scaffolder.InjectFS(fs)
×
86
        if err := scaffolder.Scaffold(); err != nil {
×
87
                return fmt.Errorf("error scaffolding init subcommand: %w", err)
×
88
        }
×
89

90
        return nil
×
91
}
92

93
func (p *initSubcommand) PostScaffold() error {
×
94
        // Inform users about GitHub Models if they didn't enable it
×
NEW
95
        // Note: AI summaries only work in PR mode (not with --only-issue)
×
NEW
96
        if !p.useGHModels && !p.onlyIssue {
×
NEW
97
                log.Info("Consider enabling GitHub Models to get an AI summary in PRs")
×
98
                log.Info("Use the --use-gh-models flag if your project/organization has permission to use GitHub Models")
×
99
        }
×
100
        return nil
×
101
}
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