Skip to content

Commit

Permalink
feat: PPT-1329: Added methods for rest-api repositories endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis committed Jun 24, 2024
1 parent 12c89a7 commit 53ecbc4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/placeos-frontend-loader/api/remotes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,25 @@ module PlaceOS::FrontendLoader::Api
repo = GitRepository.new(repository_url, username, password)
repo.tags.keys
end

# lists the drivers in a repository
@[AC::Route::GET("/:repository_url/drivers")]
def drivers(
@[AC::Param::Info(description: "the branch to grab commits from", example: "main")]
branch : String? = nil
) : Array(String)
repo = GitRepository.new(repository_url, username, password)
branch = branch || repo.default_branch
repo.file_list(ref: branch, path: "drivers/").select do |file|
file.ends_with?(".cr") && !file.ends_with?("_spec.cr") && !file.includes?("models")
end
end

# returns the default branch of the specified repository
@[AC::Route::GET("/:repository_url/default_branch")]
def default_branch : String
repo = GitRepository.new(repository_url, username, password)
repo.default_branch
end
end
end
23 changes: 23 additions & 0 deletions src/placeos-frontend-loader/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,29 @@ module PlaceOS::FrontendLoader
Array(String).from_json(response.body)
end

# List of drivers in a repository
def drivers(repository_url : String, branch : String? = nil, username : String? = nil, password : String? = nil)
encoded_url = URI.encode_www_form(repository_url)
params = URI::Params.build do |form|
form.add("username", username.to_s) if username.presence
form.add("password", password.to_s) if password.presence
form.add("branch", branch.to_s) if branch.presence
end
response = get("/remotes/#{encoded_url}/drivers?#{params}")
Array(String).from_json(response.body)
end

# Repository default branch
def default_branch(repository_url : String, username : String? = nil, password : String? = nil)
encoded_url = URI.encode_www_form(repository_url)
params = URI::Params.build do |form|
form.add("username", username.to_s) if username.presence
form.add("password", password.to_s) if password.presence
end
response = get("/remotes/#{encoded_url}/default_branch?#{params}")
response.body
end

###########################################################################

def initialize(
Expand Down

0 comments on commit 53ecbc4

Please sign in to comment.