Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public actor ProviderManager {
}
let repoSlug = "\(parsed.org)/\(parsed.repo)"
if parsed.isMR {
output = try await shell(env: env, "glab", "mr", "view", "\(parsed.number)", "--repo", repoSlug)
output = try await shell(env: env, cwd: NSHomeDirectory(), "glab", "mr", "view", "\(parsed.number)", "--repo", repoSlug)
} else {
output = try await shell(env: env, "glab", "issue", "view", "\(parsed.number)", "--repo", repoSlug)
output = try await shell(env: env, cwd: NSHomeDirectory(), "glab", "issue", "view", "\(parsed.number)", "--repo", repoSlug)
}
}

Expand Down Expand Up @@ -122,14 +122,15 @@ public actor ProviderManager {
return output.components(separatedBy: .newlines).first
}

private func shell(env: [String: String] = [:], _ args: String...) async throws -> String {
private func shell(env: [String: String] = [:], cwd: String? = nil, _ args: String...) async throws -> String {
let process = Process()
let pipe = Pipe()
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
process.arguments = args
process.environment = env.isEmpty
? ShellEnvironment.shared.env
: ShellEnvironment.shared.merging(env)
if let cwd { process.currentDirectoryURL = URL(fileURLWithPath: cwd) }
process.standardOutput = pipe
process.standardError = pipe
try process.run()
Expand Down
11 changes: 7 additions & 4 deletions Sources/Crow/App/IssueTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ final class IssueTracker {

let output: String
do {
output = try await shell(env: ["GITLAB_HOST": host], "glab", "api", endpoint)
output = try await shell(env: ["GITLAB_HOST": host], cwd: NSHomeDirectory(), "glab", "api", endpoint)
} catch {
print("[IssueTracker] Reconcile glab api failed for \(candidate.repoSlug)#\(candidate.branch) on \(host): \(error.localizedDescription.prefix(200))")
continue
Expand Down Expand Up @@ -1553,6 +1553,7 @@ final class IssueTracker {
do {
output = try await shell(
env: ["GITLAB_HOST": host],
cwd: NSHomeDirectory(),
"glab", "issue", "list", "-a", "@me", "--output-format", "json"
)
} catch {
Expand Down Expand Up @@ -1736,14 +1737,15 @@ final class IssueTracker {

// MARK: - Shell

private func shell(env: [String: String] = [:], _ args: String...) async throws -> String {
return try await shell(env: env, args: args)
private func shell(env: [String: String] = [:], cwd: String? = nil, _ args: String...) async throws -> String {
return try await shell(env: env, cwd: cwd, args: args)
}

private func shell(env: [String: String] = [:], args: [String]) async throws -> String {
private func shell(env: [String: String] = [:], cwd: String? = nil, args: [String]) async throws -> String {
currentRefreshGhCalls += 1
let args = args
let env = env
let cwd = cwd
return try await Task.detached {
let process = Process()
let outPipe = Pipe()
Expand All @@ -1753,6 +1755,7 @@ final class IssueTracker {
process.environment = env.isEmpty
? ShellEnvironment.shared.env
: ShellEnvironment.shared.merging(env)
if let cwd { process.currentDirectoryURL = URL(fileURLWithPath: cwd) }
process.standardOutput = outPipe
process.standardError = errPipe
try process.run()
Expand Down
Loading