Skip to content

Commit

Permalink
Merge pull request #24 from czechboy0/hd/cross-fork-PR-support
Browse files Browse the repository at this point in the history
added support for cross-fork pull requests
  • Loading branch information
Honza Dvorsky committed May 4, 2015
2 parents c400d37 + b107d29 commit ab3d4b7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
24 changes: 22 additions & 2 deletions Buildasaur/HDGitHubXCBotSyncer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,31 @@ public class HDGitHubXCBotSyncer : Syncer {
let schedule = BotSchedule.manualBotSchedule()
let botName = self.nameForBotWithPR(pr, repoName: self.repoName()!)
let template = self.currentBuildTemplate()
let project = self.localSource

//to handle forks
let headOriginUrl = pr.head.repo.repoUrlSSH
let localProjectOriginUrl = self.localSource.projectURL!.absoluteString

let project: LocalSource
if headOriginUrl != localProjectOriginUrl {

//we have a fork, duplicate the metadata with the fork's origin
if let source = self.localSource.duplicateForForkAtOriginURL(headOriginUrl) {
project = source
} else {
self.notifyError(Errors.errorWithInfo("Couldn't create a LocalSource for fork with origin at url \(headOriginUrl)"), context: "Creating a bot from a PR")
completion()
return
}
} else {
//a normal PR in the same repo, no need to duplicate, just use the existing localSource
project = self.localSource
}

let xcodeServer = self.xcodeServer
let branch = pr.head.ref

XcodeServerSyncerUtils.createBotFromBuildTemplate(botName, template: template, project: self.localSource, branch: branch, scheduleOverride: schedule, xcodeServer: xcodeServer) { (bot, error) -> () in
XcodeServerSyncerUtils.createBotFromBuildTemplate(botName, template: template, project: project, branch: branch, scheduleOverride: schedule, xcodeServer: xcodeServer) { (bot, error) -> () in

if error != nil {
self.notifyError(error, context: "Failed to create bot with name \(botName)")
Expand Down
29 changes: 27 additions & 2 deletions Buildasaur/LocalSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class LocalSource : JSONSerializable {
var availabilityState: AvailabilityCheckState

private(set) var workspaceMetadata: NSDictionary?

let forkOriginURL: String?

//convenience getters
var projectName: String? { get { return self.pullValueForKey("IDESourceControlProjectName") }}
var projectPath: String? { get { return self.pullValueForKey("IDESourceControlProjectPath") }}
Expand All @@ -61,7 +62,8 @@ public class LocalSource : JSONSerializable {
get {
if let urlString = self.pullValueForKey("IDESourceControlProjectURL") {

var finalUrlString = urlString
//if we have a fork, chose its URL, otherwise fallback to the loaded URL from the Checkout file
var finalUrlString = self.forkOriginURL ?? urlString
let type = self.checkoutType!
if type == .SSH {
if !finalUrlString.hasPrefix("git@") {
Expand Down Expand Up @@ -91,6 +93,8 @@ public class LocalSource : JSONSerializable {
}

init?(url: NSURL) {

self.forkOriginURL = nil
self.url = url
self.preferredTemplateId = nil
self.githubToken = nil
Expand All @@ -103,6 +107,26 @@ public class LocalSource : JSONSerializable {
}
}

private init?(original: LocalSource, forkOriginURL: String) {

self.forkOriginURL = forkOriginURL
self.url = original.url
self.preferredTemplateId = original.preferredTemplateId
self.githubToken = original.githubToken
self.availabilityState = original.availabilityState
self.publicSSHKeyUrl = original.publicSSHKeyUrl
self.privateSSHKeyUrl = original.privateSSHKeyUrl
let (parsed, error) = self.refreshMetadata()
if !parsed {
return nil
}
}

public func duplicateForForkAtOriginURL(forkURL: String) -> LocalSource? {

return LocalSource(original: self, forkOriginURL: forkURL)
}

public class func attemptToParseFromUrl(url: NSURL) -> (Bool, NSDictionary?, NSError?) {

let (meta, error) = LocalSource.loadWorkspaceMetadata(url)
Expand Down Expand Up @@ -167,6 +191,7 @@ public class LocalSource : JSONSerializable {

public required init?(json: NSDictionary) {

self.forkOriginURL = nil
self.availabilityState = .Unchecked

if
Expand Down
3 changes: 1 addition & 2 deletions Buildasaur/XcodeLocalSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ extension LocalSource {
let projectWCCIdentifier = self.projectWCCIdentifier!
let wccName = self.projectWCCName!
let projectName = self.projectName!
let projectURLOrig = self.projectURL!
let projectURL = projectURLOrig.absoluteString!
let projectURL = self.projectURL!.absoluteString!
let projectPath = self.projectPath!
let publicSSHKey = self.publicSSHKey
let privateSSHKey = self.privateSSHKey
Expand Down

0 comments on commit ab3d4b7

Please sign in to comment.