Skip to content

Commit

Permalink
Merge 484f7ad into b53fdcb
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Aug 6, 2017
2 parents b53fdcb + 484f7ad commit d17568d
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Here's a table that matches up the provided `GitHubType`s with their correspondi
| `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) |
| `Review` | id, e.g. `1` | [reviews](https://developer.github.com/v3/pulls/reviews/) |

You can inspect which fields are available for a type `G<:GitHubType` by calling `fieldnames(G)`.

Expand Down Expand Up @@ -115,7 +116,9 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API.
| `issue(repo, issue)` | `Issue` | [get the issue specified by `issue`](https://developer.github.com/v3/issues/#get-a-single-issue) |
| `issues(repo)` | `Tuple{Vector{Issue}, Dict}` | [get `repo`'s issues](https://developer.github.com/v3/issues/#list-issues-for-a-repository) |
| `create_issue(repo)` | `Issue` | [create an issue in `repo`](https://developer.github.com/v3/issues/#create-an-issue) |
| `edit_issue(repo, issue)` | `Issue` | [edit `issue` in `repo`](https://developer.github.com/v3/issues/#edit-an-issue) |
| `edit_issue(repo, issue)` | `Issue` | [edit `issue` in `repo`](https://developer.github.com/v3/issues/#edit-an-issue)
| `reviews(repo, pr)` | `Tuple{Vector{PullRequest}, Dict}` | [get a `pr`'s reviews](https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request) |
| `dismiss_review(repo, review)` | `HttpCommon.Response` | [dismiss `review` in `repo`](https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review) |

#### Comments

Expand All @@ -141,6 +144,8 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API.
| `delete_comment(repo, comment, :pr)` | `HttpCommon.Response` | [delete the PR `comment` from `repo`](https://developer.github.com/v3/issues/comments/#delete-a-comment) |
| `delete_comment(repo, comment, :review)` | `HttpCommon.Response` | [delete the review `comment` from `repo`](https://developer.github.com/v3/pulls/comments/#delete-a-comment) |
| `delete_comment(repo, comment, :commit)` | `HttpCommon.Response` | [delete the commit`comment` from `repo`](https://developer.github.com/v3/repos/comments/#delete-a-commit-comment) |
| `delete_comment(repo, comment, :commit)` | `HttpCommon.Response` | [delete the commit`comment` from `repo`](https://developer.github.com/v3/repos/comments/#delete-a-commit-comment) |
| `reply_to(repo, review, comment, body)` | `HttpCommon.Response` | [reply to the `comment` (of `review` in `repo`) creating a new comment with the specified `body`](https://developer.github.com/v3/pulls/comments/#alternative-input) |

#### Social Activity

Expand Down
10 changes: 9 additions & 1 deletion src/GitHub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ export # statuses.jl
include("issues/pull_requests.jl")
include("issues/issues.jl")
include("issues/comments.jl")
include("issues/reviews.jl")

# export -------

export # pull_requests.jl
PullRequest,
pull_requests,
pull_request,
create_pull_request
create_pull_request,
Review

export # issues.jl
Issue,
Expand All @@ -147,6 +149,12 @@ export # comments.jl
create_comment,
edit_comment,
delete_comment

export # reviews.jl
Review,
reviews,
reply_to,
dismiss_review


#########
Expand Down
4 changes: 3 additions & 1 deletion src/activity/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function event_from_payload!(kind, data::Dict)
repository = Repo(data["repository"])
elseif kind == "membership" ||
kind == "integration_installation" ||
kind == "installation"
kind == "installation" ||
kind == "installation_repositories" ||
kind == "integration_installation_repositories"
repository = Repo("")
else
error("event payload is missing repository field")
Expand Down
6 changes: 6 additions & 0 deletions src/issues/pull_requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ function create_pull_request(repo; options...)
result = gh_post_json("/repos/$(name(repo))/pulls"; options...)
return PullRequest(result)
end

function create_comment(repo, pr::PullRequest, body::AbstractString; options...)
create_comment(repo, pr, :pr; params = Dict(
:body => body
), options...)
end
39 changes: 39 additions & 0 deletions src/issues/reviews.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
type Review <: GitHubType
pr::Nullable{PullRequest}
id::Nullable{Int}
user::Nullable{Owner}
body::Nullable{String}
state::Nullable{String}
end

function Review(pr::PullRequest, data::Dict)
rev = json2github(Review, data)
rev.pr = Nullable(pr)
rev
end

namefield(rev::Review) = rev.id

function reviews(repo, pr::PullRequest; options...)
path = "/repos/$(name(repo))/pulls/$(name(pr))/reviews"
results, page_data = gh_get_paged_json(path; options...)
return map(x->Review(pr, x), results), page_data
end

function comments(repo, rev::Review; options...)
path = "/repos/$(name(repo))/pulls/$(name(get(rev.pr)))/reviews/$(name(rev))/comments"
results, page_data = gh_get_paged_json(path; options...)
return map(Comment, results), page_data
end

function reply_to(repo, r::Review, c::Comment, body; options...)
@show (repo, r, c)
create_comment(repo, get(r.pr), :review; params = Dict(
:body => body,
:in_reply_to => get(c.id)
), options...)
end

function dismiss_review(repo::Repo, r::Review; options...)
gh_put("/repos/$(name(repo))/pulls/$(name(get(rev.pr)))/reviews/$(name(rev))/dismissals")
end
7 changes: 7 additions & 0 deletions test/read_only_api_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ end
@test get(gist_obj.files)["file1.jl"]["content"] == "Hello World!"
end

@testset "Reviews" begin
pr = pull_request(ghjl, 59; auth = auth)
review = first(reviews(ghjl, pr; auth=auth)[1])

@test get(review.state) == "CHANGES_REQUESTED"
end

@testset "Activity" begin
# test GitHub.stargazers, GitHub.starred
@test length(first(stargazers(ghjl; auth = auth))) > 10 # every package should fail tests if it's not popular enough :p
Expand Down

0 comments on commit d17568d

Please sign in to comment.