diff --git a/src/repositories/commits.jl b/src/repositories/commits.jl index 5c6f144..adb45f2 100644 --- a/src/repositories/commits.jl +++ b/src/repositories/commits.jl @@ -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 diff --git a/test/read_only_api_tests.jl b/test/read_only_api_tests.jl index bd9b33f..15334b6 100644 --- a/test/read_only_api_tests.jl +++ b/test/read_only_api_tests.jl @@ -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)) @@ -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")