diff --git a/Project.toml b/Project.toml index 4c8a209..a383216 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GitForge" uuid = "8f6bce27-0656-5410-875b-07a5572985df" authors = ["Chris de Graaf "] -version = "0.2.5" +version = "0.2.6" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/api.jl b/src/api.jl index f07872c..464ad08 100644 --- a/src/api.jl +++ b/src/api.jl @@ -72,6 +72,20 @@ Get a branch from a repository. """ @endpoint get_branch(owner::AStr, repo::AStr, branch::AStr) +""" + get_branches(::Forge, owner::AbstractString, repo::AbstractString) + +Get all branches for a repository. +""" +@endpoint get_branches(owner::AStr, repo::AStr) + +""" + delete_branch(::Forge, owner::AbstractString, repo::AbstractString, branch::AbstractString) + +Delete a branch from a repository. +""" +@endpoint delete_branch(owner::AStr, repo::AStr, branch::AStr) + """ get_file_contents( ::Forge, diff --git a/src/forges/GitHub/branches.jl b/src/forges/GitHub/branches.jl index f26f1cb..634928d 100644 --- a/src/forges/GitHub/branches.jl +++ b/src/forges/GitHub/branches.jl @@ -25,3 +25,29 @@ end endpoint(::GitHubAPI, ::typeof(get_branch), owner::AStr, repo::AStr, branch::AStr) = Endpoint(:GET, "/repos/$owner/$repo/branches/$branch") into(::GitHubAPI, ::typeof(get_branch)) = Branch + +# Get Repository Branches +# https://docs.github.com/en/rest/reference/repos#list-branches +function endpoint( + ::GitHubAPI, + ::typeof(get_branches), + owner::AStr, + repo::AStr, +) + return EndPoint(:GET, "repos/$owner/$repo/branches") +end +into(::GitHubAPI, ::typeof(get_branches)) = Vector{Branch} + +# Delete Branch (Delete Reference) +# https://docs.github.com/en/rest/reference/git#delete-a-reference +# The :ref in the URL must be formatted as heads/ for branches +function endpoint( + ::GitHubAPI, + ::typeof(delete_branch), + owner::AStr, + repo::AStr, + branch::AStr, +) + return Endpoint(:DELETE, "/repos/$owner/$repo/git/refs/heads/$branch") +end +postprocessor(::GitHubAPI, ::typeof(delete_branch)) = DoNothing diff --git a/src/forges/GitLab/branches.jl b/src/forges/GitLab/branches.jl index 2f7bf08..08ff9e9 100644 --- a/src/forges/GitLab/branches.jl +++ b/src/forges/GitLab/branches.jl @@ -6,9 +6,39 @@ developers_can_push::Bool developers_can_merge::Bool can_push::Bool + web_url::String commit::Commit end endpoint(::GitLabAPI, ::typeof(get_branch), owner::AStr, repo::AStr, branch::AStr) = Endpoint(:GET, "/projects/$(encode(owner, repo))/repository/branches/$branch") into(::GitLabAPI, ::typeof(get_branch)) = Branch + + +# Get Repository Branches +# https://docs.gitlab.com/ee/api/branches.html#list-repository-branches +function endpoint( + ::GitLabAPI, + ::typeof(get_branches), + owner::AStr, + repo::AStr, +) + return Endpoint(:GET, "/projects/$(encode(owner, repo))/repository/branches") +end +into(::GitLabAPI, ::typeof(get_branches)) = Vector{Branch} + +# Delete Branch +# https://docs.gitlab.com/ee/api/branches.html#delete-repository-branch +function endpoint( + ::GitLabAPI, + ::typeof(delete_branch), + owner::AStr, + repo::AStr, + branch::AStr, +) + return Endpoint( + :DELETE, + "/projects/$(encode(owner, repo))/repository/branches/$(encode(branch))", + ) +end +postprocessor(::GitLabAPI, ::typeof(delete_branch)) = DoNothing diff --git a/src/forges/GitLab/merge_requests.jl b/src/forges/GitLab/merge_requests.jl index 5332fd2..dfe522f 100644 --- a/src/forges/GitLab/merge_requests.jl +++ b/src/forges/GitLab/merge_requests.jl @@ -88,6 +88,8 @@ endpoint(::GitLabAPI, ::typeof(unsubscribe_from_pull_request), project::Integer, Endpoint(:POST, "/projects/$project/merge_requests/$pull_request_id/unsubscribe") into(::GitLabAPI, ::typeof(unsubscribe_from_pull_request)) = MergeRequest +endpoint(::GitLabAPI, ::typeof(get_pull_requests), owner::AStr, repo::AStr) = + Endpoint(:GET, "/projects/$(encode(owner, repo))/merge_requests") endpoint(::GitLabAPI, ::typeof(get_pull_requests), project::Integer) = Endpoint(:GET, "/projects/$project/merge_requests") into(::GitLabAPI, ::typeof(get_pull_requests)) = Vector{MergeRequest}