Skip to content

Commit

Permalink
Merge pull request #7 from StefKors/github
Browse files Browse the repository at this point in the history
GitHub Support + Improvements
  • Loading branch information
StefKors authored Nov 1, 2024
2 parents fe3296d + 2a43c6c commit 149241d
Show file tree
Hide file tree
Showing 117 changed files with 4,236 additions and 2,802 deletions.
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@v4
with:
fetch-depth: 4
- name: GitHub Action for SwiftLint with --strict
uses: norio-nomura/action-swiftlint@3.2.1
with:
args: --strict
15 changes: 15 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
disabled_rules:
# Rule identifiers turned on by default to exclude from running
- colon
- comma
- control_statement
# Custom rule identifiers
- line_length
- type_body_length
- todo
- for_where
- file_length
- nesting
- redundant_string_enum_value
- identifier_name
- type_name
28 changes: 0 additions & 28 deletions Approval.swift

This file was deleted.

38 changes: 23 additions & 15 deletions DesktopWidgetTool/DesktopWidgetTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ struct Provider: TimelineProvider {
)
}

init(selectedView: QueryType) {
self.selectedView = selectedView
}

// TODO: demo data? or at placeholder?
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> Void) {
Task { @MainActor in
let now = Date.now

let context = ModelContainer.shared.mainContext

let mergeRequests = (try? context.fetch(FetchDescriptor<MergeRequest>())) ?? []
let mergeRequests = (
try? context.fetch(
FetchDescriptor<UniversalMergeRequest>(
predicate: nil,
sortBy: [.init(\.createdAt, order: .reverse)]
)
)
) ?? []
let accounts = (try? context.fetch(FetchDescriptor<Account>())) ?? []
let repos = (try? context.fetch(FetchDescriptor<LaunchpadRepo>()))?.reversed() ?? []

let entry = SimpleEntry(
date: now,
mergeRequests: mergeRequests, //Array(mergeRequests.prefix(5)),
mergeRequests: mergeRequests, // Array(mergeRequests.prefix(5)),
accounts: accounts,
repos: repos,
selectedView: selectedView
Expand All @@ -50,15 +53,22 @@ struct Provider: TimelineProvider {
}
}

func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> ()) {
func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> Void) {
Task { @MainActor in
var entries: [SimpleEntry] = []

let now = Date.now

let context = ModelContainer.shared.mainContext

let mergeRequests = (try? context.fetch(FetchDescriptor<MergeRequest>())) ?? []
let mergeRequests = (
try? context.fetch(
FetchDescriptor<UniversalMergeRequest>(
predicate: nil,
sortBy: [.init(\.createdAt, order: .reverse)]
)
)
) ?? []
let accounts = (try? context.fetch(FetchDescriptor<Account>())) ?? []
let repos = (try? context.fetch(FetchDescriptor<LaunchpadRepo>()))?.reversed() ?? []

Expand All @@ -69,18 +79,18 @@ struct Provider: TimelineProvider {
// moreRepos.append(contentsOf: repos)
// moreRepos.append(contentsOf: repos)

//let mergeRequests = (
// let mergeRequests = (
// try? context.fetch(
// FetchDescriptor<MergeRequest>(predicate: #Predicate {
// $0.type == type
// })
// )
//) ?? []
// ) ?? []

entries.append(
SimpleEntry(
date: now,
mergeRequests: mergeRequests, //Array(mergeRequests.prefix(5)),
mergeRequests: mergeRequests, // Array(mergeRequests.prefix(5)),
accounts: accounts,
repos: repos,
selectedView: selectedView
Expand All @@ -97,7 +107,7 @@ struct Provider: TimelineProvider {

struct SimpleEntry: TimelineEntry {
let date: Date
let mergeRequests: [MergeRequest]
let mergeRequests: [UniversalMergeRequest]
let accounts: [Account]
let repos: [LaunchpadRepo]
let selectedView: QueryType
Expand Down Expand Up @@ -141,7 +151,6 @@ struct ReviewRequestedMergeRequestWidget: Widget {
}
}


struct LaunchPadWidget: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(kind: "LaunchpadWidget", provider: Provider(selectedView: .authoredMergeRequests)) { entry in
Expand All @@ -155,4 +164,3 @@ struct LaunchPadWidget: Widget {
.supportedFamilies([.systemSmall, .systemMedium])
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI
import WidgetKit

struct LaunchPadWidgetEntryView : View {
struct LaunchPadWidgetEntryView: View {
var entry: Provider.Entry

@Environment(\.widgetFamily) var family
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import SwiftUI

struct MediumLaunchPadWidgetView: View {
let repos: [LaunchpadRepo]

var body: some View {
ViewThatFits {
WrappingHStack {
WidgetLaunchPadRow(repos: repos, length: 10)
}

WrappingHStack {
WidgetLaunchPadRow(repos: repos, length: 9)
}

WrappingHStack {
WidgetLaunchPadRow(repos: repos, length: 8)
}

WrappingHStack {
WidgetLaunchPadRow(repos: repos, length: 7)
}

WrappingHStack {
WidgetLaunchPadRow(repos: repos, length: 6)
}
Expand Down
2 changes: 2 additions & 0 deletions DesktopWidgetTool/LaunchPadWidget/WrappingHStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ public struct WrappingHStack: Layout {

extension WrappingHStack {
struct Row {
// swiftlint:disable:next large_tuple
var elements: [(index: Int, size: CGSize, xOffset: CGFloat)] = []
var yOffset: CGFloat = .zero
var width: CGFloat = .zero
var height: CGFloat = .zero
}

// swiftlint:disable:next function_body_length
private func arrangeRows(proposal: ProposedViewSize,
subviews: Subviews,
cache: inout Cache) -> [Row] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,79 @@
import SwiftUI

struct ExtraLargeMergeRequestWidgetInterface: View {
var mergeRequests: [MergeRequest]
var mergeRequests: [UniversalMergeRequest]
var accounts: [Account]
var repos: [LaunchpadRepo]
var selectedView: QueryType

private var filteredMRs: [UniversalMergeRequest] {
if selectedView == .reviewRequestedMergeRequests {
return mergeRequests.filter { mr in
mr.isApproved == false
}
}

return mergeRequests
}

var body: some View {
VStack(alignment: .leading, spacing: 10) {
ViewThatFits(in: .horizontal) {
WidgetLaunchPadRow(repos: repos, length: 10)
WidgetLaunchPadRow(repos: repos, length: 9)
WidgetLaunchPadRow(repos: repos, length: 8)
WidgetLaunchPadRow(repos: repos, length: 7)
WidgetLaunchPadRow(repos: repos, length: 6)
WidgetLaunchPadRow(repos: repos, length: 5)
WidgetLaunchPadRow(repos: repos, length: 4)
WidgetLaunchPadRow(repos: repos, length: 3)
}
// ViewThatFits(in: .horizontal) {
// WidgetLaunchPadRow(repos: repos, length: 10)
// WidgetLaunchPadRow(repos: repos, length: 9)
// WidgetLaunchPadRow(repos: repos, length: 8)
// WidgetLaunchPadRow(repos: repos, length: 7)
// WidgetLaunchPadRow(repos: repos, length: 6)
// WidgetLaunchPadRow(repos: repos, length: 5)
// WidgetLaunchPadRow(repos: repos, length: 4)
// WidgetLaunchPadRow(repos: repos, length: 3)
// }
//
// Divider()

VStack(alignment: .leading, spacing: 10) {
if selectedView == .reviewRequestedMergeRequests {
ViewThatFits(in: .horizontal, content: {
HStack(alignment: .center, spacing: 6) {
Text(Image(.mergeRequest))
Text("^[\(mergeRequests.count) reviews](inflect: true) requested")
}

HStack(alignment: .center, spacing: 6) {
Text(Image(.mergeRequest))
Text(mergeRequests.count.description)
}
})
}

if selectedView == .authoredMergeRequests {
ViewThatFits(in: .horizontal, content: {
HStack(alignment: .center, spacing: 6) {
Text(Image(.branch))
Text("^[\(mergeRequests.count) merge requests](inflect: true)")
}

HStack(alignment: .center, spacing: 6) {
Text(Image(.branch))
Text(mergeRequests.count.description)
}
})
}

ViewThatFits(in: .vertical) {
MergeRequestList(
mergeRequests: Array(mergeRequests.prefix(9)),
accounts: accounts,
selectedView: selectedView
)
MergeRequestList(
mergeRequests: Array(mergeRequests.prefix(8)),
accounts: accounts,
selectedView: selectedView
)
MergeRequestList(
mergeRequests: Array(mergeRequests.prefix(7)),
accounts: accounts,
selectedView: selectedView
)
MergeRequestList(
mergeRequests: Array(mergeRequests.prefix(6)),
accounts: accounts,
selectedView: selectedView
)
MergeRequestList(
mergeRequests: Array(mergeRequests.prefix(5)),
mergeRequests: Array(filteredMRs.prefix(4)),
accounts: accounts,
selectedView: selectedView
)
}
.frame(alignment: .top)

}
// .fixedSize(horizontal: false, vertical: true)
.frame(alignment: .top)
}
}


#Preview {
ExtraLargeMergeRequestWidgetInterface(
mergeRequests: [.preview, .preview, .preview, .preview],
Expand Down
Loading

0 comments on commit 149241d

Please sign in to comment.