Skip to content

Conversation

carstenbauer
Copy link
Contributor

This adds Content(::Nothing) = nothing.

Otherwise delete_file throws a MethodError.

"MWE":

using GitHub, Base64

GitHub.Content(::Nothing) = nothing # without this line I get a MethodError when calling rm below

const AUTH = GitHub.authenticate(ENV["GITHUB_AUTH"])
const REPO = Repo("crstnbr/dqmc-benchmarks")

function push(filename; message="push $filename (api)")
    content = read(filename, String)
    d = Dict(
        "content" => base64encode(content),
        "message" => message
    )
    create_file(REPO, filename; auth=AUTH, params=d)
    nothing
end


function rm(filename; message="rm $filename (api)")
    d = Dict(
        "message" => message,
        "sha" => file(REPO, filename; auth=AUTH).sha
    )
    delete_file(REPO, filename; auth=AUTH, params=d)
    nothing
end

push("result.json")
rm("result.json")

@KristofferC
Copy link
Collaborator

This seems like the wrong fix. You would assume that the Content constructor returns a Content. Isn't this just missing handling nothing somewhere else? Where does the error get thrown, what is the stacktrace?

@carstenbauer
Copy link
Contributor Author

Stacktrace

julia> rm("result.json")
ERROR: MethodError: no method matching Content(::Nothing)
Closest candidates are:
  Content(::Union{Nothing, String}, ::Union{Nothing, String}, ::Union{Nothing, String}, ::Union{Nothing, Strig}, ::Union{Nothing, String}, ::Union{Nothing, String}, ::Union{Nothing, String}, ::Union{Nothing, String}, :Union{Nothing, URI}, ::Union{Nothing, URI}, ::Union{Nothing, URI}, ::Union{Nothing, URI}, ::Union{Nothing, In64}) at C:\Users\carsten\.julia\packages\GitHub\hKBtB\src\repositories\contents.jl:6
  Content(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) at C:\Usrs\carsten\.julia\packages\GitHub\hKBtB\src\repositories\contents.jl:6
  Content(::Dict) at C:\Users\carsten\.julia\packages\GitHub\hKBtB\src\repositories\contents.jl:21
  ...
Stacktrace:
 [1] build_content_response(::Dict{String,Any}) at C:\Users\carsten\.julia\packages\GitHub\hKBtB\src\repositoies\contents.jl:77
 [2] #delete_file#80(::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol},NamedTuple{(:auth, :params),TupleGitHub.OAuth2,Dict{String,String}}}}, ::Function, ::GitHub.GitHubWebAPI, ::Repo, ::String) at C:\Users\carste\.julia\packages\GitHub\hKBtB\src\repositories\contents.jl:52
 [3] #delete_file at .\none:0 [inlined]
 [4] #delete_file#81 at .\none:0 [inlined]
 [5] (::getfield(GitHub, Symbol("#kw##delete_file")))(::NamedTuple{(:auth, :params),Tuple{GitHub.OAuth2,Dict{tring,String}}}, ::typeof(delete_file), ::Repo, ::String) at .\none:0
 [6] #rm#10(::String, ::Function, ::String) at C:\Users\carsten\Desktop\gitpr\gitpr.jl:24
 [7] rm(::String) at C:\Users\carsten\Desktop\gitpr\gitpr.jl:20
 [8] top-level scope at none:0

contents.jl around line 77:

function build_content_response(json::Dict)
    results = Dict()
    haskey(json, "commit") && setindex!(results, Commit(json["commit"]), "commit")
    haskey(json, "content") && setindex!(results, Content(json["content"]), "content")
    return results
end

Here, json["content"] turns out to be nothing.

At what level do you think should this be fixed? The JSON parsing? In build_content_response? Or in the Content constructor (currently this PR)?

@carstenbauer
Copy link
Contributor Author

Would you prefer a GitHub.Content(fill(nothing, 13)...) in the result Dict over nothing here?

@KristofferC
Copy link
Collaborator

KristofferC commented Aug 15, 2019

Setting the value for the "content" key to nothing when json["content"] === nothing makes sense to me.

@carstenbauer
Copy link
Contributor Author

Alright, I fixed it accordingly (checked that it works locally). Should be good to go?

@KristofferC KristofferC merged commit a989cad into JuliaWeb:master Aug 16, 2019
@carstenbauer carstenbauer deleted the patch-1 branch August 16, 2019 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants