-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add_checksums
- Loading branch information
Showing
12 changed files
with
370 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
"github.com/google/go-github/v39/github" | ||
"github.com/rancher/ecm-distro-tools/repository" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func labelIssuesCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "label-issues", | ||
Usage: "relabels 'Waiting for RC' issues with 'To Test' and adds a comment", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "github-token", | ||
Aliases: []string{"g"}, | ||
Usage: "github token", | ||
EnvVars: []string{"GITHUB_TOKEN"}, | ||
Required: false, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "tag", | ||
Aliases: []string{"t"}, | ||
Usage: "release candidate tag", | ||
Required: true, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "dry-run", | ||
Aliases: []string{"r"}, | ||
Usage: "list matching issues and new labels without updating", | ||
Required: false, | ||
}, | ||
}, | ||
Action: labelIssuesWaitingForRC, | ||
} | ||
} | ||
|
||
// labelIssuesWaitingForRC updates issues with the "Waiting for RC" label | ||
// to "To Test" if the issue's milestone matches the tag, and creates a comment | ||
func labelIssuesWaitingForRC(c *cli.Context) error { | ||
ctx := context.Background() | ||
tag := c.String("tag") | ||
dryRun := c.Bool("dry-run") | ||
githubToken := c.String("github-token") | ||
const org = "rancher" | ||
const repo = "rancher" | ||
const oldTag = "[zube]: Waiting for RC" | ||
const newTag = "[zube]: To Test" | ||
|
||
if tag == "" { | ||
return errors.New("'tag' must be set") | ||
} | ||
v, err := semver.NewVersion(tag) | ||
if err != nil { | ||
return err | ||
} | ||
if v.Prerelease() == "" { | ||
return errors.New("'tag' must be a prerelease") | ||
} | ||
v, err = semver.NewVersion(fmt.Sprintf("%d.%d.%d", v.Major(), v.Minor(), v.Patch())) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if githubToken == "" { | ||
return errors.New("'GITHUB_TOKEN' environment variable must be set") | ||
} | ||
client := repository.NewGithub(ctx, githubToken) | ||
opts := &github.IssueListByRepoOptions{ | ||
State: "open", | ||
Labels: []string{oldTag}, | ||
} | ||
issues := make([]*github.Issue, 0) | ||
for { | ||
|
||
ghIssues, resp, err := client.Issues.ListByRepo(ctx, org, repo, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, issue := range ghIssues { | ||
if issue.Milestone == nil { | ||
continue | ||
} | ||
pattern, err := semver.NewConstraint(*issue.Milestone.Title) | ||
if err != nil { | ||
return err | ||
} | ||
if pattern.Check(v) { | ||
issues = append(issues, issue) | ||
} | ||
} | ||
|
||
if resp.NextPage == 0 { | ||
break | ||
} | ||
opts.ListOptions.Page = resp.NextPage | ||
} | ||
|
||
if dryRun { | ||
if len(issues) == 1 { | ||
fmt.Printf("Updating %d issue\n", len(issues)) | ||
} else { | ||
fmt.Printf("Updating %d issues\n", len(issues)) | ||
} | ||
} | ||
|
||
for _, issue := range issues { | ||
if dryRun { | ||
fmt.Printf("#%d %s (%s)\n [%s] -> [%s] \n", *issue.Number, *issue.Title, *issue.Milestone.Title, oldTag, newTag) | ||
continue | ||
} | ||
labels := make([]string, 0, len(issue.Labels)) | ||
for _, label := range issue.Labels { | ||
if label.GetName() != oldTag { | ||
labels = append(labels, label.GetName()) | ||
} | ||
} | ||
labels = append(labels, newTag) | ||
_, _, err = client.Issues.Edit(ctx, org, repo, *issue.Number, &github.IssueRequest{ | ||
Labels: &labels, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
_, _, err = client.Issues.CreateComment(ctx, org, repo, *issue.Number, &github.IssueComment{ | ||
Body: github.String("Available to test on " + tag), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
include ../Makefile | ||
|
||
GO = go | ||
|
||
BINDIR := bin | ||
BINARY := semv | ||
|
||
VERSION = v0.1.0 | ||
GIT_SHA = $(shell git rev-parse HEAD) | ||
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings' | ||
TAGS = "netgo osusergo no_stage static_build" | ||
|
||
$(BINDIR)/$(BINARY): clean | ||
for arch in $(ARCHS); do \ | ||
for os in $(OSs); do \ | ||
$(GO_COMPILE) ; \ | ||
done; \ | ||
done | ||
|
||
.PHONY: clean | ||
clean: | ||
$(GO) clean | ||
rm -f $(BINDIR)/$(BINARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# semv | ||
|
||
`semv` provides subcommands to parse a semantic version, and to test if a version conforms to a semantic version constraint. | ||
|
||
### Examples | ||
|
||
```sh | ||
PRERELEASE=$(./bin/semv-darwin-amd64 parse --output go-template="{{ .Prerelease }}" v1.2.3) | ||
if [ -n "$PRERELEASE" ]; then | ||
echo "Prerelease: $PRERELEASE" | ||
fi | ||
|
||
``` | ||
|
||
```sh | ||
semv test v1.1 v1.1.1 | ||
``` | ||
|
||
## Contributions | ||
|
||
* File Issue with details of the problem, feature request, etc. | ||
* Submit a pull request and include details of what problem or feature the code is solving or implementing. |
Oops, something went wrong.