Skip to content

Commit 991824f

Browse files
committed
Feature: Add support for fetching repository mentions
1 parent 3fe6da2 commit 991824f

File tree

6 files changed

+248
-52
lines changed

6 files changed

+248
-52
lines changed

Sources/Version-Control/Base/Commands/Config.swift

+15-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public struct Config {
5555
name: String,
5656
onlyLocal: Bool = false) throws -> String? {
5757
return try getConfigValueInPath(name: name,
58-
path: String(contentsOf: directoryURL),
58+
path: directoryURL,
5959
onlyLocal: onlyLocal,
6060
type: nil)
6161
}
@@ -181,7 +181,7 @@ public struct Config {
181181
/// - If `onlyLocal` is `true`, the global configuration is not considered.
182182
/// - The `type` parameter is optional and can be used to specify the expected type of the configuration value.
183183
public func getConfigValueInPath(name: String,
184-
path: String?,
184+
path: URL?,
185185
onlyLocal: Bool = false,
186186
type: Any?) throws -> String? {
187187

@@ -201,15 +201,21 @@ public struct Config {
201201

202202
flags.append(name)
203203

204-
if let path = path {
205-
gitCommand = "cd \(path.escapedWhiteSpaces()); git \(flags)"
206-
} else {
207-
gitCommand = "git \(flags)"
208-
}
204+
let result = try GitShell().git(
205+
args: flags,
206+
path: path ?? URL(string: "")!,
207+
name: #function,
208+
options: IGitExecutionOptions(
209+
successExitCodes: Set([0, 1])
210+
)
211+
)
209212

210-
let result = try ShellClient.live().run(gitCommand)
213+
// Git exits with 1 if the value isn't found. That's OK.
214+
if (result.exitCode == 1) {
215+
return nil
216+
}
211217

212-
let output = result
218+
let output = result.stdout
213219
let pieces = output.split(separator: "\0")
214220
return pieces[0].description
215221
}

Sources/Version-Control/Errors/NetworkingError.swift

+19
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,23 @@ public enum NetworkingError: Error {
1313
case invalidResponse
1414
case serverError(statusCode: Int, data: Data)
1515
case encodingFailed(Error)
16+
case customError(message: String)
17+
18+
public var localizedDescription: String {
19+
switch self {
20+
case .invalidURL:
21+
return "The URL provided was invalid."
22+
case .noData:
23+
return "No data was received from the server."
24+
case .invalidResponse:
25+
return "The response received from the server was invalid."
26+
case .serverError(let statusCode, let data):
27+
let errorMessage = String(data: data, encoding: .utf8) ?? "Unknown server error"
28+
return "Server error with status code \(statusCode): \(errorMessage)"
29+
case .encodingFailed(let error):
30+
return "Failed to encode parameters: \(error.localizedDescription)"
31+
case .customError(let message):
32+
return message
33+
}
34+
}
1635
}

Sources/Version-Control/Services/API/BitBucket/BitBucketAPI.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct BitBucketAPI {
3434
parameters: requestBody,
3535
completionHandler: { result in
3636
switch result {
37-
case .success(let data):
37+
case .success(let (data, _)):
3838
let decoder = JSONDecoder()
3939
if let fetchedRuleset = try? decoder.decode(IAPIFullRepository.self, from: data) {
4040
completion(fetchedRuleset)
@@ -73,7 +73,7 @@ struct BitBucketAPI {
7373
parameters: nil,
7474
completionHandler: { result in
7575
switch result {
76-
case .success(let data):
76+
case .success(let (data, _)):
7777
let decoder = JSONDecoder()
7878
if let fetchedRuleset = try? decoder.decode([IAPIIssue].self, from: data) {
7979
completion(fetchedRuleset)
@@ -100,7 +100,7 @@ struct BitBucketAPI {
100100
path: path!,
101101
method: .GET) { result in
102102
switch result {
103-
case .success(let data):
103+
case .success(let (data, _)):
104104
let decoder = JSONDecoder()
105105
if let fetchedRuleset = try? decoder.decode([IBitBucketAPIPullRequest].self, from: data) {
106106
completion(fetchedRuleset)
@@ -130,7 +130,7 @@ struct BitBucketAPI {
130130
parameters: nil,
131131
completionHandler: { result in
132132
switch result {
133-
case .success(let data):
133+
case .success(let (data, _)):
134134
let decoder = JSONDecoder()
135135
if let fetchedRuleset = try? decoder.decode(IBitBucketAPIPullRequest.self, from: data) {
136136
completion(fetchedRuleset)
@@ -160,7 +160,7 @@ struct BitBucketAPI {
160160
parameters: nil,
161161
completionHandler: { result in
162162
switch result {
163-
case .success(let data):
163+
case .success(let (data, _)):
164164
let decoder = JSONDecoder()
165165
if let fetchedRuleset = try? decoder.decode([IAPIComment].self, from: data) {
166166
completion(fetchedRuleset)

0 commit comments

Comments
 (0)