Skip to content

Commit 4ccc67a

Browse files
nkottaryKristofferC
authored andcommitted
Add new methods: merge_pull_request, tags, releases (#132)
1 parent 458cb9c commit 4ccc67a

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

src/GitHub.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export # pull_requests.jl
156156
create_pull_request,
157157
update_pull_request,
158158
close_pull_request,
159+
merge_pull_request,
159160
pull_request_files,
160161
Review
161162

@@ -291,13 +292,23 @@ export # tree.jl
291292
export # tag.jl
292293
Tag,
293294
tag,
295+
tags,
294296
create_tag
295297

296298
export # gitcommit.jl
297299
GitCommit,
298300
gitcommit,
299301
create_gitcommit
300302

303+
############
304+
# Releases #
305+
############
306+
307+
include("releases/releases.jl")
301308

309+
export
310+
Release,
311+
create_release,
312+
releases
302313

303314
end # module GitHub

src/git/tag.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ namefield(tag::Tag) = tag.sha
1616
return Tag(result)
1717
end
1818

19+
@api_default function tags(api::GitHubAPI, repo; options...)
20+
result, paged_data = gh_get_paged_json(api, "/repos/$(name(repo))/git/refs/tags"; options...)
21+
return map(Tag, result), paged_data
22+
end
23+
1924
@api_default function create_tag(api::GitHubAPI, repo; options...)
2025
result = gh_post_json(api, "/repos/$(name(repo))/git/tags"; options...)
2126
return Tag(result)

src/issues/pull_requests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ end
8383
), options...)
8484
end
8585

86+
@api_default function merge_pull_request(api::GitHubAPI, repo, pr; options...)
87+
gh_put_json(api, "/repos/$(name(repo))/pulls/$(name(pr))/merge"; options...)
88+
end
89+
8690
@api_default function create_pull_request(api::GitHubAPI, repo; options...)
8791
result = gh_post_json(api, "/repos/$(name(repo))/pulls"; options...)
8892
return PullRequest(result)

src/releases/releases.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
mutable struct Release <: GitHubType
2+
url::Union{Nothing, HTTP.URI}
3+
html_url::Union{Nothing, HTTP.URI}
4+
assets_url::Union{Nothing, HTTP.URI}
5+
upload_url::Union{Nothing, HTTP.URI}
6+
tarball_url::Union{Nothing, HTTP.URI}
7+
zipball_url::Union{Nothing, HTTP.URI}
8+
id::Union{Nothing, Int}
9+
node_id::Union{Nothing, String}
10+
tag_name::Union{Nothing, String}
11+
target_commitish::Union{Nothing, String}
12+
name::Union{Nothing, String}
13+
body::Union{Nothing, String}
14+
draft::Union{Nothing, Bool}
15+
prerelease::Union{Nothing, Bool}
16+
created_at::Union{Nothing, String}
17+
published_at::Union{Nothing, String}
18+
author::Union{Nothing, Dict{String, Any}}
19+
assets::Union{Nothing, Array{Any, 1}}
20+
end
21+
22+
Release(data::Dict) = json2github(Release, data)
23+
namefield(r::Release) = r.id
24+
25+
@api_default function create_release(api::GitHubAPI, repo; options...)
26+
result = gh_post_json(api, "/repos/$(name(repo))/releases"; options...)
27+
return Release(result)
28+
end
29+
30+
@api_default function releases(api::GitHubAPI, repo; options...)
31+
result, paged_data = gh_get_paged_json(api, "/repos/$(name(repo))/releases"; options...)
32+
return map(Release, result), paged_data
33+
end

test/ghtype_tests.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,51 @@ end
956956
tree_result = Tree(tree_json)
957957
@test name(tree_result) == tree_json["sha"]
958958
end
959+
960+
@testset "Release" begin
961+
release_json = JSON.parse("""
962+
{
963+
"url": "https://api.github.com/repos/octocat/Hello-World/releases/1",
964+
"html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
965+
"assets_url": "https://api.github.com/repos/octocat/Hello-World/releases/1/assets",
966+
"upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
967+
"tarball_url": "https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0",
968+
"zipball_url": "https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0",
969+
"id": 1,
970+
"node_id": "MDc6UmVsZWFzZTE=",
971+
"tag_name": "v1.0.0",
972+
"target_commitish": "master",
973+
"name": "v1.0.0",
974+
"body": "Description of the release",
975+
"draft": false,
976+
"prerelease": false,
977+
"created_at": "2013-02-27T19:35:32Z",
978+
"published_at": "2013-02-27T19:35:32Z",
979+
"author": {
980+
"login": "octocat",
981+
"id": 1,
982+
"node_id": "MDQ6VXNlcjE=",
983+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
984+
"gravatar_id": "",
985+
"url": "https://api.github.com/users/octocat",
986+
"html_url": "https://github.com/octocat",
987+
"followers_url": "https://api.github.com/users/octocat/followers",
988+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
989+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
990+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
991+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
992+
"organizations_url": "https://api.github.com/users/octocat/orgs",
993+
"repos_url": "https://api.github.com/users/octocat/repos",
994+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
995+
"received_events_url": "https://api.github.com/users/octocat/received_events",
996+
"type": "User",
997+
"site_admin": false
998+
},
999+
"assets": [
1000+
]
1001+
}
1002+
""")
1003+
1004+
release_result = Release(release_json)
1005+
@test name(release_result) == release_json["id"]
1006+
end

0 commit comments

Comments
 (0)