Skip to content
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
1 change: 1 addition & 0 deletions Sources/Foundation/CQLClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public final class LCCQLClient {
- parameter parameters: The parameters for placeholders in CQL statement.
- parameter completion: The completion callback closure.
*/
@discardableResult
public static func execute(
application: LCApplication = LCApplication.default,
_ cql: String, parameters: LCArrayConvertible? = nil,
Expand Down
19 changes: 17 additions & 2 deletions Sources/Foundation/EngineClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ public class LCEngine {
parameters: LCObject)
-> LCValueOptionalResult
{
return self.call(application: application, function, parameters: parameters.dictionary)
let dictionary = LCDictionary(parameters.dictionary)
dictionary.removeValue(forKey: "__type")
dictionary.removeValue(forKey: "className")
return self.call(
application: application,
function,
parameters: dictionary)
}

/// call the cloud function by RPC asynchronously
Expand All @@ -146,14 +152,23 @@ public class LCEngine {
/// - parameters: The parameters of the function
/// - completion: The result of the callback
/// - Returns: The Request
@discardableResult
public static func call(
application: LCApplication = LCApplication.default,
_ function: String,
parameters: LCObject,
completion: @escaping (LCValueOptionalResult) -> Void)
-> LCRequest
{
return self.call(application: application, function, parameters: parameters.dictionary, completion: completion)
let dictionary = LCDictionary(parameters.dictionary)
dictionary.removeValue(forKey: "__type")
dictionary.removeValue(forKey: "className")
return self.call(
application: application,
function,
parameters: dictionary,
completionQueue: completionQueue,
completion: completion)
}

@discardableResult
Expand Down
16 changes: 0 additions & 16 deletions Sources/Foundation/Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,22 +306,6 @@ extension LCError {

}

/**
Synchronize on an object and do something.

- parameter object: The object locked on.
- parameter body: Something you want to do.

- returns: Result of body.
*/
func synchronize<T>(on object: Any, body: () throws -> T) rethrows -> T {
objc_sync_enter(object)

defer { objc_sync_exit(object) }

return try body()
}

/**
Dispatch task in main queue asynchronously.

Expand Down
37 changes: 13 additions & 24 deletions Sources/Foundation/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class LCFile: LCObject {
return "_File"
}

// MARK: Save

/// Save file synchronously.
public func save() -> LCBooleanResult {
return expect { fulfill in
Expand Down Expand Up @@ -162,7 +164,8 @@ public class LCFile: LCObject {
@discardableResult
private func save(
progressInBackground progress: @escaping (Double) -> Void,
completion: @escaping (LCBooleanResult) -> Void) -> LCRequest
completion: @escaping (LCBooleanResult) -> Void)
-> LCRequest
{
let httpClient: HTTPClient = self.application.httpClient

Expand Down Expand Up @@ -197,7 +200,9 @@ public class LCFile: LCObject {
}
}

let parameters = dictionary.jsonValue as? [String: Any]
var parameters = dictionary.jsonValue as? [String: Any]
parameters?.removeValue(forKey: "__type")
parameters?.removeValue(forKey: "className")

return httpClient.request(.post, "files", parameters: parameters) { response in
let result = LCValueResult<LCDictionary>(response: response)
Expand All @@ -224,7 +229,8 @@ public class LCFile: LCObject {
private func upload(
payload: Payload,
progress: @escaping (Double) -> Void,
completion: @escaping (LCBooleanResult) -> Void) -> LCRequest
completion: @escaping (LCBooleanResult) -> Void)
-> LCRequest
{
let uploader = FileUploader(file: self, payload: payload)

Expand Down Expand Up @@ -281,41 +287,24 @@ public class LCFile: LCObject {
// MARK: Unavailable

@available(*, unavailable)
public override class func save(
_ objects: [LCObject],
options: [LCObject.SaveOption] = [])
-> LCBooleanResult
{
public override class func save(_ objects: [LCObject], options: [LCObject.SaveOption] = []) -> LCBooleanResult {
fatalError("not support")
}

@available(*, unavailable)
public override class func save(
_ objects: [LCObject],
options: [LCObject.SaveOption] = [],
completion: @escaping (LCBooleanResult) -> Void)
-> LCRequest
{
public override class func save(_ objects: [LCObject], options: [LCObject.SaveOption] = [], completion: @escaping (LCBooleanResult) -> Void) -> LCRequest {
fatalError("not support")
}

@available(*, unavailable)
public override func save(
options: [LCObject.SaveOption] = [])
-> LCBooleanResult
{
public override func save(options: [LCObject.SaveOption] = []) -> LCBooleanResult {
fatalError("not support")
}

@available(*, unavailable)
public override func save(
options: [LCObject.SaveOption] = [],
completion: @escaping (LCBooleanResult) -> Void)
-> LCRequest
{
public override func save(options: [LCObject.SaveOption] = [], completion: @escaping (LCBooleanResult) -> Void) -> LCRequest {
fatalError("not support")
}

}

extension LCFile {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Foundation/FileUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ class FileUploader {
metaData["mime_type"] = attributes.mimeType

parameters["metaData"] = metaData
parameters.removeValue(forKey: "__type")
parameters.removeValue(forKey: "className")

return parameters
}
Expand Down
22 changes: 11 additions & 11 deletions Sources/Foundation/Installation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ public class LCInstallation: LCObject {
self.apnsTeamId = apnsTeamId.lcString
}

override func preferredBatchRequest(method: HTTPClient.Method, path: String, internalId: String) throws -> [String : Any]? {
override func preferredBatchRequest(
method: HTTPClient.Method,
path: String,
internalId: String)
throws -> [String : Any]?
{
switch method {
case .post, .put:
var request: [String: Any] = [:]
Expand All @@ -112,6 +117,8 @@ public class LCInstallation: LCObject {

body.removeValue(forKey: "createdAt")
body.removeValue(forKey: "updatedAt")
body.removeValue(forKey: "__type")
body.removeValue(forKey: "className")

request["body"] = body
}
Expand Down Expand Up @@ -140,13 +147,12 @@ public class LCInstallation: LCObject {
LCInstallation.saveCurrentInstallation(self)
}
}

}

// MARK: Cache

extension LCInstallation {

// MARK: Cache

struct CacheTable: Codable {
let jsonString: String
let applicationID: String
Expand Down Expand Up @@ -195,31 +201,27 @@ extension LCInstallation {
Logger.shared.error(error)
}
}

}

// MARK: Device Token Conversion
// MARK: Device Token Convertible

public protocol LCDeviceTokenConvertible {

var lcDeviceToken: LCString { get }

}

extension String: LCDeviceTokenConvertible {

public var lcDeviceToken: LCString {
return lcString
}

}

extension NSString: LCDeviceTokenConvertible {

public var lcDeviceToken: LCString {
return (self as String).lcDeviceToken
}

}

extension Data: LCDeviceTokenConvertible {
Expand All @@ -229,13 +231,11 @@ extension Data: LCDeviceTokenConvertible {

return LCString(string)
}

}

extension NSData: LCDeviceTokenConvertible {

public var lcDeviceToken: LCString {
return (self as Data).lcDeviceToken
}

}
4 changes: 4 additions & 0 deletions Sources/Foundation/SMSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public final class LCSMSClient {
- parameter variables: The variables used to substitute placeholders in template.
- parameter completion: The completion callback closure.
*/
@discardableResult
public static func requestShortMessage(
application: LCApplication = LCApplication.default,
mobilePhoneNumber: String,
Expand Down Expand Up @@ -170,6 +171,7 @@ public final class LCSMSClient {
- parameter timeToLive: The time to live of short message, in minutes. Defaults to 10 minutes.
- parameter completion: The completion callback closure.
*/
@discardableResult
public static func requestVerificationCode(
application: LCApplication = LCApplication.default,
mobilePhoneNumber: String,
Expand Down Expand Up @@ -240,6 +242,7 @@ public final class LCSMSClient {
- parameter mobilePhoneNumber: The mobile phone number where verification code will be sent to.
- parameter completion: The completion callback closure.
*/
@discardableResult
public static func requestVoiceVerificationCode(
application: LCApplication = LCApplication.default,
mobilePhoneNumber: String,
Expand Down Expand Up @@ -297,6 +300,7 @@ public final class LCSMSClient {
- parameter verificationCode: The verification code.
- parameter completion: The completion callback closure.
*/
@discardableResult
public static func verifyMobilePhoneNumber(
application: LCApplication = LCApplication.default,
_ mobilePhoneNumber: String,
Expand Down
2 changes: 2 additions & 0 deletions Sources/Foundation/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,8 @@ open class LCUser: LCObject {

var parameters = (self.dictionary.jsonValue as? [String: Any]) ?? [:]
parameters["authData"] = [platform.key: authData]
parameters.removeValue(forKey: "__type")
parameters.removeValue(forKey: "className")

let path: String
if let options = options, options.contains(.failOnNotExist) {
Expand Down
28 changes: 25 additions & 3 deletions main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,15 @@ class GitTask: Task {
static func lastReleasableMessage() -> String? {
var message: String?
_ = GitTask(
arguments: ["log", "-10", "--pretty=%B|cat"])
arguments: ["log", "-16", "--pretty=%B|cat"])
.excute(printOutput: false) {
let data = ($0.standardOutput as! Pipe).fileHandleForReading.readDataToEndOfFile()
message = String(data: data, encoding: .utf8)?
.components(separatedBy: .newlines)
.map({ s in s.trimmingCharacters(in: .whitespacesAndNewlines) })
.first(where: { (s) -> Bool in
s.hasPrefix("feat") ||
s.hasPrefix("release") ||
s.hasPrefix("feat") ||
s.hasPrefix("fix") ||
s.hasPrefix("refactor") ||
s.hasPrefix("docs")
Expand All @@ -242,13 +243,34 @@ class HubTask: Task {
}
}

enum ReleaseDrafterLabel: String {
case breakingChanges = "feat!"
case newFeatures = "feat"
case bugFixes = "fix"
case maintenanceRefactor = "refactor"
case maintenanceDocs = "docs"
}

static func pullRequest(with message: String) throws {
try version()
var label: String?
if message.hasPrefix(ReleaseDrafterLabel.breakingChanges.rawValue) {
label = ReleaseDrafterLabel.breakingChanges.rawValue
} else if message.hasPrefix(ReleaseDrafterLabel.newFeatures.rawValue) {
label = ReleaseDrafterLabel.newFeatures.rawValue
} else if message.hasPrefix(ReleaseDrafterLabel.bugFixes.rawValue) {
label = ReleaseDrafterLabel.bugFixes.rawValue
} else if message.hasPrefix(ReleaseDrafterLabel.maintenanceRefactor.rawValue) {
label = ReleaseDrafterLabel.maintenanceRefactor.rawValue
} else if message.hasPrefix(ReleaseDrafterLabel.maintenanceDocs.rawValue) {
label = ReleaseDrafterLabel.maintenanceDocs.rawValue
}
guard HubTask(arguments: [
"pull-request",
"--base", "leancloud:master",
"--message", message,
"--force", "--push", "--browse"])
"--force", "--push", "--browse"]
+ (label != nil ? ["--labels", label!] : []))
.excute() else {
throw TaskError()
}
Expand Down