Chilkat Online Tools

GetMergeConflicts Swift3 Example

AWS CodeCommit

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    authAws.accessKey = "AWS_ACCESS_KEY"
    authAws.secretKey = "AWS_SECRET_KEY"

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.region = "us-west-2"
    authAws.serviceName = "codecommit"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://codecommit.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("codecommit.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    let json = CkoJsonObject()!
    json.update("conflictDetailLevel", value: "string")
    json.update("conflictResolutionStrategy", value: "string")
    json.update("destinationCommitSpecifier", value: "string")
    json.updateInt("maxConflictFiles", value: 123)
    json.update("mergeOption", value: "string")
    json.update("nextToken", value: "string")
    json.update("repositoryName", value: "string")
    json.update("sourceCommitSpecifier", value: "string")

    // The JSON request body created by the above code:

    // {
    //   "conflictDetailLevel": "string",
    //   "conflictResolutionStrategy": "string",
    //   "destinationCommitSpecifier": "string",
    //   "maxConflictFiles": number,
    //   "mergeOption": "string",
    //   "nextToken": "string",
    //   "repositoryName": "string",
    //   "sourceCommitSpecifier": "string"
    // }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "CodeCommit_20150413.GetMergeConflicts")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    jResp.loadSb(sbResponseBody)

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var contentConflict: Int
    var fileModeConflict: Int
    var Base: String?
    var Destination: String?
    var Source: String?
    var filePath: String?
    var fileSizesBase: Int
    var fileSizesDestination: Int
    var fileSizesSource: Int
    var isBinaryFileBase: Int
    var isBinaryFileDestination: Int
    var isBinaryFileSource: Int
    var mergeOperationsDestination: String?
    var mergeOperationsSource: String?
    var numberOfConflicts: Int
    var objectTypeConflict: Int
    var objectTypesBase: String?
    var objectTypesDestination: String?
    var objectTypesSource: String?

    var baseCommitId: String? = jResp.string(of: "baseCommitId")
    var destinationCommitId: String? = jResp.string(of: "destinationCommitId")
    var mergeable: Int = jResp.int(of: "mergeable").intValue
    var nextToken: String? = jResp.string(of: "nextToken")
    var sourceCommitId: String? = jResp.string(of: "sourceCommitId")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "conflictMetadataList").intValue
    while i < count_i {
        jResp.i = i
        contentConflict = jResp.int(of: "conflictMetadataList[i].contentConflict").intValue
        fileModeConflict = jResp.int(of: "conflictMetadataList[i].fileModeConflict").intValue
        Base = jResp.string(of: "conflictMetadataList[i].fileModes.base")
        Destination = jResp.string(of: "conflictMetadataList[i].fileModes.destination")
        Source = jResp.string(of: "conflictMetadataList[i].fileModes.source")
        filePath = jResp.string(of: "conflictMetadataList[i].filePath")
        fileSizesBase = jResp.int(of: "conflictMetadataList[i].fileSizes.base").intValue
        fileSizesDestination = jResp.int(of: "conflictMetadataList[i].fileSizes.destination").intValue
        fileSizesSource = jResp.int(of: "conflictMetadataList[i].fileSizes.source").intValue
        isBinaryFileBase = jResp.int(of: "conflictMetadataList[i].isBinaryFile.base").intValue
        isBinaryFileDestination = jResp.int(of: "conflictMetadataList[i].isBinaryFile.destination").intValue
        isBinaryFileSource = jResp.int(of: "conflictMetadataList[i].isBinaryFile.source").intValue
        mergeOperationsDestination = jResp.string(of: "conflictMetadataList[i].mergeOperations.destination")
        mergeOperationsSource = jResp.string(of: "conflictMetadataList[i].mergeOperations.source")
        numberOfConflicts = jResp.int(of: "conflictMetadataList[i].numberOfConflicts").intValue
        objectTypeConflict = jResp.int(of: "conflictMetadataList[i].objectTypeConflict").intValue
        objectTypesBase = jResp.string(of: "conflictMetadataList[i].objectTypes.base")
        objectTypesDestination = jResp.string(of: "conflictMetadataList[i].objectTypes.destination")
        objectTypesSource = jResp.string(of: "conflictMetadataList[i].objectTypes.source")
        i = i + 1
    }

    // A sample JSON response body parsed by the above code:

    // {
    //   "baseCommitId": "string",
    //   "conflictMetadataList": [
    //     {
    //       "contentConflict": boolean,
    //       "fileModeConflict": boolean,
    //       "fileModes": {
    //         "base": "string",
    //         "destination": "string",
    //         "source": "string"
    //       },
    //       "filePath": "string",
    //       "fileSizes": {
    //         "base": number,
    //         "destination": number,
    //         "source": number
    //       },
    //       "isBinaryFile": {
    //         "base": boolean,
    //         "destination": boolean,
    //         "source": boolean
    //       },
    //       "mergeOperations": {
    //         "destination": "string",
    //         "source": "string"
    //       },
    //       "numberOfConflicts": number,
    //       "objectTypeConflict": boolean,
    //       "objectTypes": {
    //         "base": "string",
    //         "destination": "string",
    //         "source": "string"
    //       }
    //     }
    //   ],
    //   "destinationCommitId": "string",
    //   "mergeable": boolean,
    //   "nextToken": "string",
    //   "sourceCommitId": "string"
    // }

}