Skip to content

Commit b009260

Browse files
committed
Add support for comparing commits.
1 parent e4daeaa commit b009260

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API.
108108
| `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/) |
109109
| `commit(repo, sha)` | `Commit` | [get the commit specified by `sha`](https://developer.github.com/v3/repos/commits/#get-a-single-commit) |
110110
| `commits(repo)` | `Tuple{Vector{Commit}, Dict}` | [get `repo`'s commits](https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository) |
111+
| `compare(repo, base, head)` | `Comparison` | [compare `repo`'s commits](https://docs.github.com/en/rest/commits/commits#compare-two-commits) |
111112
| `branch(repo, branch)` | `Branch` | [get the branch specified by `branch`](https://developer.github.com/v3/repos/#get-branch) |
112113
| `branches(repo)` | `Tuple{Vector{Branch}, Dict}` | [get `repo`'s branches](https://developer.github.com/v3/repos/#list-branches) |
113114
| `file(repo, path)` | `Content` | [get the file specified by `path`](https://developer.github.com/v3/repos/contents/#get-contents) |

src/GitHub.jl

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ include("repositories/statuses.jl")
110110
include("repositories/webhooks.jl")
111111
include("repositories/deploykeys.jl")
112112
include("repositories/secrets.jl")
113+
include("repositories/compare.jl")
113114

114115
# export -------
115116

@@ -143,6 +144,10 @@ export # commits.jl
143144
commit,
144145
commits
145146

147+
export # compare.jl
148+
Comparison,
149+
compare
150+
146151
export # branches.jl
147152
Branch,
148153
branch,

src/repositories/compare.jl

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
###################
2+
# Comparison Type #
3+
###################
4+
5+
@ghdef mutable struct Comparison
6+
url::Union{URIs.URI, Nothing}
7+
html_url::Union{URIs.URI, Nothing}
8+
permalink_url::Union{URIs.URI, Nothing}
9+
diff_url::Union{URIs.URI, Nothing}
10+
patch_url::Union{URIs.URI, Nothing}
11+
base_commit::Union{Commit, Nothing}
12+
merge_base_commit::Union{Commit, Nothing}
13+
status::Union{String, Nothing}
14+
ahead_by::Union{Int, Nothing}
15+
behind_by::Union{Int, Nothing}
16+
total_commits::Union{Int, Nothing}
17+
commits::Union{Vector{Commit}, Nothing}
18+
files::Union{Vector{Content}, Nothing}
19+
end
20+
21+
###############
22+
# API Methods #
23+
###############
24+
25+
@api_default function compare(api::GitHubAPI, repo, base, head; options...)
26+
result = gh_get_json(api, "/repos/$(name(repo))/compare/$(name(base))...$(name(head))"; options...)
27+
return Comparison(result)
28+
end

test/read_only_api_tests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ end
7878
@test name(commit(ghjl, testcommit; auth = auth)) == name(testcommit)
7979
@test hasghobj(testcommit, first(commits(ghjl; auth = auth)))
8080

81+
# test GitHub.compare
82+
@test compare(ghjl, "master", "master~"; auth = auth).behind_by == 1
83+
8184
# test GitHub.file, GitHub.directory, GitHub.readme, GitHub.permalink
8285
readme_file = file(ghjl, "README.md"; auth = auth)
8386
src_dir = first(directory(ghjl, "src"; auth = auth))

0 commit comments

Comments
 (0)