Add ability to pass milestone by number

This commit is contained in:
Mislav Marohnić 2020-08-11 19:27:26 +02:00
parent 20ffa49d69
commit e12c35cc17
4 changed files with 86 additions and 21 deletions

View file

@ -46,7 +46,7 @@ func init() {
issueListCmd.Flags().IntP("limit", "L", 30, "Maximum number of issues to fetch")
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
issueListCmd.Flags().String("mention", "", "Filter by mention")
issueListCmd.Flags().StringP("milestone", "m", "", "Filter by milestone `name`")
issueListCmd.Flags().StringP("milestone", "m", "", "Filter by milestone `number` or title")
issueCmd.AddCommand(issueViewCmd)
issueViewCmd.Flags().BoolP("web", "w", false, "Open an issue in the browser")

View file

@ -285,11 +285,8 @@ func TestIssueList_web(t *testing.T) {
func TestIssueList_milestoneNotFound(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()
defer http.Verify(t)
http.StubRepoResponse("OWNER", "REPO")
http.Register(
httpmock.GraphQL(`query IssueList\b`),
httpmock.FileResponse("../test/fixtures/issueList.json"),
)
http.Register(
httpmock.GraphQL(`query RepositoryMilestoneList\b`),
httpmock.StringResponse(`
@ -300,11 +297,39 @@ func TestIssueList_milestoneNotFound(t *testing.T) {
`))
_, err := RunCommand("issue list --milestone NotFound")
if err == nil || err.Error() != `no milestone found with title: "NotFound"` {
if err == nil || err.Error() != `no milestone found with title "NotFound"` {
t.Errorf("error running command `issue list`: %v", err)
}
}
func TestIssueList_milestoneByNumber(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()
defer http.Verify(t)
http.StubRepoResponse("OWNER", "REPO")
http.Register(
httpmock.GraphQL(`query RepositoryMilestoneByNumber\b`),
httpmock.StringResponse(`
{ "data": { "repository": { "milestone": {
"id": "MDk6TWlsZXN0b25lMTIzNDU="
} } } }
`))
http.Register(
httpmock.GraphQL(`query IssueList\b`),
httpmock.GraphQLQuery(`
{ "data": { "repository": {
"hasIssuesEnabled": true,
"issues": { "nodes": [] }
} } }`, func(_ string, params map[string]interface{}) {
assert.Equal(t, "12345", params["milestone"].(string)) // Database ID for the Milestone (see #1462)
}))
_, err := RunCommand("issue list --milestone 13")
if err != nil {
t.Fatalf("error running issue list: %v", err)
}
}
func TestIssueView_web(t *testing.T) {
initBlankContext("", "OWNER/REPO", "master")
http := initFakeHTTP()