Skip to content

Commit 9cac3b9

Browse files
KristofferCmaleadt
andauthored
Add 'labels' field to PullRequest (#115)
Co-authored-by: Tim Besard <tim.besard@gmail.com>
1 parent 809994e commit 9cac3b9

File tree

6 files changed

+37
-28
lines changed

6 files changed

+37
-28
lines changed

src/GitHub.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ export # secrets.jl
178178

179179
# include -------
180180

181+
include("issues/labels.jl")
181182
include("issues/pull_requests.jl")
182183
include("issues/issues.jl")
183184
include("issues/comments.jl")
184185
include("issues/reviews.jl")
185-
include("issues/labels.jl")
186186

187187
# export -------
188188

src/issues/issues.jl

+28
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,31 @@ end
5353
result = gh_patch_json(api, "/repos/$(name(repo))/issues/$(name(issue))"; options...)
5454
return Issue(result)
5555
end
56+
57+
# labels #
58+
#--------#
59+
60+
@api_default function labels(api::GitHubAPI, repo, issue; options...)
61+
result = gh_get_json(api, "/repos/$(name(repo))/issues/$(name(issue))/labels"; options...)
62+
return Label.(result)
63+
end
64+
65+
@api_default function add_labels(api::GitHubAPI, repo, issue, labels; options...)
66+
result = gh_post_json(api, "/repos/$(name(repo))/issues/$(name(issue))/labels";
67+
params=Dict("labels" => name.(labels)), options...)
68+
return Label.(result)
69+
end
70+
71+
@api_default function set_labels(api::GitHubAPI, repo, issue, labels; options...)
72+
result = gh_put_json(api, "/repos/$(name(repo))/issues/$(name(issue))/labels";
73+
params=Dict("labels" => name.(labels)), options...)
74+
return Label.(result)
75+
end
76+
77+
@api_default function remove_all_labels(api::GitHubAPI, repo, issue; options...)
78+
return gh_delete(api, "/repos/$(name(repo))/issues/$(name(issue))/labels"; options...)
79+
end
80+
81+
@api_default function remove_label(api::GitHubAPI, repo, issue, label; options...)
82+
return gh_delete(api, "/repos/$(name(repo))/issues/$(name(issue))/labels/$(name(label))"; options...)
83+
end

src/issues/labels.jl

-25
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,3 @@ end
1111
namefield(label::Label) = label.name
1212

1313
Label(name::AbstractString) = Label(Dict("name" => name))
14-
15-
@api_default function labels(api::GitHubAPI, repo, issue; options...)
16-
result = gh_get_json(api, "/repos/$(name(repo))/issues/$(name(issue))/labels"; options...)
17-
return Label.(result)
18-
end
19-
20-
@api_default function add_labels(api::GitHubAPI, repo, issue, labels; options...)
21-
result = gh_post_json(api, "/repos/$(name(repo))/issues/$(name(issue))/labels";
22-
params=Dict("labels" => name.(labels)), options...)
23-
return Label.(result)
24-
end
25-
26-
@api_default function set_labels(api::GitHubAPI, repo, issue, labels; options...)
27-
result = gh_put_json(api, "/repos/$(name(repo))/issues/$(name(issue))/labels";
28-
params=Dict("labels" => name.(labels)), options...)
29-
return Label.(result)
30-
end
31-
32-
@api_default function remove_all_labels(api::GitHubAPI, repo, issue; options...)
33-
return gh_delete(api, "/repos/$(name(repo))/issues/$(name(issue))/labels"; options...)
34-
end
35-
36-
@api_default function remove_label(api::GitHubAPI, repo, issue, label; options...)
37-
return gh_delete(api, "/repos/$(name(repo))/issues/$(name(issue))/labels/$(name(label))"; options...)
38-
end

src/issues/pull_requests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
mergeable::Union{Bool, Nothing}
3131
merged::Union{Bool, Nothing}
3232
locked::Union{Bool, Nothing}
33+
labels::Union{Vector{Label}, Nothing}
3334
end
3435

3536
PullRequest(number::Real) = PullRequest(Dict("number" => number))

test/ghtype_tests.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ end
471471
nothing,
472472
nothing,
473473
nothing,
474-
pr_json["locked"]
474+
pr_json["locked"],
475+
nothing
475476
)
476477

477478
@test PullRequest(pr_json) == pr_result

test/read_only_api_tests.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ end
110110
state_param = Dict("state" => "all")
111111

112112
# test GitHub.pull_request, GitHub.pull_requests
113-
@test pull_request(ghjl, 37; auth = auth).title == "Fix dep warnings"
113+
let pr = pull_request(ghjl, 37; auth = auth)
114+
@test pr.title == "Fix dep warnings"
115+
@test length(pr.labels) == 1
116+
@test pr.labels[1].name == "enhancement"
117+
end
114118
@test hasghobj(37, first(pull_requests(ghjl; auth = auth, params = state_param)))
115119

116120
# test GitHub.issue, GitHub.issues

0 commit comments

Comments
 (0)