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

Adding Code Coverage and Test Number changes to comments #91

Merged
merged 3 commits into from
Jul 15, 2015
Merged
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
2 changes: 1 addition & 1 deletion Buildasaur/HDGitHubXCBotSyncer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public class HDGitHubXCBotSyncer : Syncer {

public func syncPRsAndBranchesAndBots(repo repo: Repo, repoName: String, prs: [PullRequest], branches: [Branch], bots: [Bot], completion: () -> ()) {

let prsDescription = prs.map({ "\n\tPR \($0.number): \($0.title) [\($0.head.ref) -> \($0.base.ref))]" }) + ["\n"]
let prsDescription = prs.map({ "\n\tPR \($0.number): \($0.title) [\($0.head.ref) -> \($0.base.ref)]" }) + ["\n"]
let branchesDescription = branches.map({ "\n\tBranch [\($0.name):\($0.commit.sha)]" }) + ["\n"]
let botsDescription = bots.map({ "\n\tBot \($0.name)" }) + ["\n"]
Log.verbose("Resolving prs:\n\(prsDescription) \nand branches:\n\(branchesDescription)\nand bots:\n\(botsDescription)")
Expand Down
54 changes: 38 additions & 16 deletions Buildasaur/SyncPairResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,24 @@ public class SyncPairResolver {
)
}

private func statusAndCommentFromLines(lines: [String], status: Status) -> HDGitHubXCBotSyncer.GitHubStatusAndComment {

let comment: String?
if lines.count == 0 {
comment = nil
} else {
comment = "\n".join(lines)
}
return (status: status, comment: comment)
}

func resolveStatusFromCompletedIntegrations(
integrations: Set<Integration>) -> HDGitHubXCBotSyncer.GitHubStatusAndComment {

//get integrations sorted by number
let sortedDesc = Array(integrations).sort { $0.number > $1.number }

let resultString = "*Result*: "

//if there are any succeeded, it wins - iterating from the end
if let passingIntegration = sortedDesc.filter({
(integration: Integration) -> Bool in
Expand All @@ -260,58 +272,68 @@ public class SyncPairResolver {
}
}).first {

let baseComment = HDGitHubXCBotSyncer.baseCommentFromIntegration(passingIntegration)
let comment: String
var lines = HDGitHubXCBotSyncer.baseCommentLinesFromIntegration(passingIntegration)

let status = HDGitHubXCBotSyncer.createStatusFromState(.Success, description: "Build passed!")

let summary = passingIntegration.buildResultSummary!
if passingIntegration.result == .Succeeded {
comment = baseComment + "Perfect build! All \(summary.testsCount) tests passed. :+1:"
lines.append(resultString + "**Perfect build!** All \(summary.testsCount) tests passed. :+1:")
} else if passingIntegration.result == .Warnings {
comment = baseComment + "All \(summary.testsCount) tests passed, but please fix \(summary.warningCount) warnings."
lines.append(resultString + "All \(summary.testsCount) tests passed, but please **fix \(summary.warningCount) warnings**.")
} else {
comment = baseComment + "All \(summary.testsCount) tests passed, but please fix \(summary.analyzerWarningCount) analyzer warnings."
lines.append(resultString + "All \(summary.testsCount) tests passed, but please **fix \(summary.analyzerWarningCount) analyzer warnings**.")
}

//and code coverage
let codeCoveragePercentage = summary.codeCoveragePercentage
if codeCoveragePercentage > 0 {
lines.append("*Test Coverage*: \(codeCoveragePercentage)%.")
}
return (status: status, comment: comment)

return self.statusAndCommentFromLines(lines, status: status)
}

//ok, no succeeded, warnings or analyzer warnings, get down to test failures
if let testFailingIntegration = sortedDesc.filter({
$0.result! == Integration.Result.TestFailures
}).first {

let baseComment = HDGitHubXCBotSyncer.baseCommentFromIntegration(testFailingIntegration)
var lines = HDGitHubXCBotSyncer.baseCommentLinesFromIntegration(testFailingIntegration)
let status = HDGitHubXCBotSyncer.createStatusFromState(.Failure, description: "Build failed tests!")
let summary = testFailingIntegration.buildResultSummary!
let comment = baseComment + "Build failed \(summary.testFailureCount) tests out of \(summary.testsCount)"
return (status: status, comment: comment)
lines.append(resultString + "**Build failed \(summary.testFailureCount) tests** out of \(summary.testsCount)")
return self.statusAndCommentFromLines(lines, status: status)
}

//ok, the build didn't even run then. it either got cancelled or failed
if let erroredIntegration = sortedDesc.filter({
$0.result! != Integration.Result.Canceled
}).first {

let baseComment = HDGitHubXCBotSyncer.baseCommentFromIntegration(erroredIntegration)
var lines = HDGitHubXCBotSyncer.baseCommentLinesFromIntegration(erroredIntegration)
let errorCount: String
if let summary = erroredIntegration.buildResultSummary {
errorCount = "\(summary.errorCount)"
} else {
errorCount = "?"
}
let status = HDGitHubXCBotSyncer.createStatusFromState(.Error, description: "Build error!")
let comment = baseComment + "\(errorCount) build errors: \(erroredIntegration.result!.rawValue)"
return (status: status, comment: comment)
lines.append(resultString + "**\(errorCount) errors, failing state: \(erroredIntegration.result!.rawValue)**")
return self.statusAndCommentFromLines(lines, status: status)
}

//cool, not even build error. it must be just canceled ones then.
if let canceledIntegration = sortedDesc.filter({
$0.result! == Integration.Result.Canceled
}).first {

let baseComment = HDGitHubXCBotSyncer.baseCommentFromIntegration(canceledIntegration)
var lines = HDGitHubXCBotSyncer.baseCommentLinesFromIntegration(canceledIntegration)
let status = HDGitHubXCBotSyncer.createStatusFromState(.Error, description: "Build canceled!")
let comment = baseComment + "Build was manually canceled."
return (status: status, comment: comment)

//TODO: find out who canceled it and add it to the comment?
lines.append("Build was **manually canceled**.")
return self.statusAndCommentFromLines(lines, status: status)
}

//hmm no idea, if we got all the way here. just leave it with no state.
Expand Down
12 changes: 8 additions & 4 deletions Buildasaur/SyncerBotUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ extension HDGitHubXCBotSyncer {
}
}

class func baseCommentFromIntegration(integration: Integration) -> String {
class func baseCommentLinesFromIntegration(integration: Integration) -> [String] {

var lines = [String]()

lines.append("Result of Integration **\(integration.number)**")
lines.append("---")

var comment = "Result of integration \(integration.number)\n"
if let duration = self.formattedDurationOfIntegration(integration) {
comment += "Integration took " + duration + ".\n"
lines.append("*Duration*: " + duration)
}
return comment
return lines
}

}
4 changes: 3 additions & 1 deletion BuildasaurTests/sampleFinishedIntegration.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
"warningCount": 0,
"errorChange": 0,
"improvedPerfTestCount": 0,
"analyzerWarningChange": 0
"analyzerWarningChange": 0,
"codeCoveragePercentageDelta": 0,
"codeCoveragePercentage": 0
},
"result": "succeeded",
"testedDevices": [
Expand Down
15 changes: 7 additions & 8 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@ platform :osx, '10.10'
use_frameworks!

xcs_name = 'XcodeServerSDK'
xcs_repo = 'git@github.com:czechboy0/XcodeServerSDK.git'
xcs_branch = 'swift-2'
xcs_tag = '0.1.3'

target 'BuildaUtils' do
pod xcs_name, :git => xcs_repo, :branch => xcs_branch
pod xcs_name, xcs_tag
end

target 'BuildaGitServer' do
pod xcs_name, :git => xcs_repo, :branch => xcs_branch
pod xcs_name, xcs_tag
end

target 'Buildasaur' do
pod xcs_name, :git => xcs_repo, :branch => xcs_branch
pod xcs_name, xcs_tag
end

target 'BuildaGitServerTests' do
pod xcs_name, :git => xcs_repo, :branch => xcs_branch
pod xcs_name, xcs_tag
end

target 'BuildasaurTests' do
pod xcs_name, :git => xcs_repo, :branch => xcs_branch
pod xcs_name, xcs_tag
end

target 'BuildaUtilsTests' do
pod xcs_name, :git => xcs_repo, :branch => xcs_branch
pod xcs_name, xcs_tag
end


Expand Down
18 changes: 4 additions & 14 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
PODS:
- XcodeServerSDK (0.1-beta3)
- XcodeServerSDK (0.1.3)

DEPENDENCIES:
- XcodeServerSDK (from `git@github.com:czechboy0/XcodeServerSDK.git`, branch `swift-2`)

EXTERNAL SOURCES:
XcodeServerSDK:
:branch: swift-2
:git: git@github.com:czechboy0/XcodeServerSDK.git

CHECKOUT OPTIONS:
XcodeServerSDK:
:commit: df387df50bcca48537833d37deb364d28be823c0
:git: git@github.com:czechboy0/XcodeServerSDK.git
- XcodeServerSDK (= 0.1.3)

SPEC CHECKSUMS:
XcodeServerSDK: e409d4841fd0fde113355cc7532d0e159b13ccf1
XcodeServerSDK: 811d62668e323138d552ca53451462f1fbc79513

COCOAPODS: 0.38.0.beta.1
COCOAPODS: 0.38.0.beta.2