Skip to content

Commit add1555

Browse files
committed
Add implicit conversion for IssueState -> IssueStateFilter
1 parent 6255527 commit add1555

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.joda.time.DateTime
1111
import org.joda.time.DateTimeZone
1212

1313
import codecheck.github.utils.ToDo
14+
import scala.language.implicitConversions
1415

1516
sealed abstract class IssueState(val name: String) {
1617
override def toString = name
@@ -20,6 +21,13 @@ object IssueState {
2021
case object open extends IssueState("open")
2122
case object closed extends IssueState("closed")
2223

24+
def all = IssueStateFilter.all
25+
26+
implicit def toIssueStateFilter(state: IssueState) = state match {
27+
case IssueState.open => IssueStateFilter.open
28+
case IssueState.closed => IssueStateFilter.closed
29+
}
30+
2331
val values = Array(open, closed)
2432

2533
def fromString(str: String) = values.filter(_.name == str).head

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class IssueOpSpec extends FunSpec with api.Constants with BeforeAndAfterAll {
108108
}
109109

110110
it("shold return only two issues when using options.") {
111-
val option = IssueListOption(IssueFilter.created, IssueStateFilter.open, Seq("question"), since=Some(nTime))
111+
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
112112
val result = Await.result(api.listAllIssues(option), TIMEOUT)
113113
assert(result.length > 0)
114114
assert(result.head.title == "test issue")
@@ -122,7 +122,7 @@ class IssueOpSpec extends FunSpec with api.Constants with BeforeAndAfterAll {
122122
}
123123

124124
it("shold return only one issues when using options.") {
125-
val option = IssueListOption(IssueFilter.created, IssueStateFilter.open, Seq("question"), since=Some(nTime))
125+
val option = IssueListOption(IssueFilter.created, IssueState.open, Seq("question"), since=Some(nTime))
126126
val result = Await.result(api.listUserIssues(option), TIMEOUT)
127127
assert(result.length > 0)
128128
assert(result.head.title == "test issue")
@@ -141,23 +141,23 @@ class IssueOpSpec extends FunSpec with api.Constants with BeforeAndAfterAll {
141141
}
142142

143143
it("should return only one issue from user's own repo when using options.") {
144-
val option = new IssueListOption4Repository(Some(MilestoneSearchOption(1)), IssueStateFilter.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
144+
val option = new IssueListOption4Repository(Some(MilestoneSearchOption(1)), IssueState.open, Some(user), Some(user), labels=Seq("question"), since=Some(nTime))
145145
val result = Await.result(api.listRepositoryIssues(user, userRepo, option), TIMEOUT)
146146
//showResponse(option.q)
147147
assert(result.length == 1)
148148
assert(result.head.title == "test issue")
149149
}
150150

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

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

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

0 commit comments

Comments
 (0)