Add a milestone name instead of an id, when creating
This commit is contained in:
Mislav Marohnić 2019-06-15 00:31:59 +02:00 коммит произвёл GitHub
Родитель 844c913588 e5cc8207cd
Коммит 8b49f3c0a7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 97 добавлений и 45 удалений

Просмотреть файл

@ -132,10 +132,11 @@ With no arguments, show a list of open issues.
-c, --copy
Put the URL of the new issue to clipboard instead of printing it.
-M, --milestone <ID>
Display only issues for a GitHub milestone with id <ID>.
-M, --milestone <NAME>
Display only issues for a GitHub milestone with the name <NAME>.
When opening an issue, add this issue to a GitHub milestone with id <ID>.
When opening an issue, add this issue to a GitHub milestone with the name <NAME>.
Passing the milestone number is deprecated.
-l, --labels <LABELS>
Display only issues with certain labels.
@ -168,7 +169,7 @@ hub-pr(1), hub(1)
-a, --assignee USER
-s, --state STATE
-f, --format FMT
-M, --milestone M
-M, --milestone NAME
-c, --creator USER
-@, --mentioned USER
-l, --labels LIST
@ -187,7 +188,7 @@ hub-pr(1), hub(1)
KnownFlags: `
-m, --message MSG
-F, --file FILE
-M, --milestone M
-M, --milestone NAME
-l, --labels LIST
-a, --assign USER
-o, --browse
@ -241,7 +242,16 @@ func listIssues(cmd *Command, args *Args) {
filters["assignee"] = args.Flag.Value("--assignee")
}
if args.Flag.HasReceived("--milestone") {
filters["milestone"] = args.Flag.Value("--milestone")
milestoneValue := args.Flag.Value("--milestone")
if milestoneValue == "none" {
filters["milestone"] = milestoneValue
} else {
milestoneNumber, err := milestoneValueToNumber(milestoneValue, gh, project)
utils.Check(err)
if milestoneNumber > 0 {
filters["milestone"] = milestoneNumber
}
}
}
if args.Flag.HasReceived("--creator") {
filters["creator"] = args.Flag.Value("--creator")
@ -574,8 +584,10 @@ text is the title and the rest is the description.`, project))
params["assignees"] = flagIssueAssignees
}
if flagIssueMilestone := args.Flag.Int("--milestone"); flagIssueMilestone > 0 {
params["milestone"] = flagIssueMilestone
milestoneNumber, err := milestoneValueToNumber(args.Flag.Value("--milestone"), gh, project)
utils.Check(err)
if milestoneNumber > 0 {
params["milestone"] = milestoneNumber
}
args.NoForward()
@ -673,3 +685,25 @@ func pickHighContrastTextColor(color *utils.Color) *utils.Color {
}
return utils.Black
}
func milestoneValueToNumber(value string, client *github.Client, project *github.Project) (int, error) {
if value == "" {
return 0, nil
}
if milestoneNumber, err := strconv.Atoi(value); err == nil {
return milestoneNumber, nil
}
milestones, err := client.FetchMilestones(project)
if err != nil {
return 0, err
}
for _, milestone := range milestones {
if strings.EqualFold(milestone.Title, value) {
return milestone.Number, nil
}
}
return 0, fmt.Errorf("error: no milestone found with name '%s'", value)
}

Просмотреть файл

@ -306,17 +306,8 @@ of text is the title and the rest is the description.`, fullBase, fullHead))
}
}
milestoneNumber := 0
if flagPullRequestMilestone := args.Flag.Value("--milestone"); flagPullRequestMilestone != "" {
// BC: Don't try to resolve milestone name if it's an integer
milestoneNumber, err = strconv.Atoi(flagPullRequestMilestone)
if err != nil {
milestones, err := client.FetchMilestones(baseProject)
utils.Check(err)
milestoneNumber, err = findMilestoneNumber(milestones, flagPullRequestMilestone)
utils.Check(err)
}
}
milestoneNumber, err := milestoneValueToNumber(args.Flag.Value("--milestone"), client, baseProject)
utils.Check(err)
var pullRequestURL string
if args.Noop {
@ -463,16 +454,6 @@ func parsePullRequestIssueNumber(url string) string {
return ""
}
func findMilestoneNumber(milestones []github.Milestone, name string) (int, error) {
for _, milestone := range milestones {
if strings.EqualFold(milestone.Title, name) {
return milestone.Number, nil
}
}
return 0, fmt.Errorf("error: no milestone found with name '%s'", name)
}
func commaSeparated(l []string) []string {
res := []string{}
for _, i := range l {

Просмотреть файл

@ -116,6 +116,34 @@ Feature: hub issue
"""
When I successfully run `hub issue -M none`
Scenario: Fetch issues assigned to milestone by number
Given the GitHub API server:
"""
get('/repos/github/hub/issues') {
assert :milestone => "12"
json []
}
"""
When I successfully run `hub issue -M 12`
Scenario: Fetch issues assigned to milestone by name
Given the GitHub API server:
"""
get('/repos/github/hub/milestones') {
status 200
json [
{ :number => 237, :title => "prerelease" },
{ :number => 1337, :title => "v1" },
{ :number => 41319, :title => "Hello World!" }
]
}
get('/repos/github/hub/issues') {
assert :milestone => "1337"
json []
}
"""
When I successfully run `hub issue -M v1`
Scenario: Fetch issues created by a given user
Given the GitHub API server:
"""
@ -381,6 +409,29 @@ Feature: hub issue
https://github.com/github/hub/issues/1337\n
"""
Scenario: Create an issue with milestone by name
Given the GitHub API server:
"""
get('/repos/github/hub/milestones') {
status 200
json [
{ :number => 237, :title => "prerelease" },
{ :number => 1337, :title => "v1" },
{ :number => 41319, :title => "Hello World!" }
]
}
post('/repos/github/hub/issues') {
assert :milestone => 41319
status 201
json :html_url => "https://github.com/github/hub/issues/1337"
}
"""
When I successfully run `hub issue create -m "hello" -M "hello world!"`
Then the output should contain exactly:
"""
https://github.com/github/hub/issues/1337\n
"""
Scenario: Editing empty issue message
Given the git commit editor is "vim"
And the text editor adds:

Просмотреть файл

@ -44,14 +44,7 @@ func (client *Client) FetchPullRequests(project *Project, filterParams map[strin
path := fmt.Sprintf("repos/%s/%s/pulls?per_page=%d", project.Owner, project.Name, perPage(limit, 100))
if filterParams != nil {
query := url.Values{}
for key, value := range filterParams {
switch v := value.(type) {
case string:
query.Add(key, v)
}
}
path += "&" + query.Encode()
path = addQuery(path, filterParams)
}
pulls = []PullRequest{}
@ -642,14 +635,7 @@ func (client *Client) FetchIssues(project *Project, filterParams map[string]inte
path := fmt.Sprintf("repos/%s/%s/issues?per_page=%d", project.Owner, project.Name, perPage(limit, 100))
if filterParams != nil {
query := url.Values{}
for key, value := range filterParams {
switch v := value.(type) {
case string:
query.Add(key, v)
}
}
path += "&" + query.Encode()
path = addQuery(path, filterParams)
}
issues = []Issue{}