Skip to content

Commit

Permalink
Add extra branch functions
Browse files Browse the repository at this point in the history
- get_branches
- delete_branch
- Add an "owner/repo" version of get_pull_requests for GitLab
  • Loading branch information
fchorney committed Sep 10, 2021
1 parent 21918e7 commit 1e4ac7b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GitForge"
uuid = "8f6bce27-0656-5410-875b-07a5572985df"
authors = ["Chris de Graaf <me@cdg.dev>"]
version = "0.2.5"
version = "0.2.6"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
14 changes: 14 additions & 0 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions src/forges/GitHub/branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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/<branch name> 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
30 changes: 30 additions & 0 deletions src/forges/GitLab/branches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/forges/GitLab/merge_requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 1e4ac7b

Please sign in to comment.