Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Sep 28, 2022
1 parent d3f8fa6 commit c196d32
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions JiraBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ extension AppDelegate {
}
}
}
else {
self.statusBarItem.button?.title = String(0)
}

self.menu.addItem(.separator())
let refreshItem = NSMenuItem(title: "Refresh", action: #selector(self.refreshMenu), keyEquivalent: "")
Expand Down
2 changes: 1 addition & 1 deletion JiraBar/Extensions/DefaultsExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Defaults
extension Defaults.Keys {
static let jiraUsername = Key<String>("jiraUsername", default: "")

static let jiraHost = Key<String>("jiraHost", default: "")
static let jiraHost = Key<String>("jiraHost", default: "https://issues.apache.org/jira")
static let jql = Key<String>("jql", default: "")

static let refreshRate = Key<Int>("refreshRate", default: 5)
Expand Down
32 changes: 22 additions & 10 deletions JiraBar/Jira/JiraClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import KeychainAccess

public class JiraClient {
@Default(.jiraUsername) var jiraUsername
// @Default(.jiraToken) var jiraToken
@Default(.jiraHost) var jiraHost
@Default(.jql) var jql
@Default(.maxResults) var maxResults
Expand All @@ -21,10 +20,14 @@ public class JiraClient {
"fields":"id,assignee,summary,status,issuetype,project",
"maxResults": maxResults
]
let headers: HTTPHeaders = [
.authorization(username: jiraUsername, password: jiraToken),
var headers: HTTPHeaders = [
.accept("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
}

AF.request(url, method: .get, parameters: parameters, headers: headers)
.validate(statusCode: 200..<300)
.responseDecodable(of: JiraResponse.self) { response in
Expand All @@ -42,12 +45,15 @@ public class JiraClient {
func getTransitionsByIssueKey(issueKey: String, completion: @escaping (([Transition]) -> Void)) -> Void {
let url = "\(jiraHost)/rest/api/2/issue/\(issueKey)/transitions"

let headers: HTTPHeaders = [
.authorization(username: jiraUsername, password: jiraToken),
var headers: HTTPHeaders = [
.accept("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
}

AF.request(url, method: .get, parameters: nil, headers: headers)
AF.request(url, method: .get, parameters: nil, headers: (!jiraUsername.isEmpty && !jiraToken.isEmpty) ? headers : nil)
.validate(statusCode: 200..<300)
.responseDecodable(of: TransitionsResponse.self) { response in
switch response.result {
Expand All @@ -69,12 +75,15 @@ public class JiraClient {
]
]

let headers: HTTPHeaders = [
.authorization(username: jiraUsername, password: jiraToken),
var headers: HTTPHeaders = [
.accept("application/json"),
.contentType("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
}

AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
.validate(statusCode: 200..<300)
.responseJSON { response in
Expand All @@ -94,10 +103,13 @@ public class JiraClient {
func getMyself(completion: @escaping(User?) -> Void) {
let url = "\(jiraHost)/rest/api/2/myself"

let headers: HTTPHeaders = [
.authorization(username: jiraUsername, password: jiraToken),
var headers: HTTPHeaders = [
.accept("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
}

AF.request(url, method: .get, parameters: nil, headers: headers)
.validate(statusCode: 200..<300)
Expand Down

0 comments on commit c196d32

Please sign in to comment.