Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add swiftlint pipeline #22

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: SwiftLint

on:
pull_request:
paths:
- '.github/workflows/swiftlint.yml'
- '.swiftlint.yml'
- '**/*.swift'

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: GitHub Action for SwiftLint
uses: norio-nomura/[email protected]
- name: GitHub Action for SwiftLint (Only files changed in the PR)
uses: norio-nomura/[email protected]
env:
DIFF_BASE: ${{ github.base_ref }}
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.8
9 changes: 9 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# format options

--allman false
--indent 2
--importgrouping testable-bottom

# rules

--enable isEmpty
3 changes: 2 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
indentation_width: 4
indentation_width: 2
indentation_style: tabs
cyclomatic_complexity:
warning: 5
error: 7
Expand Down
10 changes: 4 additions & 6 deletions BudgetMeApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
true
}
}
12 changes: 6 additions & 6 deletions BudgetMeApp/Constants/STEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import Foundation

/// Environment to be used for testing/debugging and production
enum STEnvironment {
#if DEBUG
#if DEBUG
static let environment = STEnvironment.sandbox
#else
#else
static let environment = STEnvironment.production
#endif
#endif

static let sandbox = URL(string: "https://api-sandbox.starlingbank.com/api/v2")!
static let production = URL(string: "https://api.starlingbank.com/api/v2")!
static let sandbox = URL(string: "https://api-sandbox.starlingbank.com/api/v2")!
static let production = URL(string: "https://api.starlingbank.com/api/v2")!
}

enum Constants {
static let auth = URL(string: "https://api-sandbox.starlingbank.com/oauth/access-token")!
static let auth = URL(string: "https://api-sandbox.starlingbank.com/oauth/access-token")!
}
40 changes: 20 additions & 20 deletions BudgetMeApp/Constants/SpendingCategoryFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@
import Foundation

