Skip to content

Commit

Permalink
got local scanner working
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Feb 21, 2020
1 parent d62a93d commit f596219
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
46 changes: 44 additions & 2 deletions Sources/ActionStatusCommon/RepoSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,61 @@ class RepoSet: ObservableObject {

DispatchQueue.main.async {
print("Completed Refresh")
self.items = reloaded
var included: [Repo] = []
let remainingIDs = Set<String>(self.items.map({ $0.id.uuidString }))
let reloadedToUse = reloaded.filter({ remainingIDs.contains($0.id.uuidString)})
self.items = reloadedToUse
self.block?()
self.scheduleRefresh(after: 10.0)
}
}
}

func addRepo() -> Repo {
@discardableResult func addRepo() -> Repo {
let repo = Repo()
items.append(repo)
return repo
}

@discardableResult func addRepo(name: String, owner: String) -> Repo {
let repo = Repo(name, owner: owner, workflow: "Tests")
items.append(repo)
return repo
}

func add(fromFolders urls: [URL]) {
if let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) {
let fm = FileManager.default
for url in urls {
if let enumerator = fm.enumerator(at: url, includingPropertiesForKeys: []) {
while let url = enumerator.nextObject() as? URL {
if url.lastPathComponent == ".git" {
add(fromGitRepo: url, detector: detector)
}
}
}
}
}
}

func add(fromGitRepo url: URL, detector: NSDataDetector) {
if let config = try? String(contentsOf: url.appendingPathComponent("config")) {
let tweaked = config.replacingOccurrences(of: "[email protected]:", with: "https://github.com/")
let range = NSRange(location: 0, length: tweaked.count)
for result in detector.matches(in: tweaked, options: [], range: range) {
if let url = result.url, url.scheme == "https", url.host == "github.com" {
let name = url.deletingPathExtension().lastPathComponent
let owner = url.deletingLastPathComponent().lastPathComponent
let existing = items.filter({ $0.name == name && $0.owner == owner })
if existing.count == 0 {
addRepo(name: name, owner: owner)
}
}
}
}
}


func remove(repo: Repo) {
if let index = items.firstIndex(of: repo) {
var updated = items
Expand Down
4 changes: 2 additions & 2 deletions Sources/ActionStatusCommon/Resources/BuildNumber.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BUILD_NUMBER = 83
BUILD_COMMIT = edca550422e479763147453346af24f05cc4b559
BUILD_NUMBER = 84
BUILD_COMMIT = d62a93d35d4ce01d1a109e15e37cacb6f39744b4
41 changes: 1 addition & 40 deletions Sources/ActionStatusMobile/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,10 @@ class AppDelegate: AppCommon {

@IBAction func addLocalRepos() {
pickFilesToOpen(types: ["public.folder"]) { urls in


let fm = FileManager.default
for url in urls {
if
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue),
let items = try? fm.contentsOfDirectory(at: url, includingPropertiesForKeys: [], options: []) {
for item in items {
if item.lastPathComponent == ".git" {
print(item.deletingLastPathComponent())
if let config = try? String(contentsOf: item.appendingPathComponent("config")) {
let tweaked = config.replacingOccurrences(of: "[email protected]:", with: "https://github.com/")
let range = NSRange(location: 0, length: tweaked.count)
for result in detector.matches(in: tweaked, options: [], range: range) {
if let url = result.url, url.scheme == "https", url.host == "github.com" {
let repo = url.deletingPathExtension().lastPathComponent
let owner = url.deletingLastPathComponent().lastPathComponent
self.addRepo(name: repo, owner: owner)
}
}
// let lines = config.split(separator: "\n").filter({ $0.contains("github.com") })
// for line in lines {
// if line.contains("[email protected]:") {
// let spec = line.split(separator: ":")[1].split(separator: "/")
// self.addRepo(name: String(spec[0]), owner: String(spec[1]))
// } else if line.contains("https://github.com/") {
// let spec = line.split(separator: "/")
// self.addRepo(name: String(spec[3]), owner: String(spec[4]))
// }
// }
}
}
}
}
}
self.repos.add(fromFolders: urls)
}
}

func addRepo(name: String, owner: String) {
print(name)
print(owner)
}

class CustomPicker: UIDocumentPickerViewController, UIDocumentPickerDelegate {
typealias Completion = ([URL]) -> Void

Expand Down

0 comments on commit f596219

Please sign in to comment.