Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to opt out of requesting TestRun details and turn off defaultFilter #80

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to teamcity-rest-client library will be documented in this file.

## [1.14.0] - 2021-03-05

### Added

- Set `defaultFilter` of BuildLocator to false by default in `BuildLocator::all`, set default values for BuildLocator params to imitate `defaultFilter:true` behaviour.
- `BuildLocator::includeFailedToStart` method for including failed to start builds (excluded for `defaultFilter:true` by default).
- `TestRunsLocator::withoutDetails` method for excluding `details` and `ignoreDetails` fields from response.

## [1.13.0] - 2020-12-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
projectVersion=1.13
projectVersion=1.14
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ interface BuildLocator {
fun includePersonal() : BuildLocator
fun onlyPersonal(): BuildLocator

fun includeFailedToStart(): BuildLocator

fun limitResults(count: Int): BuildLocator
fun pageSize(pageSize: Int): BuildLocator

Expand Down Expand Up @@ -196,6 +198,7 @@ interface TestRunsLocator {
* of individual runs, and status will be SUCCESSFUL if and only if all runs are successful.
*/
fun expandMultipleInvocations() : TestRunsLocator
fun withoutDetails(): TestRunsLocator
fun all(): Sequence<TestRun>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,13 @@ private class BuildLocatorImpl(private val instance: TeamCityInstanceImpl) : Bui
private var tags = ArrayList<String>()
private var limitResults: Int? = null
private var pageSize: Int? = null
private var branch: String? = null
private var branch = "default:true"
private var includeAllBranches = false
private var pinnedOnly = false
private var personal: String? = null
private var personal = "false"
private var running: String? = null
private var canceled: String? = null
private var canceled = "false"
private var failedToStart = "false"

override fun fromConfiguration(buildConfigurationId: BuildConfigurationId): BuildLocatorImpl {
this.buildConfigurationId = buildConfigurationId
Expand Down Expand Up @@ -405,7 +406,7 @@ private class BuildLocatorImpl(private val instance: TeamCityInstanceImpl) : Bui
}

override fun withAllBranches(): BuildLocator {
if (branch != null) {
if (branch != "default:true") {
LOG.warn("Branch is ignored because of #withAllBranches")
}

Expand All @@ -428,6 +429,11 @@ private class BuildLocatorImpl(private val instance: TeamCityInstanceImpl) : Bui
return this
}

override fun includeFailedToStart(): BuildLocator {
this.failedToStart = "any"
return this
}

override fun limitResults(count: Int): BuildLocator {
this.limitResults = count
return this
Expand All @@ -450,7 +456,7 @@ private class BuildLocatorImpl(private val instance: TeamCityInstanceImpl) : Bui
snapshotDependencyTo?.stringId?.let { "snapshotDependency:(to:(id:$it))" },
number?.let { "number:$it" },
running?.let { "running:$it" },
canceled?.let { "canceled:$it" },
canceled.let { "canceled:$it" },
vcsRevision?.let { "revision:$it" },
status?.name?.let { "status:$it" },
if (tags.isNotEmpty())
Expand All @@ -463,16 +469,17 @@ private class BuildLocatorImpl(private val instance: TeamCityInstanceImpl) : Bui
until?.let {"untilDate:${teamCityServiceDateFormat.withZone(ZoneOffset.UTC).format(it)}"},

if (!includeAllBranches)
branch?.let { "branch:$it" }
"branch:$branch"
else
"branch:default:any",

personal?.let { "personal:$it" },
personal.let { "personal:$it" },
failedToStart.let { "failedToStart:$it" },

// Always use default filter since sometimes TC automatically switches between
// Always set default filter explicitly since sometimes TC automatically switches between
// defaultFilter:true and defaultFilter:false
// See BuildPromotionFinder.java in rest-api, setLocatorDefaults method
"defaultFilter:true"
"defaultFilter:false"
)

if (parameters.isEmpty()) {
Expand Down Expand Up @@ -550,6 +557,7 @@ private class TestRunsLocatorImpl(private val instance: TeamCityInstanceImpl) :
private var affectedProjectId: ProjectId? = null
private var testStatus: TestStatus? = null
private var expandMultipleInvocations = false
private var withoutDetails: Boolean = false

override fun limitResults(count: Int): TestRunsLocator {
this.limitResults = count
Expand Down Expand Up @@ -586,6 +594,11 @@ private class TestRunsLocatorImpl(private val instance: TeamCityInstanceImpl) :
return this
}

override fun withoutDetails(): TestRunsLocator {
this.withoutDetails = true
return this
}

override fun all(): Sequence<TestRun> {
val statusLocator = when (testStatus) {
null -> null
Expand Down Expand Up @@ -613,7 +626,8 @@ private class TestRunsLocatorImpl(private val instance: TeamCityInstanceImpl) :
val testOccurrencesLocator = parameters.joinToString(",")
LOG.debug("Retrieving test occurrences from ${instance.serverUrl} using query '$testOccurrencesLocator'")

return@lazyPaging instance.service.testOccurrences(locator = testOccurrencesLocator, fields = TestOccurrenceBean.filter)
val filter = if (withoutDetails) TestOccurrenceBean.withoutDetailsFilter else (TestOccurrenceBean.allFieldsFilter)
return@lazyPaging instance.service.testOccurrences(locator = testOccurrencesLocator, fields = filter)
}) { testOccurrencesBean ->
Page(
data = testOccurrencesBean.testOccurrence.map { TestRunImpl(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ internal open class TestOccurrenceBean {
var firstFailed: BuildBean? = null

companion object {
val filter = "testOccurrence(name,status,ignored,muted,currentlyMuted,newFailure,duration,ignoreDetails,details,firstFailed(id),nextFixed(id),build(id),test(id))"
const val withoutDetailsFilter = "testOccurrence(name,status,ignored,muted,currentlyMuted,newFailure,duration,firstFailed(id),nextFixed(id),build(id),test(id))"
const val allFieldsFilter = "testOccurrence(name,status,ignored,muted,currentlyMuted,newFailure,duration,ignoreDetails,details,firstFailed(id),nextFixed(id),build(id),test(id))"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestsTest {

@Test
fun test_deprecated_list_tests() {
@Suppress("DEPRECATION")
val tests = publicInstance().builds()
.fromConfiguration(runTestsBuildConfiguration)
.limitResults(3)
Expand Down