From 48075ed4163ed82f4857eb3ffa644d121274535c Mon Sep 17 00:00:00 2001 From: Paresh Mathur Date: Sun, 24 Oct 2021 13:31:28 +0530 Subject: [PATCH 1/4] add method to get commits from a PR --- README.md | 1 + src/repositories/commits.jl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index fcc6530..22981dd 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API. | `stats(repo, stat[, attempts = 3])` | `HTTP.Response` | [get information on `stat` (e.g. "contributors", "code_frequency", "commit_activity", etc.)](https://developer.github.com/v3/repos/statistics/) | | `commit(repo, sha)` | `Commit` | [get the commit specified by `sha`](https://developer.github.com/v3/repos/commits/#get-a-single-commit) | | `commits(repo)` | `Tuple{Vector{Commit}, Dict}` | [get `repo`'s commits](https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository) | +| `commits(repo, pr)` | `Tuple{Vector{Commit}, Dict}` | [get `pr`'s commits for `repo`](https://docs.github.com/en/rest/reference/pulls#list-commits-on-a-pull-request) | | `branch(repo, branch)` | `Branch` | [get the branch specified by `branch`](https://developer.github.com/v3/repos/#get-branch) | | `branches(repo)` | `Tuple{Vector{Branch}, Dict}` | [get `repo`'s branches](https://developer.github.com/v3/repos/#list-branches) | | `file(repo, path)` | `Content` | [get the file specified by `path`](https://developer.github.com/v3/repos/contents/#get-contents) | diff --git a/src/repositories/commits.jl b/src/repositories/commits.jl index 0f80689..5c6f144 100644 --- a/src/repositories/commits.jl +++ b/src/repositories/commits.jl @@ -34,3 +34,8 @@ end result = gh_get_json(api, "/repos/$(name(repo))/commits/$(name(sha))"; options...) return Commit(result) 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 +end \ No newline at end of file From 0781b9bf558731b040d425358d6b7134b131e7af Mon Sep 17 00:00:00 2001 From: Paresh Mathur Date: Tue, 26 Oct 2021 21:59:56 +0530 Subject: [PATCH 2/4] add documentation about pull request files --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 22981dd..fe841af 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Here's a table that matches up the provided `GitHubType`s with their correspondi | `Label` | name, e.g. `bug` | [issue labels](https://docs.github.com/en/rest/reference/issues#labels) | `Status` | id, e.g. `366961773` | [commit statuses](https://developer.github.com/v3/repos/statuses/) | | `PullRequest` | number, e.g. `44` | [pull requests](https://developer.github.com/v3/pulls/) | +| `PullRequestFile` | filename, e.g. `file1.txt` | [pull request files](https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files) | | `Issue` | number, e.g. `31` | [issues](https://developer.github.com/v3/issues/) | | `Team` | id, e.g. `1` | [teams](https://developer.github.com/v3/orgs/teams) | | `Gist` | id, e.g. `0bace7cc774df4b3a4b0ee9aaa271ef6` | [gists](https://developer.github.com/v3/gists) | @@ -137,6 +138,7 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API. |---------------------------------|------------------------------------|------------------------------------------------------------------------------------------------------------| | `pull_request(repo, pr)` | `PullRequest` | [get the pull request specified by `pr`](https://developer.github.com/v3/pulls/#get-a-single-pull-request) | | `pull_requests(repo)` | `Tuple{Vector{PullRequest}, Dict}` | [get `repo`'s pull requests](https://developer.github.com/v3/pulls/#list-pull-requests) | +| `pull_request_files(repo, pr)` | `Tuple{Vector{PullRequestFiles}, Dict}` | [get this `repo`'s `pr`'s file changes](https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files) | | `create_pull_request(repo)` | `PullRequest` | [create pull request in `repo`](https://developer.github.com/v3/pulls/#create-a-pull-request) | | `update_pull_request(repo, pr)` | `PullRequest` | [update the given `pr` in `repo`](https://developer.github.com/v3/pulls/#update-a-pull-request) | | `close_pull_request(repo, pr)` | `PullRequest` | [close the given `pr` in `repo`](https://developer.github.com/v3/pulls/#update-a-pull-request) | From d5e84be25ef5df9f2a4ad090e02af5f381e489d0 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Nov 2022 10:10:17 +0100 Subject: [PATCH 3/4] Fix commit iteration for PRs, add PR-only method. --- src/repositories/commits.jl | 16 ++++++++++++++-- test/read_only_api_tests.jl | 22 ++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) 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") From 48d810bd34b63c8310996a02c551a3731457d411 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Nov 2022 10:10:57 +0100 Subject: [PATCH 4/4] Add missing auth. --- test/read_only_api_tests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/read_only_api_tests.jl b/test/read_only_api_tests.jl index 15334b6..6c45837 100644 --- a/test/read_only_api_tests.jl +++ b/test/read_only_api_tests.jl @@ -109,12 +109,12 @@ end # of a pull request let pr = pull_request(ghjl, 37; auth = auth) - commit_vec, page_data = commits(pr) + commit_vec, page_data = commits(pr; auth = auth) @test commit_vec isa Vector{Commit} @test length(commit_vec) == 1 end let - commit_vec, page_data = commits(ghjl, 37) + commit_vec, page_data = commits(ghjl, 37; auth = auth) @test commit_vec isa Vector{Commit} @test length(commit_vec) == 1 end