Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 7 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
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

## OS X files
.DS_Store
.DS_Store?
.Trashes
.Spotlight-V100
*.swp

## Xcode build files
DerivedData/
build/

## Xcode private settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

xcuserdata/

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Swift Package Manager
.build/

Pods/
Podfile.lock
348 changes: 343 additions & 5 deletions GithubIssues.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,59 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D7CE58D91F64118400380CEE"
BuildableName = "GithubIssues.app"
BlueprintName = "GithubIssues"
ReferencedContainer = "container:GithubIssues.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D7CE58ED1F64118400380CEE"
BuildableName = "GithubIssuesTests.xctest"
BlueprintName = "GithubIssuesTests"
ReferencedContainer = "container:GithubIssues.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D7CE58F81F64118400380CEE"
BuildableName = "GithubIssuesUITests.xctest"
BlueprintName = "GithubIssuesUITests"
ReferencedContainer = "container:GithubIssues.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D7CE58D91F64118400380CEE"
BuildableName = "GithubIssues.app"
BlueprintName = "GithubIssues"
ReferencedContainer = "container:GithubIssues.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand All @@ -26,6 +71,16 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D7CE58D91F64118400380CEE"
BuildableName = "GithubIssues.app"
BlueprintName = "GithubIssues"
ReferencedContainer = "container:GithubIssues.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -35,6 +90,16 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D7CE58D91F64118400380CEE"
BuildableName = "GithubIssues.app"
BlueprintName = "GithubIssues"
ReferencedContainer = "container:GithubIssues.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
10 changes: 10 additions & 0 deletions GithubIssues.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Latest</string>
</dict>
</plist>
130 changes: 130 additions & 0 deletions GithubIssues/API.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//
// API.swift
// GithubIssues
//
// Created by Leonard on 2017. 9. 10..
// Copyright © 2017년 intmain. All rights reserved.
//

import Foundation
import Alamofire
import SwiftyJSON


