mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-04-29 04:24:58 +08:00
add gql id decoder from #393
This commit is contained in:
16
Classes/Systems/GraphQLIDDecode.swift
Normal file
16
Classes/Systems/GraphQLIDDecode.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// GraphQLIDDecode.swift
|
||||
// Freetime
|
||||
//
|
||||
// Created by Ryan Nystrom on 9/27/17.
|
||||
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
func GraphQLIDDecode(id: String, separator: String) -> Int? {
|
||||
guard let data = Data(base64Encoded: id, options: [.ignoreUnknownCharacters]),
|
||||
let text = String(data: data, encoding: .utf8)
|
||||
else { return nil }
|
||||
return (text.components(separatedBy: separator).last as NSString?)?.integerValue
|
||||
}
|
||||
@@ -192,6 +192,9 @@
|
||||
2963A9321EE1EBE20066509C /* UIMenuController+Reactions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2963A9311EE1EBE20066509C /* UIMenuController+Reactions.swift */; };
|
||||
2963A9341EE2118E0066509C /* ResponderButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2963A9331EE2118E0066509C /* ResponderButton.swift */; };
|
||||
2963A93B1EE25F6F0066509C /* LabelableFields+IssueLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2963A93A1EE25F6F0066509C /* LabelableFields+IssueLabelModel.swift */; };
|
||||
296B4E311F7C805600C16887 /* GraphQLIDDecode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296B4E301F7C805600C16887 /* GraphQLIDDecode.swift */; };
|
||||
296B4E321F7C80A200C16887 /* GraphQLIDDecode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296B4E301F7C805600C16887 /* GraphQLIDDecode.swift */; };
|
||||
296B4E341F7C80B800C16887 /* GraphQLIDDecodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296B4E331F7C80B800C16887 /* GraphQLIDDecodeTests.swift */; };
|
||||
296CD8291F0141A6001190B9 /* Samples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 296CD8281F0141A6001190B9 /* Samples.swift */; };
|
||||
2971722B1F069E6B005E43AC /* SpinnerSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2971722A1F069E6B005E43AC /* SpinnerSectionController.swift */; };
|
||||
2971722D1F069E96005E43AC /* SpinnerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2971722C1F069E96005E43AC /* SpinnerCell.swift */; };
|
||||
@@ -500,6 +503,8 @@
|
||||
2963A9311EE1EBE20066509C /* UIMenuController+Reactions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIMenuController+Reactions.swift"; sourceTree = "<group>"; };
|
||||
2963A9331EE2118E0066509C /* ResponderButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResponderButton.swift; sourceTree = "<group>"; };
|
||||
2963A93A1EE25F6F0066509C /* LabelableFields+IssueLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "LabelableFields+IssueLabelModel.swift"; sourceTree = "<group>"; };
|
||||
296B4E301F7C805600C16887 /* GraphQLIDDecode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLIDDecode.swift; sourceTree = "<group>"; };
|
||||
296B4E331F7C80B800C16887 /* GraphQLIDDecodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLIDDecodeTests.swift; sourceTree = "<group>"; };
|
||||
296CD8241F014130001190B9 /* _graphql.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = _graphql.json; sourceTree = "<group>"; };
|
||||
296CD8251F014130001190B9 /* _notifications.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = _notifications.json; sourceTree = "<group>"; };
|
||||
296CD8281F0141A6001190B9 /* Samples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Samples.swift; sourceTree = "<group>"; };
|
||||
@@ -1097,6 +1102,7 @@
|
||||
children = (
|
||||
297AE84C1EC0D58A00B44A1F /* DateDisplayTests.swift */,
|
||||
2981A8A61EFEBEF900E25EF1 /* EmojiTests.swift */,
|
||||
296B4E331F7C80B800C16887 /* GraphQLIDDecodeTests.swift */,
|
||||
297AE84E1EC0D58A00B44A1F /* Info.plist */,
|
||||
29A476B11ED24D99005D0953 /* IssueTests.swift */,
|
||||
29C2950D1EC7B43B00D46CD2 /* ListKitTestCase.swift */,
|
||||
@@ -1204,6 +1210,7 @@
|
||||
29316DCC1ECD31E9007CAE3F /* StatusBar.swift */,
|
||||
29416BFC1F118DD700D03E1A /* String+QueryItemValue.swift */,
|
||||
292CD3CF1F0DBB5C00D3D57B /* WebviewCellHeightCache.swift */,
|
||||
296B4E301F7C805600C16887 /* GraphQLIDDecode.swift */,
|
||||
);
|
||||
path = Systems;
|
||||
sourceTree = "<group>";
|
||||
@@ -1889,6 +1896,7 @@
|
||||
2928C78C1F15D80E0000D06D /* IssueRenamedSectionController.swift in Sources */,
|
||||
292FCB1D1EDFCD3D0026635E /* ReactionViewModel.swift in Sources */,
|
||||
2980033E1F51E93500BE90F4 /* RatingSectionController.swift in Sources */,
|
||||
296B4E311F7C805600C16887 /* GraphQLIDDecode.swift in Sources */,
|
||||
294563E61EE4EE6F00DBCD35 /* IssueStatusModel.swift in Sources */,
|
||||
29C9FDE11EC667AE00EE3A52 /* Styles.swift in Sources */,
|
||||
292CD3CC1F0DB89600D3D57B /* IssueReviewSectionController.swift in Sources */,
|
||||
@@ -2102,6 +2110,7 @@
|
||||
292FF8A71F2EA860009E63F7 /* Strings.swift in Sources */,
|
||||
29EDFE7E1F65C688005BCCEB /* SplitPlaceholderViewController.swift in Sources */,
|
||||
293A458D1F296CF300DD1006 /* MMElement+CodeBlock.swift in Sources */,
|
||||
296B4E341F7C80B800C16887 /* GraphQLIDDecodeTests.swift in Sources */,
|
||||
293A45851F296CE200DD1006 /* IssueCommentCodeBlockModel.swift in Sources */,
|
||||
293A45981F298D5700DD1006 /* IssueCommentTableCollectionCell.swift in Sources */,
|
||||
293A459F1F298EED00DD1006 /* IssueCommentHtmlModel.swift in Sources */,
|
||||
@@ -2111,6 +2120,7 @@
|
||||
293A459B1F298E7D00DD1006 /* IssueCommentSummaryModel.swift in Sources */,
|
||||
293A458B1F296CF300DD1006 /* CommentModelsFromMarkdown.swift in Sources */,
|
||||
293A457D1F296BD200DD1006 /* NSAttributedStringSizing.swift in Sources */,
|
||||
296B4E321F7C80A200C16887 /* GraphQLIDDecode.swift in Sources */,
|
||||
293A45791F296B7E00DD1006 /* MMMarkdownASTTests.swift in Sources */,
|
||||
294B11251F7B40CA00E04F2D /* IssueDetailsModel.swift in Sources */,
|
||||
293A45941F296D5B00DD1006 /* CollapsibleCell.swift in Sources */,
|
||||
|
||||
18
FreetimeTests/GraphQLIDDecodeTests.swift
Normal file
18
FreetimeTests/GraphQLIDDecodeTests.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// GraphQLIDDecodeTests.swift
|
||||
// FreetimeTests
|
||||
//
|
||||
// Created by Ryan Nystrom on 9/27/17.
|
||||
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
class GraphQLIDDecodeTests: XCTestCase {
|
||||
|
||||
func test_whenDecodingIssueComment_thatNumberReturned() {
|
||||
let result = GraphQLIDDecode(id: "MDEyOklzc3VlQ29tbWVudDMzMTY2OTI5OA==", separator: "IssueComment")
|
||||
XCTAssertEqual(result, 331669298)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user