Skip to content

Commit

Permalink
Fix commit iteration for PRs, add PR-only method.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Nov 24, 2022
1 parent 0781b9b commit d5e84be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/repositories/commits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@ namefield(commit::Commit) = commit.sha
# API Methods #
###############

@api_default function commits(api::GitHubAPI, repo; options...)
# repo #
#------#

@api_default function commits(api::GitHubAPI, repo::Union{Repo,String}; options...)
results, page_data = gh_get_paged_json(api, "/repos/$(name(repo))/commits"; options...)
return map(Commit, results), page_data
end

@api_default function commit(api::GitHubAPI, repo, sha; options...)
@api_default function commit(api::GitHubAPI, repo, sha::Union{Commit,String}; options...)
result = gh_get_json(api, "/repos/$(name(repo))/commits/$(name(sha))"; options...)
return Commit(result)
end

# pull request #
#--------------#

@api_default function commits(api::GitHubAPI, pr; options...)
repo = pr.base.repo
results, page_data = gh_get_paged_json(api, "/repos/$(name(repo))/pulls/$(name(pr))/commits"; options...)
return map(Commit, results), page_data
end

@api_default function commits(api::GitHubAPI, repo, pr; options...)
results, page_data = gh_get_paged_json(api, "/repos/$(name(repo))/pulls/$(name(pr))/commits"; options...)
return map(Commit, results), page_data
Expand Down
22 changes: 18 additions & 4 deletions test/read_only_api_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ end
@test name(branch(ghjl, "master"; auth = auth)) == "master"
@test hasghobj("master", first(branches(ghjl; auth = auth)))

# test GitHub.commit, GitHub.commits
@test name(commit(ghjl, testcommit; auth = auth)) == name(testcommit)
@test hasghobj(testcommit, first(commits(ghjl; auth = auth)))

# test GitHub.file, GitHub.directory, GitHub.readme, GitHub.permalink
readme_file = file(ghjl, "README.md"; auth = auth)
src_dir = first(directory(ghjl, "src"; auth = auth))
Expand Down Expand Up @@ -106,6 +102,24 @@ end
# @test iscollaborator(ghjl, "jrevels"; auth = auth)
end

@testset "Commits" begin
# of a repo
@test name(commit(ghjl, testcommit; auth = auth)) == name(testcommit)
@test hasghobj(testcommit, first(commits(ghjl; auth = auth)))

# of a pull request
let pr = pull_request(ghjl, 37; auth = auth)
commit_vec, page_data = commits(pr)
@test commit_vec isa Vector{Commit}
@test length(commit_vec) == 1
end
let
commit_vec, page_data = commits(ghjl, 37)
@test commit_vec isa Vector{Commit}
@test length(commit_vec) == 1
end
end

@testset "Issues" begin
state_param = Dict("state" => "all")

Expand Down

0 comments on commit d5e84be

Please sign in to comment.