struct API {
static func getOauthKey(user: String, password: String, completionHandler: @escaping (DataResponse<JSON>) -> Void) {
var headers: HTTPHeaders = [:]
if let authorizationHeader = Request.authorizationHeader(user: user, password: password) {
headers[authorizationHeader.key] = authorizationHeader.value
}
let parameters: Parameters = ["client_secret": Router.clientSecret , "scopes": ["public_repo"], "note": "admin script" ]
Alamofire.request(Router.authKey(parameters, headers))
.responseSwiftyJSON { json in
print(json)
completionHandler(json)
}
}

static func repoIssues(owner: String, repo: String, page: Int, completionHandler: @escaping (DataResponse<[Model.Issue]>) -> Void) {
let parameters: Parameters = ["page": page, "state": "all"]
Alamofire.request(Router.repoIssues(owner: owner, repo: repo, parameters: parameters)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
let result = dataResponse.map({ (json: JSON) -> [Model.Issue] in
return json.arrayValue.map{
Model.Issue(json: $0)
}
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭔가 좀더 간단히 할 수 있을 것 같은데..

let result = dataResponse.map { $0.arrayValue }.map { Model.Issue(json: $0) }

completionHandler(result)
}
}

typealias IssueResponsesHandler = (DataResponse<[Model.Issue]>) -> Void
static func repoIssues(owner: String, repo: String) -> (Int, @escaping IssueResponsesHandler) -> Void {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typealias는 class 밖에 있는게 더 읽기 편할듯?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API. IssueResponsesHandler 보다 IssueResponsesHandler가 나아보이나요?


return { (page: Int, handler: @escaping IssueResponsesHandler) in
let parameters: Parameters = ["page": page, "state": "all"]
Alamofire.request(Router.repoIssues(owner: owner, repo: repo, parameters: parameters)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
let result = dataResponse.map({ (json: JSON) -> [Model.Issue] in
return json.arrayValue.map{
Model.Issue(json: $0)
}
})
handler(result)
}
}
}

typealias CommentResponsesHandler = (DataResponse<[Model.Comment]>) -> Void

static func issueComment(owner: String, repo: String, number: Int) -> (Int, @escaping CommentResponsesHandler) -> Void {
return { page, handler in
let parameters: Parameters = ["page": page]
Alamofire.request(Router.issueDetail(owner: owner, repo: repo, number: number, parameters: parameters)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
let result = dataResponse.map({ (json: JSON) -> [Model.Comment] in
return json.arrayValue.map{
Model.Comment(json: $0)
}
})
handler(result)
}
}
}

static func issueDetail(owner: String, repo: String, number: Int, page: Int, completionHandler: @escaping (DataResponse<[Model.Comment]>) -> Void) {
let parameters: Parameters = ["page": page]
Alamofire.request(Router.issueDetail(owner: owner, repo: repo, number: number, parameters: parameters)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
let result = dataResponse.map({ (json: JSON) -> [Model.Comment] in
return json.arrayValue.map{
Model.Comment(json: $0)
}
})
completionHandler(result)
}
}

static func createComment(owner: String, repo: String, number: Int, comment: String, completionHandler: @escaping (DataResponse<Model.Comment>) -> Void ) {
let parameters: Parameters = ["body": comment]
Alamofire.request(Router.createComment(owner: owner, repo: repo, number: number, parameters: parameters)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
let result = dataResponse.map({ (json: JSON) -> Model.Comment in
Model.Comment(json: json)
})
completionHandler(result)
}
}

static func createIssue(owner: String, repo: String, title: String, body: String, completionHandler: @escaping (DataResponse<Model.Issue>) -> Void ) {
let parameters: Parameters = ["title": title, "body": body]
Alamofire.request(Router.createIssue(owner: owner, repo: repo, parameters: parameters)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
print(dataResponse.request?.url?.absoluteString)
let result = dataResponse.map({ (json: JSON) -> Model.Issue in
Model.Issue(json: json)
})
completionHandler(result)
}
}

static func closeIssue(owner: String, repo: String, number: Int, issue: Model.Issue, completionHandler: @escaping (DataResponse<Model.Issue>) -> Void) {
var dict = issue.toDict
dict["state"] = Model.Issue.State.closed.display
Alamofire.request(Router.editIssue(owner: owner, repo: repo, number: number, parameters: dict)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
print(dataResponse.request?.url?.absoluteString)
let result = dataResponse.map({ (json: JSON) -> Model.Issue in
Model.Issue(json: json)
})
completionHandler(result)
}

}

static func openIssue(owner: String, repo: String, number: Int, issue: Model.Issue, completionHandler: @escaping (DataResponse<Model.Issue>) -> Void) {
var dict = issue.toDict
dict["state"] = Model.Issue.State.open.display
Alamofire.request(Router.editIssue(owner: owner, repo: repo, number: number, parameters: dict)).responseSwiftyJSON { (dataResponse: DataResponse<JSON>) in
print(dataResponse.request?.url?.absoluteString)
let result = dataResponse.map({ (json: JSON) -> Model.Issue in
Model.Issue(json: json)
})
completionHandler(result)
}

}
}
10 changes: 10 additions & 0 deletions GithubIssues/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.


if !GlobalState.instance.isLoggedIn {
let loginViewController = LoginViewController.viewController
DispatchQueue.main.asyncAfter(deadline: .now() + 0.0, execute: { [weak self] in
self?.window?.rootViewController?.present(loginViewController, animated: false, completion: nil)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기야 말로 unowned로 써도 되겠네요?
아니면... 이렇게 회피? ㅋㅋㅋ

UIApplication.shared.delegate?.window?.rootViewController?.present(loginViewController, animated: false, completion: nil)

})

}

return true
}

Expand Down
25 changes: 25 additions & 0 deletions GithubIssues/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -59,6 +79,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
6 changes: 6 additions & 0 deletions GithubIssues/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
21 changes: 21 additions & 0 deletions GithubIssues/Assets.xcassets/Octocat.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Octocat.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading