From 92377c7ac51fc44bf565d310a092e31e9d85a09a Mon Sep 17 00:00:00 2001 From: Hannes Date: Sun, 20 Nov 2022 18:10:54 +0000 Subject: [PATCH 1/6] Add function to get a repo's topics --- src/GitHub.jl | 5 +++++ src/repositories/topics.jl | 20 ++++++++++++++++++++ test/read_only_api_tests.jl | 7 +++++++ 3 files changed, 32 insertions(+) create mode 100644 src/repositories/topics.jl diff --git a/src/GitHub.jl b/src/GitHub.jl index cda2cb3..3d47156 100644 --- a/src/GitHub.jl +++ b/src/GitHub.jl @@ -110,6 +110,7 @@ include("repositories/statuses.jl") include("repositories/webhooks.jl") include("repositories/deploykeys.jl") include("repositories/secrets.jl") +include("repositories/topics.jl") # export ------- @@ -172,6 +173,10 @@ export # secrets.jl create_secret, delete_secret +export # topics.jl + Topic, + topics + ########## # Issues # ########## diff --git a/src/repositories/topics.jl b/src/repositories/topics.jl new file mode 100644 index 0000000..bb11a7e --- /dev/null +++ b/src/repositories/topics.jl @@ -0,0 +1,20 @@ +############### +# Topic Type # +############### + +@ghdef mutable struct Topic + name::String +end + +Topic(name::AbstractString) = Commit(Dict("name" => name)) + +namefield(topic::Topic) = topic.name + +############### +# API Methods # +############### + +@api_default function topics(api::GitHubAPI, repo; options...) + results, page_data = gh_get_paged_json(api, "/repos/$(name(repo))/topics"; options...) + return map(Topic, results["names"]), page_data +end diff --git a/test/read_only_api_tests.jl b/test/read_only_api_tests.jl index 391b371..4d6fac0 100644 --- a/test/read_only_api_tests.jl +++ b/test/read_only_api_tests.jl @@ -249,3 +249,10 @@ end @test repo_license_obj.path == "LICENSE.md" @test repo_license_obj.typ == "file" end + +@testset "Topics" begin + # test GitHub.topics + topics_obj, _ = topics(ghjl) + @test typeof(topics_obj) == Vector{Topic} + @test length(topics_obj) == 0 +end From 71eee430979d3d391265c409ce05572a4bc9043f Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Nov 2022 09:05:34 +0100 Subject: [PATCH 2/6] Also test on a repo that does have topics. --- test/read_only_api_tests.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/read_only_api_tests.jl b/test/read_only_api_tests.jl index 4d6fac0..e3a27ec 100644 --- a/test/read_only_api_tests.jl +++ b/test/read_only_api_tests.jl @@ -252,7 +252,11 @@ end @testset "Topics" begin # test GitHub.topics - topics_obj, _ = topics(ghjl) + topics_obj, page_data = topics(ghjl) @test typeof(topics_obj) == Vector{Topic} @test length(topics_obj) == 0 + + # also test on a repository that _does_ have topics + topics_obj, page_data = topics("JuliaLang/julia") + @test length(topics_obj) > 0 end From b07a31c7e011b07f439d77ec334c57deeb6f6c38 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Nov 2022 09:12:29 +0100 Subject: [PATCH 3/6] Simplify topics. --- src/GitHub.jl | 8 ++------ src/repositories/repositories.jl | 8 ++++++++ src/repositories/topics.jl | 20 -------------------- test/read_only_api_tests.jl | 2 +- 4 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 src/repositories/topics.jl diff --git a/src/GitHub.jl b/src/GitHub.jl index 3d47156..c84aae2 100644 --- a/src/GitHub.jl +++ b/src/GitHub.jl @@ -110,7 +110,6 @@ include("repositories/statuses.jl") include("repositories/webhooks.jl") include("repositories/deploykeys.jl") include("repositories/secrets.jl") -include("repositories/topics.jl") # export ------- @@ -127,7 +126,8 @@ export # repositories.jl add_collaborator, remove_collaborator, collaborator_permission, - stats + stats, + topics export # contents.jl Content, @@ -173,10 +173,6 @@ export # secrets.jl create_secret, delete_secret -export # topics.jl - Topic, - topics - ########## # Issues # ########## diff --git a/src/repositories/repositories.jl b/src/repositories/repositories.jl index 57cd2f6..8f48066 100644 --- a/src/repositories/repositories.jl +++ b/src/repositories/repositories.jl @@ -130,3 +130,11 @@ 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 diff --git a/src/repositories/topics.jl b/src/repositories/topics.jl deleted file mode 100644 index bb11a7e..0000000 --- a/src/repositories/topics.jl +++ /dev/null @@ -1,20 +0,0 @@ -############### -# Topic Type # -############### - -@ghdef mutable struct Topic - name::String -end - -Topic(name::AbstractString) = Commit(Dict("name" => name)) - -namefield(topic::Topic) = topic.name - -############### -# API Methods # -############### - -@api_default function topics(api::GitHubAPI, repo; options...) - results, page_data = gh_get_paged_json(api, "/repos/$(name(repo))/topics"; options...) - return map(Topic, results["names"]), page_data -end diff --git a/test/read_only_api_tests.jl b/test/read_only_api_tests.jl index e3a27ec..e9db2b2 100644 --- a/test/read_only_api_tests.jl +++ b/test/read_only_api_tests.jl @@ -253,7 +253,7 @@ end @testset "Topics" begin # test GitHub.topics topics_obj, page_data = topics(ghjl) - @test typeof(topics_obj) == Vector{Topic} + @test typeof(topics_obj) == Vector{String} @test length(topics_obj) == 0 # also test on a repository that _does_ have topics From 0ff7ff5bb2657ca17528413d7128e9a2dd7f94bd Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Nov 2022 09:12:36 +0100 Subject: [PATCH 4/6] Document topics. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fcc6530..6e5a0bb 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ 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) | | `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) | From 0c7780de5a783ff9dcc771805157c62ca917d5bd Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Nov 2022 09:24:28 +0100 Subject: [PATCH 5/6] Support for setting topics. --- README.md | 1 + src/GitHub.jl | 3 ++- src/repositories/repositories.jl | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e5a0bb..9062d9d 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API. | `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 c84aae2..82ebdf2 100644 --- a/src/GitHub.jl +++ b/src/GitHub.jl @@ -127,7 +127,8 @@ export # repositories.jl remove_collaborator, collaborator_permission, stats, - topics + topics, + set_topics export # contents.jl Content, diff --git a/src/repositories/repositories.jl b/src/repositories/repositories.jl index 8f48066..43b25b8 100644 --- a/src/repositories/repositories.jl +++ b/src/repositories/repositories.jl @@ -138,3 +138,9 @@ end 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 From 087c377cb02d95ddcbbfa33d0ebe084d8d6acb73 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 24 Nov 2022 09:41:01 +0100 Subject: [PATCH 6/6] Add missing auth. --- test/read_only_api_tests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/read_only_api_tests.jl b/test/read_only_api_tests.jl index e9db2b2..df51fcd 100644 --- a/test/read_only_api_tests.jl +++ b/test/read_only_api_tests.jl @@ -252,11 +252,11 @@ end @testset "Topics" begin # test GitHub.topics - topics_obj, page_data = topics(ghjl) + 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") + topics_obj, page_data = topics("JuliaLang/julia"; auth = auth) @test length(topics_obj) > 0 end