Chilkat Online Tools

DescribeMergeConflicts 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.update("filePath", value: "string")
    json.updateInt("maxMergeHunks", 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",
    //   "filePath": "string",
    //   "maxMergeHunks": 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.DescribeMergeConflicts")

    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 EndLine: Int
    var HunkContent: String?
    var StartLine: Int
    var destinationEndLine: Int
    var destinationHunkContent: String?
    var destinationStartLine: Int
    var isConflict: Int
    var sourceEndLine: Int
    var sourceHunkContent: String?
    var sourceStartLine: Int

    var baseCommitId: String? = jResp.string(of: "baseCommitId")
    var ContentConflict: Int = jResp.int(of: "conflictMetadata.contentConflict").intValue
    var FileModeConflict: Int = jResp.int(of: "conflictMetadata.fileModeConflict").intValue
    var Base: String? = jResp.string(of: "conflictMetadata.fileModes.base")
    var Destination: String? = jResp.string(of: "conflictMetadata.fileModes.destination")
    var Source: String? = jResp.string(of: "conflictMetadata.fileModes.source")
    var FilePath: String? = jResp.string(of: "conflictMetadata.filePath")
    var FileSizesBase: Int = jResp.int(of: "conflictMetadata.fileSizes.base").intValue
    var FileSizesDestination: Int = jResp.int(of: "conflictMetadata.fileSizes.destination").intValue
    var FileSizesSource: Int = jResp.int(of: "conflictMetadata.fileSizes.source").intValue
    var IsBinaryFileBase: Int = jResp.int(of: "conflictMetadata.isBinaryFile.base").intValue
    var IsBinaryFileDestination: Int = jResp.int(of: "conflictMetadata.isBinaryFile.destination").intValue
    var IsBinaryFileSource: Int = jResp.int(of: "conflictMetadata.isBinaryFile.source").intValue
    var MergeOperationsDestination: String? = jResp.string(of: "conflictMetadata.mergeOperations.destination")
    var MergeOperationsSource: String? = jResp.string(of: "conflictMetadata.mergeOperations.source")
    var NumberOfConflicts: Int = jResp.int(of: "conflictMetadata.numberOfConflicts").intValue
    var ObjectTypeConflict: Int = jResp.int(of: "conflictMetadata.objectTypeConflict").intValue
    var ObjectTypesBase: String? = jResp.string(of: "conflictMetadata.objectTypes.base")
    var ObjectTypesDestination: String? = jResp.string(of: "conflictMetadata.objectTypes.destination")
    var ObjectTypesSource: String? = jResp.string(of: "conflictMetadata.objectTypes.source")
    var destinationCommitId: String? = jResp.string(of: "destinationCommitId")
    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: "mergeHunks").intValue
    while i < count_i {
        jResp.i = i
        EndLine = jResp.int(of: "mergeHunks[i].base.endLine").intValue
        HunkContent = jResp.string(of: "mergeHunks[i].base.hunkContent")
        StartLine = jResp.int(of: "mergeHunks[i].base.startLine").intValue
        destinationEndLine = jResp.int(of: "mergeHunks[i].destination.endLine").intValue
        destinationHunkContent = jResp.string(of: "mergeHunks[i].destination.hunkContent")
        destinationStartLine = jResp.int(of: "mergeHunks[i].destination.startLine").intValue
        isConflict = jResp.int(of: "mergeHunks[i].isConflict").intValue
        sourceEndLine = jResp.int(of: "mergeHunks[i].source.endLine").intValue
        sourceHunkContent = jResp.string(of: "mergeHunks[i].source.hunkContent")
        sourceStartLine = jResp.int(of: "mergeHunks[i].source.startLine").intValue
        i = i + 1
    }

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

    // {
    //   "baseCommitId": "string",
    //   "conflictMetadata": {
    //     "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",
    //   "mergeHunks": [
    //     {
    //       "base": {
    //         "endLine": number,
    //         "hunkContent": "string",
    //         "startLine": number
    //       },
    //       "destination": {
    //         "endLine": number,
    //         "hunkContent": "string",
    //         "startLine": number
    //       },
    //       "isConflict": boolean,
    //       "source": {
    //         "endLine": number,
    //         "hunkContent": "string",
    //         "startLine": number
    //       }
    //     }
    //   ],
    //   "nextToken": "string",
    //   "sourceCommitId": "string"
    // }

}