Skip to content

Commit f4ccda3

Browse files
committed
Add IssueStateFilter separate from IssueState
* src/main/scala/codecheck/github/models/Issue.scala (IssueStateFilter): Add new type for filtering separate from IssueState. (IssueListOption, IssueListOption4Repository, IssueInput): Use new type, IssueStateFilter. * src/main/scala/codecheck/github/app/commands/IssueCommand.scala: Use IssueStateFilter instead of IssueState. * src/main/scala/codecheck/github/models/PullRequest.scala (PullRequestListOption, PullRequestRef): Use IssueStateFilter. * src/test/scala/IssueOpSpec.scala: Use IssueStateFilter.
1 parent b7897f3 commit f4ccda3

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

Diff for: src/main/scala/codecheck/github/app/commands/IssueCommand.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import codecheck.github.app.CommandSetting
99
import codecheck.github.app.Repo
1010
import codecheck.github.models.IssueListOption
1111
import codecheck.github.models.IssueFilter
12-
import codecheck.github.models.IssueState
12+
import codecheck.github.models.IssueStateFilter
1313
import codecheck.github.models.IssueSort
1414
import codecheck.github.models.SortDirection
1515
import codecheck.github.utils.PrintList
@@ -32,7 +32,7 @@ class IssueCommand(val api: GitHubAPI) extends Command {
3232

3333
def listOption = IssueListOption(
3434
IssueFilter.fromString(filter),
35-
IssueState.fromString(state),
35+
IssueStateFilter.fromString(state),
3636
labels,
3737
IssueSort.fromString(sort),
3838
SortDirection.fromString(direction),

Diff for: src/main/scala/codecheck/github/models/Issue.scala

+17-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ sealed abstract class IssueState(val name: String) {
1919
object IssueState {
2020
case object open extends IssueState("open")
2121
case object closed extends IssueState("closed")
22-
case object all extends IssueState("all")
22+
23+
val values = Array(open, closed)
24+
25+
def fromString(str: String) = values.filter(_.name == str).head
26+
}
27+
28+
sealed abstract class IssueStateFilter(val name: String) {
29+
override def toString = name
30+
}
31+
32+
object IssueStateFilter {
33+
case object open extends IssueStateFilter("open")
34+
case object closed extends IssueStateFilter("closed")
35+
case object all extends IssueStateFilter("all")
2336

2437
val values = Array(open, closed, all)
2538

@@ -70,7 +83,7 @@ object MilestoneSearchOption {
7083

7184
case class IssueListOption(
7285
filter: IssueFilter = IssueFilter.assigned,
73-
state: IssueState = IssueState.open,
86+
state: IssueStateFilter = IssueStateFilter.open,
7487
labels: Seq[String] = Nil,
7588
sort: IssueSort = IssueSort.created,
7689
direction: SortDirection = SortDirection.desc,
@@ -83,7 +96,7 @@ case class IssueListOption(
8396

8497
case class IssueListOption4Repository(
8598
milestone: Option[MilestoneSearchOption] = None,
86-
state: IssueState = IssueState.open,
99+
state: IssueStateFilter = IssueStateFilter.open,
87100
assignee: Option[String] = None,
88101
creator: Option[String] = None,
89102
mentioned: Option[String] = None,
@@ -107,7 +120,7 @@ case class IssueInput(
107120
assignee: Option[String] = None,
108121
milestone: Option[Int] = None,
109122
labels: Seq[String] = Nil,
110-
state: Option[IssueState] = None
123+
state: Option[IssueStateFilter] = None
111124
) extends AbstractInput {
112125
override val value: JValue = {
113126
val a = assignee.map { s =>

Diff for: src/main/scala/codecheck/github/models/PullRequest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object PullRequestAction {
3939
}
4040

4141
case class PullRequestListOption(
42-
state: IssueState = IssueState.open,
42+
state: IssueStateFilter = IssueStateFilter.open,
4343
head: Option[String] = None,
4444
base: Option[String] = None,
4545
sort: IssueSort = IssueSort.created,

Diff for: src/test/scala/IssueOpSpec.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.joda.time.DateTimeZone
77
import codecheck.github.models.IssueListOption
88
import codecheck.github.models.IssueFilter
99
import codecheck.github.models.IssueListOption4Repository
10-
import codecheck.github.models.IssueState
10+
import codecheck.github.models.IssueStateFilter
1111
import codecheck.github.models.Issue
1212
import codecheck.github.models.IssueInput
1313
import codecheck.github.models.MilestoneSearchOption
@@ -116,7 +116,7 @@ class IssueOpSpec extends FunSpec with Constants with BeforeAndAfterAll {
116116
}
117117

118118
it("shold return only two issues when using options.") {
119-
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
119+
val option = IssueListOption(IssueFilter.created, IssueStateFilter.open, Seq("question"), since=Some(nTime))
120120
val result = Await.result(api.listAllIssues(option), TIMEOUT)
121121
assert(result.length > 0)
122122
assert(result.head.title == "test issue")
@@ -130,7 +130,7 @@ class IssueOpSpec extends FunSpec with Constants with BeforeAndAfterAll {
130130
}
131131

132132
it("shold return only one issues when using options.") {
133-
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
133+
val option = IssueListOption(IssueFilter.created, IssueStateFilter.open, Seq("question"), since=Some(nTime))
134134
val result = Await.result(api.listUserIssues(option), TIMEOUT)
135135
assert(result.length > 0)
136136
assert(result.head.title == "test issue")
@@ -149,23 +149,23 @@ class IssueOpSpec extends FunSpec with Constants with BeforeAndAfterAll {
149149
}
150150

151151
it("should return only one issue from user's own repo when using options.") {
152-
val option = new IssueListOption4Repository(Some(MilestoneSearchOption(1)), IssueState.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
152+
val option = new IssueListOption4Repository(Some(MilestoneSearchOption(1)), IssueStateFilter.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
153153
val result = Await.result(api.listRepositoryIssues(user, userRepo, option), TIMEOUT)
154154
//showResponse(option.q)
155155
assert(result.length == 1)
156156
assert(result.head.title == "test issue")
157157
}
158158

159159
it("should return only one issue from organization's repo when using options.") {
160-
val option = new IssueListOption4Repository(None, IssueState.open, None, Some(user), labels=Nil, since=Some(nTime))
160+
val option = new IssueListOption4Repository(None, IssueStateFilter.open, None, Some(user), labels=Nil, since=Some(nTime))
161161
val result = Await.result(api.listRepositoryIssues(organization, tRepo, option), TIMEOUT)
162162
assert(result.length == 1)
163163
assert(result.head.title == "test issue")
164164
}
165165
}
166166

167167
describe("editIssue(owner, repo, number, input)") {
168-
val input = IssueInput(Some("test issue edited"), Some("testing again"), Some(user), None, Seq("question", "bug"), Some(IssueState.closed))
168+
val input = IssueInput(Some("test issue edited"), Some("testing again"), Some(user), None, Seq("question", "bug"), Some(IssueStateFilter.closed))
169169

170170
it("should edit the issue in user's own repo.") {
171171
val result = Await.result(api.editIssue(user, userRepo, nUser, input), TIMEOUT)

0 commit comments

Comments
 (0)