diff --git a/cmd/Makefile b/cmd/Makefile index da6b8514..5de2f5e2 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -1,6 +1,12 @@ BINARIES = gen_release_notes gen_release_report backport semv standup k3s_release rancher_release test_coverage upstream_go_version rke2_release ARCHS = amd64 arm64 OSs = linux darwin freebsd - GO_COMPILE = CGO_ENABLED=1 $(GO) build -tags $(TAGS) -v -ldflags "$(LDFLAGS)" -o $@-$${os}-$${arch} +OS := $(shell uname) + +ifeq ($(OS),Darwin) +GEN_HASH = shasum -a 256 $@-$${os}-$${arch} >> $(BINDIR)/sha256sums-$(BINARY).txt +else GEN_HASH = sha256sum $@-$${os}-$${arch} >> $(BINDIR)/sha256sums-$(BINARY).txt +endif + diff --git a/cmd/gen_release_notes/main.go b/cmd/gen_release_notes/main.go index 2867ee42..e8ff8a4d 100644 --- a/cmd/gen_release_notes/main.go +++ b/cmd/gen_release_notes/main.go @@ -22,17 +22,19 @@ Usage: %[2]s [-r repo] [-m milestone] [-p prev milestone] Options: -h help -v show version and exit + -o repository owner/org -r repo repository that should be used -m milestone milestone to be used -p prev milestone previous milestone -d enable debug logs Examples: # generate release notes for RKE2 for milestone v1.21.5 - %[2]s -r rke2 -m v1.21.5+rke2r1 -p v1.21.4+rke2r1 + %[2]s -o rancher -r rke2 -m v1.21.5+rke2r1 -p v1.21.4+rke2r1 ` var ( vers bool + owner string repo string milestone string prevMilestone string @@ -53,6 +55,7 @@ func main() { flag.BoolVar(&vers, "v", false, "") flag.BoolVar(&debug, "d", false, "") + flag.StringVar(&owner, "o", "", "") flag.StringVar(&repo, "r", "", "") flag.StringVar(&milestone, "m", "", "") flag.StringVar(&prevMilestone, "p", "", "") @@ -73,8 +76,13 @@ func main() { os.Exit(1) } - if !repository.IsValidRepo(repo) { - fmt.Println("error: please provide a valid repository") + if owner == "" { + fmt.Println("error: owner flag required") + os.Exit(1) + } + + if repo == "" { + fmt.Println("error: repo flag required") os.Exit(1) } @@ -86,7 +94,7 @@ func main() { ctx := context.Background() client := repository.NewGithub(ctx, ghToken) - notes, err := release.GenReleaseNotes(ctx, repo, milestone, prevMilestone, client) + notes, err := release.GenReleaseNotes(ctx, owner, repo, milestone, prevMilestone, client) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/cmd/rke2_release/README.md b/cmd/rke2_release/README.md index 75df5f52..84014779 100644 --- a/cmd/rke2_release/README.md +++ b/cmd/rke2_release/README.md @@ -16,12 +16,25 @@ Checks if new Golang versions are available and creates new releases in `rancher **Examples** -``` +```sh export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} rke2_release image-build-base-release ``` +```sh +rke2_release components -l all +image-build-base |v1.21.3b1 +image-build-calico |v3.26.1-build20231009 +image-build-cni-plugins |v1.2.0-build20231009 +... +``` + +```sh +rke2_release components -l image-build-k8s-metrics-server +image-build-k8s-metrics-server|v0.6.3-build20231009 +``` + ## Contributions - File Issue with details of the problem, feature request, etc. diff --git a/cmd/rke2_release/components.go b/cmd/rke2_release/components.go new file mode 100644 index 00000000..5db7f566 --- /dev/null +++ b/cmd/rke2_release/components.go @@ -0,0 +1,78 @@ +package main + +import ( + "context" + "errors" + "fmt" + "os" + "text/tabwriter" + + "github.com/rancher/ecm-distro-tools/repository" + "github.com/urfave/cli/v2" +) + +func componentsCommand() *cli.Command { + return &cli.Command{ + Name: "components", + Usage: "interact with the RKE2 components", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "github-token", + Aliases: []string{"g"}, + EnvVars: []string{"GITHUB_TOKEN"}, + Required: true, + }, + &cli.StringFlag{ + Name: "list", + Aliases: []string{"l"}, + Required: false, + }, + }, + Action: components, + } +} + +func components(c *cli.Context) error { + token := c.String("github-token") + if token == "" { + return errors.New("env var GITHUB_TOKEN is required") + } + + listContent := c.String("list") + + ctx := context.Background() + ghClient := repository.NewGithub(ctx, token) + w := tabwriter.NewWriter(os.Stdout, 0, 0, 0, ' ', tabwriter.Debug) + + if listContent == "all" { + for _, repo := range repository.RKE2HardenedImages { + owner, repo, err := repository.SplitOwnerRepo(repo) + if err != nil { + return err + } + + tag, err := repository.LatestTag(ctx, ghClient, owner, repo) + if err != nil { + return err + } + + fmt.Fprintf(w, "%s\t%+v\n", repo, *tag.Name) + } + } else { + owner, repo, err := repository.SplitOwnerRepo(listContent) + if err != nil { + return err + } + + tag, err := repository.LatestTag(ctx, ghClient, owner, repo) + if err != nil { + return err + } + + fmt.Fprintf(w, "%s\t%+v\n", repo, *tag.Name) + } + + w.Flush() + + return nil +} diff --git a/cmd/rke2_release/main.go b/cmd/rke2_release/main.go index 1dccd6e5..88da3c29 100644 --- a/cmd/rke2_release/main.go +++ b/cmd/rke2_release/main.go @@ -28,6 +28,7 @@ func main() { app.UseShortOptionHandling = true app.Commands = []*cli.Command{ imageBuildBaseReleaseCommand(), + componentsCommand(), } app.Flags = rootFlags diff --git a/rke2-dependencies.md b/docs/rke2-dependencies.md similarity index 100% rename from rke2-dependencies.md rename to docs/rke2-dependencies.md diff --git a/release/k3s/k3s.go b/release/k3s/k3s.go index ff7df50a..40232bbd 100644 --- a/release/k3s/k3s.go +++ b/release/k3s/k3s.go @@ -658,10 +658,12 @@ func (r *Release) CreateRelease(ctx context.Context, client *github.Client, rc b rcNum := 1 name := r.NewK8SClient + "+" + r.NewK3SVersion oldName := r.OldK8SVersion + "+" + r.OldK8SVersion + for { if rc { name = r.NewK8SVersion + "-rc" + strconv.Itoa(rcNum) + "+" + r.NewK3SVersion } + opts := &repository.CreateReleaseOpts{ Repo: k3sRepo, Name: name, @@ -670,27 +672,36 @@ func (r *Release) CreateRelease(ctx context.Context, client *github.Client, rc b Draft: !rc, ReleaseNotes: "", } + if !rc { - latestRc, err := release.LatestRC(ctx, k3sRepo, r.NewK8SVersion, client) - buff, err := release.GenReleaseNotes(ctx, k3sRepo, latestRc, oldName, client) + latestRc, err := release.LatestRC(ctx, "k3s-io", k3sRepo, r.NewK8SVersion, client) + if err != nil { + return err + } + + buff, err := release.GenReleaseNotes(ctx, "k3s-io", k3sRepo, latestRc, oldName, client) if err != nil { return err } opts.ReleaseNotes = buff.String() } - _, err := repository.CreateRelease(ctx, client, opts) - if err != nil { + + if _, err := repository.CreateRelease(ctx, client, opts); err != nil { githubErr := err.(*github.ErrorResponse) if strings.Contains(githubErr.Errors[0].Code, "already_exists") { if !rc { return err } + rcNum += 1 continue } + return err } + break } + return nil } diff --git a/release/rancher/rancher.go b/release/rancher/rancher.go index 4ffdd57e..10ecb82c 100644 --- a/release/rancher/rancher.go +++ b/release/rancher/rancher.go @@ -258,18 +258,13 @@ func SetChartBranchReferences(ctx context.Context, forkPath, rancherBaseBranch, } func createPRFromRancher(ctx context.Context, rancherBaseBranch, title, branchName, forkOwner string, ghClient *github.Client) error { - const repo = "rancher" - org, err := repository.OrgFromRepo(repo) - if err != nil { - return err - } pull := &github.NewPullRequest{ Title: github.String(title), Base: github.String(rancherBaseBranch), Head: github.String(forkOwner + ":" + branchName), MaintainerCanModify: github.Bool(true), } - _, _, err = ghClient.PullRequests.Create(ctx, org, repo, pull) + _, _, err := ghClient.PullRequests.Create(ctx, "rancher", "rancher", pull) return err } diff --git a/release/release.go b/release/release.go index b2d719d4..ab766a5d 100644 --- a/release/release.go +++ b/release/release.go @@ -102,7 +102,7 @@ func capitalize(s string) string { // GenReleaseNotes genereates release notes based on the given milestone, // previous milestone, and repository. -func GenReleaseNotes(ctx context.Context, repo, milestone, prevMilestone string, client *github.Client) (*bytes.Buffer, error) { +func GenReleaseNotes(ctx context.Context, owner, repo, milestone, prevMilestone string, client *github.Client) (*bytes.Buffer, error) { funcMap := template.FuncMap{ "majMin": majMin, "trimPeriods": trimPeriods, @@ -113,7 +113,7 @@ func GenReleaseNotes(ctx context.Context, repo, milestone, prevMilestone string, tmpl := template.New(templateName).Funcs(funcMap) tmpl = template.Must(tmpl.Parse(changelogTemplate)) - content, err := repository.RetrieveChangeLogContents(ctx, client, repo, prevMilestone, milestone) + content, err := repository.RetrieveChangeLogContents(ctx, client, owner, repo, prevMilestone, milestone) if err != nil { return nil, err } @@ -294,16 +294,11 @@ func KubernetesGoVersion(ctx context.Context, client *github.Client, version str // VerifyAssets checks the number of assets for the // given release and indicates if the expected number has // been met. -func VerifyAssets(ctx context.Context, client *github.Client, repo string, tags []string) (map[string]bool, error) { +func VerifyAssets(ctx context.Context, client *github.Client, owner, repo string, tags []string) (map[string]bool, error) { if len(tags) == 0 { return nil, errors.New("no tags provided") } - org, err := repository.OrgFromRepo(repo) - if err != nil { - return nil, err - } - releases := make(map[string]bool, len(tags)) const ( @@ -317,7 +312,7 @@ func VerifyAssets(ctx context.Context, client *github.Client, repo string, tags continue } - release, _, err := client.Repositories.GetReleaseByTag(ctx, org, repo, tag) + release, _, err := client.Repositories.GetReleaseByTag(ctx, owner, repo, tag) if err != nil { switch err := err.(type) { case *github.ErrorResponse: @@ -348,17 +343,12 @@ func VerifyAssets(ctx context.Context, client *github.Client, repo string, tags } // ListAssets gets all assets associated with the given release. -func ListAssets(ctx context.Context, client *github.Client, repo, tag string) ([]*github.ReleaseAsset, error) { - org, err := repository.OrgFromRepo(repo) - if err != nil { - return nil, err - } - +func ListAssets(ctx context.Context, client *github.Client, owner, repo, tag string) ([]*github.ReleaseAsset, error) { if tag == "" { return nil, errors.New("invalid tag provided") } - release, _, err := client.Repositories.GetReleaseByTag(ctx, org, repo, tag) + release, _, err := client.Repositories.GetReleaseByTag(ctx, owner, repo, tag) if err != nil { switch err := err.(type) { case *github.ErrorResponse: @@ -374,17 +364,12 @@ func ListAssets(ctx context.Context, client *github.Client, repo, tag string) ([ } // DeleteAssetsByRelease deletes all release assets for the given release tag. -func DeleteAssetsByRelease(ctx context.Context, client *github.Client, repo, tag string) error { - org, err := repository.OrgFromRepo(repo) - if err != nil { - return err - } - +func DeleteAssetsByRelease(ctx context.Context, client *github.Client, owner, repo, tag string) error { if tag == "" { return errors.New("invalid tag provided") } - release, _, err := client.Repositories.GetReleaseByTag(ctx, org, repo, tag) + release, _, err := client.Repositories.GetReleaseByTag(ctx, owner, repo, tag) if err != nil { switch err := err.(type) { case *github.ErrorResponse: @@ -397,7 +382,7 @@ func DeleteAssetsByRelease(ctx context.Context, client *github.Client, repo, tag } for _, asset := range release.Assets { - if _, err := client.Repositories.DeleteReleaseAsset(ctx, org, repo, asset.GetID()); err != nil { + if _, err := client.Repositories.DeleteReleaseAsset(ctx, owner, repo, asset.GetID()); err != nil { return err } } @@ -406,17 +391,12 @@ func DeleteAssetsByRelease(ctx context.Context, client *github.Client, repo, tag } // DeleteAssetByID deletes the release asset associated with the given ID. -func DeleteAssetByID(ctx context.Context, client *github.Client, repo, tag string, id int64) error { - org, err := repository.OrgFromRepo(repo) - if err != nil { - return err - } - +func DeleteAssetByID(ctx context.Context, client *github.Client, owner, repo, tag string, id int64) error { if tag == "" { return errors.New("invalid tag provided") } - if _, err := client.Repositories.DeleteReleaseAsset(ctx, org, repo, id); err != nil { + if _, err := client.Repositories.DeleteReleaseAsset(ctx, owner, repo, id); err != nil { return err } @@ -622,13 +602,10 @@ func findInURL(url, regex, str string, checkStatusCode bool) []string { } // LatestRC will get the latest rc created for the k8s version in either rke2 or k3s -func LatestRC(ctx context.Context, repo, k8sVersion string, client *github.Client) (string, error) { +func LatestRC(ctx context.Context, owner, repo, k8sVersion string, client *github.Client) (string, error) { var rcs []*github.RepositoryRelease - org, err := repository.OrgFromRepo(repo) - if err != nil { - return "", err - } - allReleases, _, err := client.Repositories.ListReleases(ctx, org, repo, &github.ListOptions{}) + + allReleases, _, err := client.Repositories.ListReleases(ctx, owner, repo, &github.ListOptions{}) if err != nil { return "", err } diff --git a/release/rke2/rke2.go b/release/rke2/rke2.go index aa82bf29..11bba5fd 100644 --- a/release/rke2/rke2.go +++ b/release/rke2/rke2.go @@ -10,7 +10,6 @@ import ( "github.com/google/go-github/v39/github" ecmHTTP "github.com/rancher/ecm-distro-tools/http" - "github.com/rancher/ecm-distro-tools/repository" "github.com/sirupsen/logrus" ) @@ -29,10 +28,7 @@ func ImageBuildBaseRelease(ctx context.Context, ghClient *github.Client) error { if err != nil { return err } - imageBuildBaseOrg, err := repository.OrgFromRepo(imageBuildBaseRepo) - if err != nil { - return err - } + for _, version := range versions { logrus.Info("version: " + version.Version) if !version.Stable { @@ -41,13 +37,13 @@ func ImageBuildBaseRelease(ctx context.Context, ghClient *github.Client) error { } v := "v" + strings.Split(version.Version, "go")[1] + "b1" logrus.Info("stripped version: " + v) - _, _, err := ghClient.Repositories.GetReleaseByTag(ctx, imageBuildBaseOrg, imageBuildBaseRepo, v) + _, _, err := ghClient.Repositories.GetReleaseByTag(ctx, "rancher", imageBuildBaseRepo, v) if err == nil { logrus.Info("release " + v + " already exists") continue } logrus.Info("release " + v + " doesn't exists, creating release") - _, _, err = ghClient.Repositories.CreateRelease(ctx, imageBuildBaseOrg, imageBuildBaseRepo, &github.RepositoryRelease{ + _, _, err = ghClient.Repositories.CreateRelease(ctx, "rancher", imageBuildBaseRepo, &github.RepositoryRelease{ TagName: github.String(v), Name: github.String(v), Prerelease: github.Bool(false), diff --git a/repository/repositories.go b/repository/repositories.go new file mode 100644 index 00000000..9ae4adc3 --- /dev/null +++ b/repository/repositories.go @@ -0,0 +1,79 @@ +package repository + +import ( + "errors" + "strings" +) + +// RKE2HardenedImages +var RKE2HardenedImages = []string{ + "rancher/image-build-base", + "rancher/image-build-calico", + "rancher/image-build-cni-plugins", + "rancher/image-build-containerd", + "rancher/image-build-coredns", + "rancher/image-build-crictl", + "rancher/image-build-dns-nodecache", + "rancher/image-build-etcd", + "rancher/image-build-flannel", + "rancher/image-build-ib-sriov-cni", + "rancher/image-build-k8s-metrics-server", + "rancher/image-build-kubernetes", + "rancher/image-build-multus", + "rancher/image-build-rke2-cloud-provider", + "rancher/image-build-runc", + "rancher/image-build-sriov-cni", + "rancher/image-build-sriov-network-device-plugin", + "rancher/image-build-sriov-network-resources-injector", + "rancher/image-build-sriov-operator", + "rancher/image-build-whereabouts", + "rancher/ingress-nginx", +} + +// RKE2MirroredImages +var RKE2MirroredImages = []string{ + "mirrored-ingress-nginx-kube-webhook-certgen", + "mirrored-cilium-cilium", + "mirrored-cilium-operator-aws", + "mirrored-cilium-operator-azure", + "mirrored-cilium-operator-generic", + "mirrored-calico-operator", + "mirrored-calico-ctl", + "mirrored-calico-kube-controllers", + "mirrored-calico-typha", + "mirrored-calico-node", + "mirrored-calico-pod2daemon-flexvol", + "mirrored-calico-cni", + "mirrored-calico-apiserver", + "mirrored-cloud-provider-vsphere-cpi-release-manager", + "mirrored-cloud-provider-vsphere-csi-release-driver", + "mirrored-cloud-provider-vsphere-csi-release-syncer", + "mirrored-sig-storage-csi-node-driver-registrar", + "mirrored-sig-storage-csi-resizer", + "mirrored-sig-storage-livenessprobe", + "mirrored-sig-storage-csi-attacher", + "mirrored-sig-storage-csi-provisioner", +} + +// RKE2Adjacent +var RKE2Adjacent = []string{ + "rancher/rke2-upgrade", + "rancher/rke2-packaging", + "rancher/system-agent-installer-rke2", + "rancher/system-upgrade-controller", +} + +const ownerRepoSeparattor = "/" + +func SplitOwnerRepo(ownerRepo string) (string, string, error) { + if !strings.Contains(ownerRepo, ownerRepoSeparattor) { + return "", "", errors.New("invalid format") + } + + ss := strings.Split(ownerRepo, ownerRepoSeparattor) + if len(ss) != 2 { + return "", "", errors.New("invalid format") + } + + return ss[0], ss[1], nil +} diff --git a/repository/repository.go b/repository/repository.go index bb623e60..96b6d3d9 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -23,20 +23,13 @@ const ( httpTimeout = time.Second * 10 ) -// repoToOrg associates repo to org. -var repoToOrg = map[string]string{ - "rke2": "rancher", - "k3s": "k3s-io", - "rancher": "rancher", - "image-build-base": "rancher", -} - // stripBackportTag returns a string with a prefix backport tag removed func stripBackportTag(s string) string { if strings.Contains(s, "Release") || strings.Contains(s, "release") && strings.Contains(s, "[") || strings.Contains(s, "]") { s = strings.Split(s, "]")[1] } s = strings.Trim(s, " ") + return s } @@ -50,6 +43,7 @@ func (t *TokenSource) Token() (*oauth2.Token, error) { token := &oauth2.Token{ AccessToken: t.AccessToken, } + return token, nil } @@ -65,32 +59,9 @@ func NewGithub(ctx context.Context, token string) *github.Client { return github.NewClient(oauthClient) } -// OrgFromRepo gets the Github organization that the -// given repository is in or returns an error if -// it is not found. -func OrgFromRepo(repo string) (string, error) { - if repo, ok := repoToOrg[repo]; ok { - return repo, nil - } - - return "", errors.New("repo not found: " + repo) -} - -// IsValidRepo determines if the given -// repository is valid for this program -// to operate against. -func IsValidRepo(repo string) bool { - for r := range repoToOrg { - if repo == r { - return true - } - } - - return false -} - // CreateReleaseOpts type CreateReleaseOpts struct { + Owner string `json:"owner"` Repo string `json:"repo"` Name string `json:"name"` Prerelease bool `json:"pre_release"` @@ -100,16 +71,36 @@ type CreateReleaseOpts struct { } // ListReleases -func ListReleases(ctx context.Context, client *github.Client, repo string) ([]*github.RepositoryRelease, error) { - org, err := OrgFromRepo(repo) +func ListReleases(ctx context.Context, client *github.Client, owner, repo string) ([]*github.RepositoryRelease, error) { + releases, _, err := client.Repositories.ListReleases(ctx, owner, repo, &github.ListOptions{}) if err != nil { return nil, err } - releases, _, err := client.Repositories.ListReleases(ctx, org, repo, &github.ListOptions{}) + + return releases, nil +} + +// ListTags +func ListTags(ctx context.Context, client *github.Client, owner, repo string) ([]*github.RepositoryTag, error) { + tags, _, err := client.Repositories.ListTags(ctx, owner, repo, &github.ListOptions{}) if err != nil { return nil, err } - return releases, nil + + return tags, nil +} + +func LatestTag(ctx context.Context, client *github.Client, owner, repo string) (*github.RepositoryTag, error) { + tags, err := ListTags(ctx, client, owner, repo) + if err != nil { + return nil, err + } + + if len(tags) == 0 { + return nil, nil + } + + return tags[0], nil } // CreateRelease @@ -118,11 +109,6 @@ func CreateRelease(ctx context.Context, client *github.Client, cro *CreateReleas return nil, errors.New("CreateReleaseOpts cannot be nil") } - org, err := OrgFromRepo(cro.Repo) - if err != nil { - return nil, err - } - rr := github.RepositoryRelease{ Name: &cro.Name, TagName: &cro.Name, @@ -135,7 +121,8 @@ func CreateRelease(ctx context.Context, client *github.Client, cro *CreateReleas rr.Body = &cro.ReleaseNotes rr.GenerateReleaseNotes = &genReleaseNotes } - release, _, err := client.Repositories.CreateRelease(ctx, org, cro.Repo, &rr) + + release, _, err := client.Repositories.CreateRelease(ctx, cro.Owner, cro.Repo, &rr) if err != nil { return nil, err } @@ -145,6 +132,7 @@ func CreateRelease(ctx context.Context, client *github.Client, cro *CreateReleas // CreateReleaseIssueOpts type CreateReleaseIssueOpts struct { + Owner string Repo string Release string Captain string @@ -152,11 +140,6 @@ type CreateReleaseIssueOpts struct { // CreateReleaseIssue func CreateReleaseIssue(ctx context.Context, client *github.Client, cri *CreateReleaseIssueOpts) (*github.Issue, error) { - org, err := OrgFromRepo(cri.Repo) - if err != nil { - return nil, err - } - body := fmt.Sprintf(cutRKE2ReleaseIssue, cri.Release, cri.Release) ir := github.IssueRequest{ Title: types.StringPtr("Cut " + cri.Release), @@ -164,7 +147,8 @@ func CreateReleaseIssue(ctx context.Context, client *github.Client, cri *CreateR Assignee: types.StringPtr(cri.Captain), State: types.StringPtr("open"), } - issue, _, err := client.Issues.Create(ctx, org, cri.Repo, &ir) + + issue, _, err := client.Issues.Create(ctx, cri.Owner, cri.Repo, &ir) if err != nil { return nil, err } @@ -173,13 +157,8 @@ func CreateReleaseIssue(ctx context.Context, client *github.Client, cri *CreateR } // RetrieveOriginalIssue -func RetrieveOriginalIssue(ctx context.Context, client *github.Client, repo string, issueID uint) (*github.Issue, error) { - org, err := OrgFromRepo(repo) - if err != nil { - return nil, err - } - - issue, _, err := client.Issues.Get(ctx, org, repo, int(issueID)) +func RetrieveOriginalIssue(ctx context.Context, client *github.Client, owner, repo string, issueID uint) (*github.Issue, error) { + issue, _, err := client.Issues.Get(ctx, owner, repo, int(issueID)) if err != nil { return nil, err } @@ -204,12 +183,7 @@ type ChangeLog struct { } // CreateBackportIssues -func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue *github.Issue, repo, branch, user string, i *Issue) (*github.Issue, error) { - org, err := OrgFromRepo(repo) - if err != nil { - return nil, err - } - +func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue *github.Issue, owner, repo, branch, user string, i *Issue) (*github.Issue, error) { title := fmt.Sprintf(i.Title, strings.Title(branch), origIssue.GetTitle()) body := fmt.Sprintf(i.Body, origIssue.GetTitle(), *origIssue.Number) @@ -221,7 +195,7 @@ func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue } else { assignee = types.StringPtr("") } - issue, _, err := client.Issues.Create(ctx, org, repo, &github.IssueRequest{ + issue, _, err := client.Issues.Create(ctx, owner, repo, &github.IssueRequest{ Title: github.String(title), Body: github.String(body), Assignee: assignee, @@ -235,6 +209,7 @@ func CreateBackportIssues(ctx context.Context, client *github.Client, origIssue // PerformBackportOpts type PerformBackportOpts struct { + Owner string `json:"owner"` Repo string `json:"repo"` Commits []string `json:"commits"` IssueID uint `json:"issue_id"` @@ -245,10 +220,6 @@ type PerformBackportOpts struct { // PerformBackport creates backport issues, performs a cherry-pick of the // given commit if it exists. func PerformBackport(ctx context.Context, client *github.Client, pbo *PerformBackportOpts) ([]*github.Issue, error) { - if !IsValidRepo(pbo.Repo) { - return nil, fmt.Errorf("invalid repo: %s", pbo.Repo) - } - const ( issueTitle = "[%s] - %s" issueBody = "Backport fix for %s\n\n* #%d" @@ -259,7 +230,7 @@ func PerformBackport(ctx context.Context, client *github.Client, pbo *PerformBac return nil, errors.New("no branches specified") } - origIssue, err := RetrieveOriginalIssue(ctx, client, pbo.Repo, pbo.IssueID) + origIssue, err := RetrieveOriginalIssue(ctx, client, pbo.Owner, pbo.Repo, pbo.IssueID) if err != nil { return nil, err } @@ -271,7 +242,7 @@ func PerformBackport(ctx context.Context, client *github.Client, pbo *PerformBac issues := make([]*github.Issue, len(backportBranches)) for _, branch := range backportBranches { - newIssue, err := CreateBackportIssues(ctx, client, origIssue, pbo.Repo, branch, pbo.User, &issue) + newIssue, err := CreateBackportIssues(ctx, client, origIssue, pbo.Owner, pbo.Repo, branch, pbo.User, &issue) if err != nil { return nil, err } @@ -348,13 +319,8 @@ func PerformBackport(ctx context.Context, client *github.Client, pbo *PerformBac // RetrieveChangeLogContents gets the relevant changes // for the given release, formats, and returns them. -func RetrieveChangeLogContents(ctx context.Context, client *github.Client, repo, prevMilestone, milestone string) ([]ChangeLog, error) { - org, err := OrgFromRepo(repo) - if err != nil { - return nil, err - } - - comp, _, err := client.Repositories.CompareCommits(ctx, org, repo, prevMilestone, milestone, &github.ListOptions{}) +func RetrieveChangeLogContents(ctx context.Context, client *github.Client, owner, repo, prevMilestone, milestone string) ([]ChangeLog, error) { + comp, _, err := client.Repositories.CompareCommits(ctx, owner, repo, prevMilestone, milestone, &github.ListOptions{}) if err != nil { return nil, err } @@ -367,7 +333,7 @@ func RetrieveChangeLogContents(ctx context.Context, client *github.Client, repo, continue } - prs, _, err := client.PullRequests.ListPullRequestsWithCommit(ctx, org, repo, sha, &github.PullRequestListOptions{}) + prs, _, err := client.PullRequests.ListPullRequestsWithCommit(ctx, owner, repo, sha, &github.PullRequestListOptions{}) if err != nil { return nil, err }