From 3b231b5623c3c3aaf5132d7e3a6fdf1e23e672cf Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sat, 14 Oct 2023 10:27:38 +0200 Subject: [PATCH] `create_repo`: `params` should be a keyword argument (#219) This patch deprecates `params` as a positional argument and replace it with a keyword argument (like for all other API functions). I noticed this when the `params` I passed as keyword argument were overriding the `params` created with the `name` positional argument. --- README.md | 2 +- src/repositories/repositories.jl | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0113dce..a75cb1e 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ GitHub.jl implements a bunch of methods that make REST requests to GitHub's API. | method | return type | documentation | |----------------------------------------------------------|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------| | `repo(repo)` | `Repo` | [get `repo`](https://developer.github.com/v3/repos/#get) | -| `create_repo(owner, name, params=Dict{String,String}())` | `Repo` | [create a repository of the given `name` in the given `owner`'s account](https://developer.github.com/v3/repos/#create) | +| `create_repo(owner, name)` | `Repo` | [create a repository of the given `name` in the given `owner`'s account](https://developer.github.com/v3/repos/#create) | | `create_fork(repo)` | `Repo` | [create a fork of `repo`](https://developer.github.com/v3/repos/forks/#create-a-fork) | | `forks(repo)` | `Tuple{Vector{Repo}, Dict}` | [get `repo`'s forks](https://developer.github.com/v3/repos/forks/#list-forks) | | `contributors(repo)` | `Dict` | [get `repo`'s contributors](https://developer.github.com/v3/repos/#list-contributors) | diff --git a/src/repositories/repositories.jl b/src/repositories/repositories.jl index 43b25b8..9d05454 100644 --- a/src/repositories/repositories.jl +++ b/src/repositories/repositories.jl @@ -52,8 +52,8 @@ namefield(repo::Repo) = repo.full_name return Repo(result) end -@api_default function create_repo(api::GitHubAPI, owner, repo_name::String, params=Dict{String,Any}(); options...) - params["name"] = repo_name +@api_default function create_repo(api::GitHubAPI, owner, repo_name::String; params=Dict(), options...) + params = merge(params, Dict("name" => repo_name)) if isorg(owner) result = gh_post_json(api, "/orgs/$(name(owner))/repos"; params=params, options...) else @@ -62,6 +62,11 @@ end return Repo(result) end +@api_default function create_repo(api::GitHubAPI, owner, repo_name::String, params; options...) + Base.depwarn("params should be passed as a keyword argument instead of a positional argument", :create_repo) + return create_repo(api, owner, repo_name; params=params, options...) +end + @api_default function delete_repo(api::GitHubAPI, repo; options...) return gh_delete(api, "/repos/$(name(repo))"; options...) end