Skip to content

Commit

Permalink
Feature: Add support for fetching repository mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
nanashili committed Jul 16, 2024
1 parent 3fe6da2 commit 991824f
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 52 deletions.
24 changes: 15 additions & 9 deletions Sources/Version-Control/Base/Commands/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public struct Config {
name: String,
onlyLocal: Bool = false) throws -> String? {
return try getConfigValueInPath(name: name,
path: String(contentsOf: directoryURL),
path: directoryURL,
onlyLocal: onlyLocal,
type: nil)
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public struct Config {
/// - If `onlyLocal` is `true`, the global configuration is not considered.
/// - The `type` parameter is optional and can be used to specify the expected type of the configuration value.
public func getConfigValueInPath(name: String,
path: String?,
path: URL?,
onlyLocal: Bool = false,
type: Any?) throws -> String? {

Expand All @@ -201,15 +201,21 @@ public struct Config {

flags.append(name)

if let path = path {
gitCommand = "cd \(path.escapedWhiteSpaces()); git \(flags)"
} else {
gitCommand = "git \(flags)"
}
let result = try GitShell().git(
args: flags,
path: path ?? URL(string: "")!,
name: #function,
options: IGitExecutionOptions(
successExitCodes: Set([0, 1])
)
)

let result = try ShellClient.live().run(gitCommand)
// Git exits with 1 if the value isn't found. That's OK.
if (result.exitCode == 1) {
return nil
}

let output = result
let output = result.stdout
let pieces = output.split(separator: "\0")
return pieces[0].description
}
Expand Down
19 changes: 19 additions & 0 deletions Sources/Version-Control/Errors/NetworkingError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,23 @@ public enum NetworkingError: Error {
case invalidResponse
case serverError(statusCode: Int, data: Data)
case encodingFailed(Error)
case customError(message: String)

public var localizedDescription: String {
switch self {
case .invalidURL:
return "The URL provided was invalid."
case .noData:
return "No data was received from the server."
case .invalidResponse:
return "The response received from the server was invalid."
case .serverError(let statusCode, let data):

Check failure on line 26 in Sources/Version-Control/Errors/NetworkingError.swift

View workflow job for this annotation

GitHub Actions / lint

Combine multiple pattern matching bindings by moving keywords out of tuples (pattern_matching_keywords)

Check failure on line 26 in Sources/Version-Control/Errors/NetworkingError.swift

View workflow job for this annotation

GitHub Actions / lint

Combine multiple pattern matching bindings by moving keywords out of tuples (pattern_matching_keywords)
let errorMessage = String(data: data, encoding: .utf8) ?? "Unknown server error"
return "Server error with status code \(statusCode): \(errorMessage)"
case .encodingFailed(let error):
return "Failed to encode parameters: \(error.localizedDescription)"
case .customError(let message):
return message
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct BitBucketAPI {
parameters: requestBody,
completionHandler: { result in
switch result {
case .success(let data):
case .success(let (data, _)):
let decoder = JSONDecoder()
if let fetchedRuleset = try? decoder.decode(IAPIFullRepository.self, from: data) {
completion(fetchedRuleset)
Expand Down Expand Up @@ -73,7 +73,7 @@ struct BitBucketAPI {
parameters: nil,
completionHandler: { result in
switch result {
case .success(let data):
case .success(let (data, _)):
let decoder = JSONDecoder()
if let fetchedRuleset = try? decoder.decode([IAPIIssue].self, from: data) {
completion(fetchedRuleset)
Expand All @@ -100,7 +100,7 @@ struct BitBucketAPI {
path: path!,
method: .GET) { result in
switch result {
case .success(let data):
case .success(let (data, _)):
let decoder = JSONDecoder()
if let fetchedRuleset = try? decoder.decode([IBitBucketAPIPullRequest].self, from: data) {
completion(fetchedRuleset)
Expand Down Expand Up @@ -130,7 +130,7 @@ struct BitBucketAPI {
parameters: nil,
completionHandler: { result in
switch result {
case .success(let data):
case .success(let (data, _)):
let decoder = JSONDecoder()
if let fetchedRuleset = try? decoder.decode(IBitBucketAPIPullRequest.self, from: data) {
completion(fetchedRuleset)
Expand Down Expand Up @@ -160,7 +160,7 @@ struct BitBucketAPI {
parameters: nil,
completionHandler: { result in
switch result {
case .success(let data):
case .success(let (data, _)):
let decoder = JSONDecoder()
if let fetchedRuleset = try? decoder.decode([IAPIComment].self, from: data) {
completion(fetchedRuleset)
Expand Down
Loading

0 comments on commit 991824f

Please sign in to comment.