Skip to content

Commit

Permalink
Merge pull request #32 from JuliaWeb/fc/list-branches
Browse files Browse the repository at this point in the history
Add extra branch functions
  • Loading branch information
fchorney authored Sep 13, 2021
2 parents 21918e7 + 1e4ac7b commit 30b5008
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

2 comments on commit 30b5008

@fchorney
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/44779

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.6 -m "<description of version>" 30b5008e4f98c82b48df22a58b83887d3b7427b0
git push origin v0.2.6

Please sign in to comment.