diff --git a/README.md b/README.md index fcc6530..9062d9d 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,8 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API. | `remove_collaborator(repo, user)` | `HTTP.Response` | [remove `user` as a collaborator from `repo`](https://developer.github.com/v3/repos/collaborators/#remove-collaborator) | | `collaborator_permission(repo, user)` | `HTTP.Response` | [get the `repo` permission of a collaborator](https://developer.github.com/v3/repos/collaborators/#get-repository-permissions-for-a-user) | | `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/) | +| `topics(repo)` | `Vector{String}` | [get the list of topics of a repository.)](https://docs.github.com/en/rest/repos/repos#get-all-repository-topics) | +| `set_topics(repo, topics)` | `Vector{String}` | [set the list of topics of a repository.)](https://docs.github.com/en/rest/repos/repos#replace-all-repository-topics) | | `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) | | `branch(repo, branch)` | `Branch` | [get the branch specified by `branch`](https://developer.github.com/v3/repos/#get-branch) | diff --git a/src/GitHub.jl b/src/GitHub.jl index cda2cb3..82ebdf2 100644 --- a/src/GitHub.jl +++ b/src/GitHub.jl @@ -126,7 +126,9 @@ export # repositories.jl add_collaborator, remove_collaborator, collaborator_permission, - stats + stats, + topics, + set_topics export # contents.jl Content, diff --git a/src/repositories/repositories.jl b/src/repositories/repositories.jl index 57cd2f6..43b25b8 100644 --- a/src/repositories/repositories.jl +++ b/src/repositories/repositories.jl @@ -130,3 +130,17 @@ end end return r end + +# topics # +#--------# + +@api_default function topics(api::GitHubAPI, repo; options...) + results, page_data = gh_get_paged_json(api, "/repos/$(name(repo))/topics"; options...) + return convert(Vector{String}, results["names"]), page_data +end + +@api_default function set_topics(api::GitHubAPI, repo, topics; options...) + result = gh_put_json(api, "/repos/$(name(repo))/topics"; + params=Dict("names" => topics), options...) + return convert(Vector{String}, result["names"]) +end diff --git a/test/read_only_api_tests.jl b/test/read_only_api_tests.jl index 391b371..df51fcd 100644 --- a/test/read_only_api_tests.jl +++ b/test/read_only_api_tests.jl @@ -249,3 +249,14 @@ end @test repo_license_obj.path == "LICENSE.md" @test repo_license_obj.typ == "file" end + +@testset "Topics" begin + # test GitHub.topics + topics_obj, page_data = topics(ghjl; auth = auth) + @test typeof(topics_obj) == Vector{String} + @test length(topics_obj) == 0 + + # also test on a repository that _does_ have topics + topics_obj, page_data = topics("JuliaLang/julia"; auth = auth) + @test length(topics_obj) > 0 +end