enum SpendingCategoryFactory {
static func makeSpendingCategory(spendingCategory: SpendingCategory) -> SpendingCategoryImage {
switch spendingCategory {
case .TRAVEL: return TravelSC()
case .REVENUE: return RevenueSC()
case .OTHER: return OtherSC()
default: return DefaultSC()
}
static func makeSpendingCategory(spendingCategory: SpendingCategory) -> SpendingCategoryImage {
switch spendingCategory {
case .TRAVEL: return TravelSC()
case .REVENUE: return RevenueSC()
case .OTHER: return OtherSC()
default: return DefaultSC()
}
}
}

protocol SpendingCategoryImage {
var categoryImage: String { get }
var categoryImage: String { get }
}

private struct RevenueSC: SpendingCategoryImage {
var categoryImage: String {
"sterlingsign.circle.fill"
}
var categoryImage: String {
"sterlingsign.circle.fill"
}
}

private struct OtherSC: SpendingCategoryImage {
var categoryImage: String {
"pencil.and.ellipsis.rectangle"
}
var categoryImage: String {
"pencil.and.ellipsis.rectangle"
}
}

private struct TravelSC: SpendingCategoryImage {
var categoryImage: String {
"airplane"
}
var categoryImage: String {
"airplane"
}
}

private struct DefaultSC: SpendingCategoryImage {
var categoryImage: String {
"bag"
}
var categoryImage: String {
"bag"
}
}
110 changes: 54 additions & 56 deletions BudgetMeApp/Constants/UserDefault+PropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,80 @@
import Foundation

struct UserDefaultsConfig {
@UserDefault("token", defaultValue: "")
static var token: String
@UserDefault("token", defaultValue: "")
static var token: String

@UserDefault("refreshToken", defaultValue: "")
static var refreshToken: String
@UserDefault("refreshToken", defaultValue: "")
static var refreshToken: String

@UserDefault("clientId", defaultValue: "")
static var clientId: String
@UserDefault("clientId", defaultValue: "")
static var clientId: String

@UserDefault("clientSecret", defaultValue: "")
static var clientSecret: String
@UserDefault("clientSecret", defaultValue: "")
static var clientSecret: String
}

@propertyWrapper
struct UserDefault<T> {
let key: String
let defaultValue: T
let key: String
let defaultValue: T

init(_ key: String, defaultValue: T) {
self.key = key
self.defaultValue = defaultValue
}
init(_ key: String, defaultValue: T) {
self.key = key
self.defaultValue = defaultValue
}

var wrappedValue: T {
get {
return UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
}
set {
UserDefaults.standard.set(newValue, forKey: key)
}
var wrappedValue: T {
get {
UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
}
set {
UserDefaults.standard.set(newValue, forKey: key)
}
}
}

extension UserDefaults {
public enum Keys {
static let token = "token"
static let refreshToken = "refreshToken"
static let clientId = "clientId"
static let clientSecret = "clientSecret"
}

public enum Keys {
static let token = "token"
static let refreshToken = "refreshToken"
static let clientId = "clientId"
static let clientSecret = "clientSecret"
var token: String {
set {
set(newValue, forKey: Keys.token)
}

var token: String {
set {
set(newValue, forKey: Keys.token)
}
get {
return string(forKey: Keys.token) ?? ""
}
get {
string(forKey: Keys.token) ?? ""
}
}

var refreshToken: String {
set {
set(newValue, forKey: Keys.refreshToken)
}
get {
return string(forKey: Keys.refreshToken) ?? ""
}
var refreshToken: String {
set {
set(newValue, forKey: Keys.refreshToken)
}

var clientId: String {
set {
set(newValue, forKey: Keys.clientId)
}
get {
return string(forKey: Keys.clientId) ?? ""
}
get {
string(forKey: Keys.refreshToken) ?? ""
}
}

var clientSecret: String {
set {
set(newValue, forKey: Keys.clientSecret)
}
get {
return string(forKey: Keys.clientSecret) ?? ""
}
var clientId: String {
set {
set(newValue, forKey: Keys.clientId)
}
get {
string(forKey: Keys.clientId) ?? ""
}
}

var clientSecret: String {
set {
set(newValue, forKey: Keys.clientSecret)
}
get {
string(forKey: Keys.clientSecret) ?? ""
}
}
}
95 changes: 45 additions & 50 deletions BudgetMeApp/Controller/Accounts/AccountsViewController+Alerts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,66 @@
import UIKit

extension AccountsViewController {

func performDownloadPDF(yearMonth: String) {
self.viewModel.downloadPDFStatement(accountId: Session.shared.accountId, yearMonth: yearMonth)
.subscribe { event in
switch event {
case .completed:
self.showSuccessAlert()
case .error(let error):
self.viewModel.errorPublisher.onNext(error)
}
func performDownloadPDF(yearMonth: String) {
viewModel.downloadPDFStatement(accountId: Session.shared.accountId, yearMonth: yearMonth)
.subscribe { event in
switch event {
case .completed:
self.showSuccessAlert()
case let .error(error):
self.viewModel.errorPublisher.onNext(error)
}
.disposed(by: self.disposeBag)
}

func performDownloadCSV(yearMonth: String) {
self.viewModel.downloadCSVStatement(accountId: Session.shared.accountId, yearMonth: yearMonth)
.subscribe { event in
switch event {
case .completed:
self.showSuccessAlert()
case .error(let error):
self.viewModel.errorPublisher.onNext(error)
}
}
.disposed(by: disposeBag)
}

func performDownloadCSV(yearMonth: String) {
viewModel.downloadCSVStatement(accountId: Session.shared.accountId, yearMonth: yearMonth)
.subscribe { event in
switch event {
case .completed:
self.showSuccessAlert()
case let .error(error):
self.viewModel.errorPublisher.onNext(error)
}
.disposed(by: self.disposeBag)
}

func presentDownloadAlert() {
}
.disposed(by: disposeBag)
}

let alert = UIAlertController(title: "Select file type for statement", message: "", preferredStyle: .alert)
func presentDownloadAlert() {
let alert = UIAlertController(title: "Select file type for statement", message: "", preferredStyle: .alert)

let pdfAction = UIAlertAction(title: "PDF", style: .default, handler: { _ in
let pdfAction = UIAlertAction(title: "PDF", style: .default, handler: { _ in

let yearMonth = alert.textFields![0].text!
self.performDownloadPDF(yearMonth: yearMonth)
let yearMonth = alert.textFields![0].text!
self.performDownloadPDF(yearMonth: yearMonth)

})
})

let csvAction = UIAlertAction(title: "CSV", style: .default, handler: { _ in
let csvAction = UIAlertAction(title: "CSV", style: .default, handler: { _ in

let yearMonth = alert.textFields![0].text!
self.performDownloadCSV(yearMonth: yearMonth)
let yearMonth = alert.textFields![0].text!
self.performDownloadCSV(yearMonth: yearMonth)

})
})

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

alert.addAction(pdfAction)
alert.addAction(csvAction)

alert.addTextField { tf in
tf.placeholder = "e.g. 2020-03"
}

self.present(alert, animated: true, completion: nil)
alert.addAction(pdfAction)
alert.addAction(csvAction)

alert.addTextField { tf in
tf.placeholder = "e.g. 2020-03"
}

func showSuccessAlert() {
present(alert, animated: true, completion: nil)
}

let alert = UIAlertController(title: "Download success", message: "", preferredStyle: .alert)
func showSuccessAlert() {
let alert = UIAlertController(title: "Download success", message: "", preferredStyle: .alert)

alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))

self.present(alert, animated: true, completion: nil)
}
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))

present(alert, animated: true, completion: nil)
}
}
Loading