Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of the create-issue command #2

Merged
merged 10 commits into from
Nov 16, 2023
36 changes: 34 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
module systay/vitess-releaser
module vitess.io/vitess-releaser

go 1.21.0

require github.com/spf13/cobra v1.8.0

require (
github.com/cli/go-gh v1.2.1 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/cli/shurcooL-graphql v0.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/henvic/httpretty v0.0.6 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/termenv v0.12.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.17.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
510 changes: 510 additions & 0 deletions go.sum

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions go/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2023 The Vitess Authors.

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

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

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

package cmd

import (
"fmt"
"os"

"vitess.io/vitess-releaser/go/cmd/flags"
"vitess.io/vitess-releaser/go/cmd/prerequisite"

"github.com/spf13/cobra"
)

var (
releaseVersion string
)

var rootCmd = &cobra.Command{
Use: "vitess-releaser",
Short: "vitess-releaser - a tool for releasing vitess",
Long: "vitess-releaser - a tool for releasing vitess",
Run: func(cmd *cobra.Command, args []string) {

},
}

func init() {
rootCmd.PersistentFlags().StringVarP(&releaseVersion, flags.MajorRelease, "r", "", "Number of the major release on which we want to create a new release.")
err := rootCmd.MarkPersistentFlagRequired(flags.MajorRelease)
if err != nil {
panic(err)
}

rootCmd.AddCommand(prerequisite.Prerequisite())
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Whoops. There was an error while executing your CLI '%s'", err)
os.Exit(1)
}
}
21 changes: 21 additions & 0 deletions go/cmd/flags/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2023 The Vitess Authors.

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

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

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

package flags

const (
MajorRelease = "release"
)
98 changes: 98 additions & 0 deletions go/cmd/prerequisite/create_issue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright 2023 The Vitess Authors.

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

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

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

package prerequisite

import (
"bytes"
"fmt"
"log"
"text/template"

"github.com/spf13/cobra"
"vitess.io/vitess-releaser/go/cmd/flags"
"vitess.io/vitess-releaser/go/git"
"vitess.io/vitess-releaser/go/github"
"vitess.io/vitess-releaser/go/vitess"
)

const (
releaseIssueTemplate = `This release is scheduled for: TODO: '.Date' here .

### Prerequisites for Release

- [ ] Notify the community on Slack.
- [ ] Make sure the release notes summary is prepared and clean.
- [ ] Make sure backport Pull Requests are merged, list below.

### Pre-Release

- [ ] Follow Code-Freeze / Pre-Release instructions from release documentation.
- [ ] Create new GitHub Milestone.
- [ ] Create Pre-Release Pull Request.

### Release

- [ ] Follow release instructions.
- [ ] Merge release notes on main.
- [ ] Make sure Docker Images are available.
- [ ] Close previous GitHub Milestone.

### Post-Release

- [ ] Announce new release:
- [ ] Slack
- [ ] Twitter
`
)

// Create issue:
// - Make sure we are in the vitess repo
// - Make sure the git state is clean
// - Figure out the new release number
// - Create the issue for the corresponding release number
var createIssue = &cobra.Command{
Use: "create-issue",
Short: "Create the release issue",
Run: func(cmd *cobra.Command, args []string) {
if !git.CheckCurrentRepo("vitessio/vitess.git") {
log.Fatal("the tool should be run from the vitessio/vitess repository directory")
}
if !git.CleanLocalState() {
log.Fatal("the vitess repository should have a clean state")
}

majorRelease := cmd.Flags().Lookup(flags.MajorRelease).Value.String()
newRelease := vitess.FindNextRelease(majorRelease)

tmpl := template.Must(template.New("release-issue").Parse(releaseIssueTemplate))
b := bytes.NewBuffer(nil)
err := tmpl.Execute(b, nil)
if err != nil {
log.Fatal(err)
}

newIssue := github.Issue{
Title: fmt.Sprintf("Release of v%s", newRelease),
Body: b.String(),
Labels: []string{"Component: General", "Type: Release"},
Assignee: "@me",
}

link := newIssue.Create()
fmt.Println("Link to the new GitHub Issue: ", link)
},
}
32 changes: 32 additions & 0 deletions go/cmd/prerequisite/prerequisite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2023 The Vitess Authors.

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

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

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

package prerequisite

import (
"github.com/spf13/cobra"
)

func Prerequisite() *cobra.Command {
cmd := &cobra.Command{
Use: "prerequisite",
Short: "Runs the prerequisites of a release",
Run: func(cmd *cobra.Command, args []string) {},
}

cmd.AddCommand(createIssue)
return cmd
}
47 changes: 47 additions & 0 deletions go/git/git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2023 The Vitess Authors.

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

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

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

package git

import (
"log"
"os/exec"
"strings"
)

func CheckCurrentRepo(repoWanted string) bool {
out, err := exec.Command("git", "remote", "-v").CombinedOutput()
if err != nil {
log.Fatalf("%s: %s", err, out)
}
outStr := string(out)
return strings.Contains(outStr, repoWanted)
}

func CleanLocalState() bool {
out, err := exec.Command("git", "status", "-s").CombinedOutput()
if err != nil {
log.Fatalf("%s: %s", err, out)
}
return len(out) == 0
}

func Checkout(branch string) {
out, err := exec.Command("git", "checkout", branch).CombinedOutput()
if err != nil {
log.Fatalf("%s: %s", err, out)
}
}
47 changes: 47 additions & 0 deletions go/github/issues.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2023 The Vitess Authors.

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

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

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

package github

import (
"log"
"strings"

"github.com/cli/go-gh"
)

type Issue struct {
Title string
Body string
Labels []string
Assignee string
}

// Create will open the issue on GitHub and return the link of the newly created issue
func (i *Issue) Create() string {
stdOut, _, err := gh.Exec(
"issue", "create",
"--repo", "vitessio/vitess",
"--title", i.Title,
"--body", i.Body,
"--label", strings.Join(i.Labels, ","),
"--assignee", i.Assignee,
)
if err != nil {
log.Fatal(err)
}
return strings.ReplaceAll(stdOut.String(), "\n", "")
}
25 changes: 25 additions & 0 deletions go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2023 The Vitess Authors.

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

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

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

package main

import (
"vitess.io/vitess-releaser/go/cmd"
)

func main() {
cmd.Execute()
}
Loading