Skip to content

Commit b2f531f

Browse files
authored
Merge pull request #274 from zapcannon87/developer
fix: object post __type & className
2 parents 26fd3d1 + d1fe423 commit b2f531f

File tree

9 files changed

+75
-56
lines changed

9 files changed

+75
-56
lines changed

Sources/Foundation/CQLClient.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public final class LCCQLClient {
112112
- parameter parameters: The parameters for placeholders in CQL statement.
113113
- parameter completion: The completion callback closure.
114114
*/
115+
@discardableResult
115116
public static func execute(
116117
application: LCApplication = LCApplication.default,
117118
_ cql: String, parameters: LCArrayConvertible? = nil,

Sources/Foundation/EngineClient.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ public class LCEngine {
135135
parameters: LCObject)
136136
-> LCValueOptionalResult
137137
{
138-
return self.call(application: application, function, parameters: parameters.dictionary)
138+
let dictionary = LCDictionary(parameters.dictionary)
139+
dictionary.removeValue(forKey: "__type")
140+
dictionary.removeValue(forKey: "className")
141+
return self.call(
142+
application: application,
143+
function,
144+
parameters: dictionary)
139145
}
140146

141147
/// call the cloud function by RPC asynchronously
@@ -146,14 +152,23 @@ public class LCEngine {
146152
/// - parameters: The parameters of the function
147153
/// - completion: The result of the callback
148154
/// - Returns: The Request
155+
@discardableResult
149156
public static func call(
150157
application: LCApplication = LCApplication.default,
151158
_ function: String,
152159
parameters: LCObject,
153160
completion: @escaping (LCValueOptionalResult) -> Void)
154161
-> LCRequest
155162
{
156-
return self.call(application: application, function, parameters: parameters.dictionary, completion: completion)
163+
let dictionary = LCDictionary(parameters.dictionary)
164+
dictionary.removeValue(forKey: "__type")
165+
dictionary.removeValue(forKey: "className")
166+
return self.call(
167+
application: application,
168+
function,
169+
parameters: dictionary,
170+
completionQueue: completionQueue,
171+
completion: completion)
157172
}
158173

159174
@discardableResult

Sources/Foundation/Extension.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,6 @@ extension LCError {
306306

307307
}
308308

309-
/**
310-
Synchronize on an object and do something.
311-
312-
- parameter object: The object locked on.
313-
- parameter body: Something you want to do.
314-
315-
- returns: Result of body.
316-
*/
317-
func synchronize<T>(on object: Any, body: () throws -> T) rethrows -> T {
318-
objc_sync_enter(object)
319-
320-
defer { objc_sync_exit(object) }
321-
322-
return try body()
323-
}
324-
325309
/**
326310
Dispatch task in main queue asynchronously.
327311

Sources/Foundation/File.swift

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public class LCFile: LCObject {
107107
return "_File"
108108
}
109109

110+
// MARK: Save
111+
110112
/// Save file synchronously.
111113
public func save() -> LCBooleanResult {
112114
return expect { fulfill in
@@ -162,7 +164,8 @@ public class LCFile: LCObject {
162164
@discardableResult
163165
private func save(
164166
progressInBackground progress: @escaping (Double) -> Void,
165-
completion: @escaping (LCBooleanResult) -> Void) -> LCRequest
167+
completion: @escaping (LCBooleanResult) -> Void)
168+
-> LCRequest
166169
{
167170
let httpClient: HTTPClient = self.application.httpClient
168171

@@ -197,7 +200,9 @@ public class LCFile: LCObject {
197200
}
198201
}
199202

200-
let parameters = dictionary.jsonValue as? [String: Any]
203+
var parameters = dictionary.jsonValue as? [String: Any]
204+
parameters?.removeValue(forKey: "__type")
205+
parameters?.removeValue(forKey: "className")
201206

202207
return httpClient.request(.post, "files", parameters: parameters) { response in
203208
let result = LCValueResult<LCDictionary>(response: response)
@@ -224,7 +229,8 @@ public class LCFile: LCObject {
224229
private func upload(
225230
payload: Payload,
226231
progress: @escaping (Double) -> Void,
227-
completion: @escaping (LCBooleanResult) -> Void) -> LCRequest
232+
completion: @escaping (LCBooleanResult) -> Void)
233+
-> LCRequest
228234
{
229235
let uploader = FileUploader(file: self, payload: payload)
230236

@@ -281,41 +287,24 @@ public class LCFile: LCObject {
281287
// MARK: Unavailable
282288

283289
@available(*, unavailable)
284-
public override class func save(
285-
_ objects: [LCObject],
286-
options: [LCObject.SaveOption] = [])
287-
-> LCBooleanResult
288-
{
290+
public override class func save(_ objects: [LCObject], options: [LCObject.SaveOption] = []) -> LCBooleanResult {
289291
fatalError("not support")
290292
}
291293

292294
@available(*, unavailable)
293-
public override class func save(
294-
_ objects: [LCObject],
295-
options: [LCObject.SaveOption] = [],
296-
completion: @escaping (LCBooleanResult) -> Void)
297-
-> LCRequest
298-
{
295+
public override class func save(_ objects: [LCObject], options: [LCObject.SaveOption] = [], completion: @escaping (LCBooleanResult) -> Void) -> LCRequest {
299296
fatalError("not support")
300297
}
301298

302299
@available(*, unavailable)
303-
public override func save(
304-
options: [LCObject.SaveOption] = [])
305-
-> LCBooleanResult
306-
{
300+
public override func save(options: [LCObject.SaveOption] = []) -> LCBooleanResult {
307301
fatalError("not support")
308302
}
309303

310304
@available(*, unavailable)
311-
public override func save(
312-
options: [LCObject.SaveOption] = [],
313-
completion: @escaping (LCBooleanResult) -> Void)
314-
-> LCRequest
315-
{
305+
public override func save(options: [LCObject.SaveOption] = [], completion: @escaping (LCBooleanResult) -> Void) -> LCRequest {
316306
fatalError("not support")
317307
}
318-
319308
}
320309

321310
extension LCFile {

Sources/Foundation/FileUploader.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ class FileUploader {
263263
metaData["mime_type"] = attributes.mimeType
264264

265265
parameters["metaData"] = metaData
266+
parameters.removeValue(forKey: "__type")
267+
parameters.removeValue(forKey: "className")
266268

267269
return parameters
268270
}

Sources/Foundation/Installation.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ public class LCInstallation: LCObject {
9999
self.apnsTeamId = apnsTeamId.lcString
100100
}
101101

102-
override func preferredBatchRequest(method: HTTPClient.Method, path: String, internalId: String) throws -> [String : Any]? {
102+
override func preferredBatchRequest(
103+
method: HTTPClient.Method,
104+
path: String,
105+
internalId: String)
106+
throws -> [String : Any]?
107+
{
103108
switch method {
104109
case .post, .put:
105110
var request: [String: Any] = [:]
@@ -112,6 +117,8 @@ public class LCInstallation: LCObject {
112117

113118
body.removeValue(forKey: "createdAt")
114119
body.removeValue(forKey: "updatedAt")
120+
body.removeValue(forKey: "__type")
121+
body.removeValue(forKey: "className")
115122

116123
request["body"] = body
117124
}
@@ -140,13 +147,12 @@ public class LCInstallation: LCObject {
140147
LCInstallation.saveCurrentInstallation(self)
141148
}
142149
}
143-
144150
}
145151

146-
// MARK: Cache
147-
148152
extension LCInstallation {
149153

154+
// MARK: Cache
155+
150156
struct CacheTable: Codable {
151157
let jsonString: String
152158
let applicationID: String
@@ -195,31 +201,27 @@ extension LCInstallation {
195201
Logger.shared.error(error)
196202
}
197203
}
198-
199204
}
200205

201-
// MARK: Device Token Conversion
206+
// MARK: Device Token Convertible
202207

203208
public protocol LCDeviceTokenConvertible {
204209

205210
var lcDeviceToken: LCString { get }
206-
207211
}
208212

209213
extension String: LCDeviceTokenConvertible {
210214

211215
public var lcDeviceToken: LCString {
212216
return lcString
213217
}
214-
215218
}
216219

217220
extension NSString: LCDeviceTokenConvertible {
218221

219222
public var lcDeviceToken: LCString {
220223
return (self as String).lcDeviceToken
221224
}
222-
223225
}
224226

225227
extension Data: LCDeviceTokenConvertible {
@@ -229,13 +231,11 @@ extension Data: LCDeviceTokenConvertible {
229231

230232
return LCString(string)
231233
}
232-
233234
}
234235

235236
extension NSData: LCDeviceTokenConvertible {
236237

237238
public var lcDeviceToken: LCString {
238239
return (self as Data).lcDeviceToken
239240
}
240-
241241
}

Sources/Foundation/SMSClient.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public final class LCSMSClient {
112112
- parameter variables: The variables used to substitute placeholders in template.
113113
- parameter completion: The completion callback closure.
114114
*/
115+
@discardableResult
115116
public static func requestShortMessage(
116117
application: LCApplication = LCApplication.default,
117118
mobilePhoneNumber: String,
@@ -170,6 +171,7 @@ public final class LCSMSClient {
170171
- parameter timeToLive: The time to live of short message, in minutes. Defaults to 10 minutes.
171172
- parameter completion: The completion callback closure.
172173
*/
174+
@discardableResult
173175
public static func requestVerificationCode(
174176
application: LCApplication = LCApplication.default,
175177
mobilePhoneNumber: String,
@@ -240,6 +242,7 @@ public final class LCSMSClient {
240242
- parameter mobilePhoneNumber: The mobile phone number where verification code will be sent to.
241243
- parameter completion: The completion callback closure.
242244
*/
245+
@discardableResult
243246
public static func requestVoiceVerificationCode(
244247
application: LCApplication = LCApplication.default,
245248
mobilePhoneNumber: String,
@@ -297,6 +300,7 @@ public final class LCSMSClient {
297300
- parameter verificationCode: The verification code.
298301
- parameter completion: The completion callback closure.
299302
*/
303+
@discardableResult
300304
public static func verifyMobilePhoneNumber(
301305
application: LCApplication = LCApplication.default,
302306
_ mobilePhoneNumber: String,

Sources/Foundation/User.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,8 @@ open class LCUser: LCObject {
11661166

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

11701172
let path: String
11711173
if let options = options, options.contains(.failOnNotExist) {

main.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,15 @@ class GitTask: Task {
212212
static func lastReleasableMessage() -> String? {
213213
var message: String?
214214
_ = GitTask(
215-
arguments: ["log", "-10", "--pretty=%B|cat"])
215+
arguments: ["log", "-16", "--pretty=%B|cat"])
216216
.excute(printOutput: false) {
217217
let data = ($0.standardOutput as! Pipe).fileHandleForReading.readDataToEndOfFile()
218218
message = String(data: data, encoding: .utf8)?
219219
.components(separatedBy: .newlines)
220220
.map({ s in s.trimmingCharacters(in: .whitespacesAndNewlines) })
221221
.first(where: { (s) -> Bool in
222-
s.hasPrefix("feat") ||
222+
s.hasPrefix("release") ||
223+
s.hasPrefix("feat") ||
223224
s.hasPrefix("fix") ||
224225
s.hasPrefix("refactor") ||
225226
s.hasPrefix("docs")
@@ -242,13 +243,34 @@ class HubTask: Task {
242243
}
243244
}
244245

246+
enum ReleaseDrafterLabel: String {
247+
case breakingChanges = "feat!"
248+
case newFeatures = "feat"
249+
case bugFixes = "fix"
250+
case maintenanceRefactor = "refactor"
251+
case maintenanceDocs = "docs"
252+
}
253+
245254
static func pullRequest(with message: String) throws {
246255
try version()
256+
var label: String?
257+
if message.hasPrefix(ReleaseDrafterLabel.breakingChanges.rawValue) {
258+
label = ReleaseDrafterLabel.breakingChanges.rawValue
259+
} else if message.hasPrefix(ReleaseDrafterLabel.newFeatures.rawValue) {
260+
label = ReleaseDrafterLabel.newFeatures.rawValue
261+
} else if message.hasPrefix(ReleaseDrafterLabel.bugFixes.rawValue) {
262+
label = ReleaseDrafterLabel.bugFixes.rawValue
263+
} else if message.hasPrefix(ReleaseDrafterLabel.maintenanceRefactor.rawValue) {
264+
label = ReleaseDrafterLabel.maintenanceRefactor.rawValue
265+
} else if message.hasPrefix(ReleaseDrafterLabel.maintenanceDocs.rawValue) {
266+
label = ReleaseDrafterLabel.maintenanceDocs.rawValue
267+
}
247268
guard HubTask(arguments: [
248269
"pull-request",
249270
"--base", "leancloud:master",
250271
"--message", message,
251-
"--force", "--push", "--browse"])
272+
"--force", "--push", "--browse"]
273+
+ (label != nil ? ["--labels", label!] : []))
252274
.excute() else {
253275
throw TaskError()
254276
}

0 commit comments

Comments
 (0)