whiteinge/ok.sh

upload_asset error with organization

folknor opened this issue ยท 15 comments

Hi,

I'm having a problem using the upload_asset command with a github organization.

Here is the output of -vvv: https://hastebin.com/iquqitoqep
And this is the tail end of -vvv -j: https://hastebin.com/itutoribat
The first one has been edited heavily to remove the zip binary and ssl data, just for ease of reading.
Second one is just the end, mostly so you can see this:

/home/folk/.local/bin/ok.sh: 1561: local: "url":: bad variable name

Here is the relevant line from my lua script:
oksh("-vvv", "-j", "upload_asset", userId, repo, id, zip, "filename=" .. zip, "mime_type=application/zip")
userId = stellaris-mods
repo = test for the first paste, testing on the short 2nd paste
zip = folk_testmod.zip

My head is fried at the moment, hopefully I can take a closer look soon, and come back with some more information.

Yeah I have no clue, please help.

Here's some output with set -x:

+ [ X-GitHub-Request-Id = Link_next ]
+ IFS=:  read -r hdr val
+ output=
+ printf %s\n 
+ cat
+ :
+ cat
+ [ 1 -eq 1 ]
+ _log info Remaining next link follows: 50
+ local level=info
+ local message=Remaining next link follows: 50
+ shift 2
+ local lname
+ lname=INFO
+ level=4
+ printf %s %s: %s\n ok.sh INFO Remaining next link follows: 50
ok.sh INFO: Remaining next link follows: 50
+ [ -n  ]
+ return
+ local upload_url={ "url": "https://api.github.com/repos/stellaris-mods/testing/releases/7806555", "assets_url": "https://api.github.com/repos/stellaris-mods/testing/releases/7806555/assets", "upload_url": "https://uploads.github.com/repos/stellaris-mods/testing/releases/7806555/assets?name=folktestmod.zip", "html_url": "https://github.com/stellaris-mods/testing/releases/tag/20170919-r3", "id": 7806555, "tag_name": "20170919-r3", "target_commitish": "master", "name": null, "draft": false, "author": { "login": "folknor", "id": 233791, "avatar_url": "https://avatars2.githubusercontent.com/u/233791?v=4", "gravatar_id": "", "url": "https://api.github.com/users/folknor", "html_url": "https://github.com/folknor", "followers_url": "https://api.github.com/users/folknor/followers", "following_url": "https://api.github.com/users/folknor/following{/other_user}", "gists_url": "https://api.github.com/users/folknor/gists{/gist_id}", "starred_url": "https://api.github.com/users/folknor/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/folknor/subscriptions", "organizations_url": "https://api.github.com/users/folknor/orgs", "repos_url": "https://api.github.com/users/folknor/repos", "events_url": "https://api.github.com/users/folknor/events{/privacy}", "received_events_url": "https://api.github.com/users/folknor/received_events", "type": "User", "site_admin": false }, "prerelease": false, "created_at": "2017-09-19T11:56:11Z", "published_at": "2017-09-19T11:56:36Z", "assets": [ ], "tarball_url": "https://api.github.com/repos/stellaris-mods/testing/tarball/20170919-r3", "zipball_url": "https://api.github.com/repos/stellaris-mods/testing/zipball/20170919-r3", "body": "* Testing without _ in name." }
/home/folk/.local/bin/ok.sh: 1566: local: "url":: bad variable name
+ excode=2
+ trap - EXIT
+ exec
+ exec
+ exec
+ rm -rf /tmp/ok.sh.3915.6785868917
+ exit 2

Here - just for reference - is formatted json from a different debug run than the above comment. The only difference is that the uploaded file name contains a underscore ("_") - "folk_testmod.zip", but in the above comment it's "folktestmod.zip":

{
	"url": "https://api.github.com/repos/stellaris-mods/testing/releases/7806517",
	"assets_url": "https://api.github.com/repos/stellaris-mods/testing/releases/7806517/assets",
	"upload_url": "https://uploads.github.com/repos/stellaris-mods/testing/releases/7806517/assets?name=folk_testmod.zip",
	"html_url": "https://github.com/stellaris-mods/testing/releases/tag/20170919-r2",
	"id": 7806517,
	"tag_name": "20170919-r2",
	"target_commitish": "master",
	"name": null,
	"draft": false,
	"author": {
		"login": "folknor",
		"id": 233791,
		"avatar_url": "https://avatars2.githubusercontent.com/u/233791?v=4",
		"gravatar_id": "",
		"url": "https://api.github.com/users/folknor",
		"html_url": "https://github.com/folknor",
		"followers_url": "https://api.github.com/users/folknor/followers",
		"following_url": "https://api.github.com/users/folknor/following{/other_user}",
		"gists_url": "https://api.github.com/users/folknor/gists{/gist_id}",
		"starred_url": "https://api.github.com/users/folknor/starred{/owner}{/repo}",
		"subscriptions_url": "https://api.github.com/users/folknor/subscriptions",
		"organizations_url": "https://api.github.com/users/folknor/orgs",
		"repos_url": "https://api.github.com/users/folknor/repos",
		"events_url": "https://api.github.com/users/folknor/events{/privacy}",
		"received_events_url": "https://api.github.com/users/folknor/received_events",
		"type": "User",
		"site_admin": false
	},
	"prerelease": false,
	"created_at": "2017-09-19T11:52:53Z",
	"published_at": "2017-09-19T11:53:03Z",
	"assets": [],
	"tarball_url": "https://api.github.com/repos/stellaris-mods/testing/tarball/20170919-r2",
	"zipball_url": "https://api.github.com/repos/stellaris-mods/testing/zipball/20170919-r2",
	"body": "* Updated readme.md with changes from steam.bbcode.\n* Steam.bbcode update."
}

Thanks for all the details. I'll try to reproduce and report back.

I have a lot more debug output and I'm ready to assist in testing for the next 3-4 hours if needed.

Thanks for the offer! I won't be able to get to it until after work so several hours at the soonest but I'll comment when I do.

Does it work if you remove the -j flag?

This function is an outlier in that it's the only one that requires jq to perform an internal query. I've thought about removing it or splitting it out for that reason (see #9). That said, it at least needs a check in its current form. I've added one in #48.

No, it does not work without -j, I said that in the initial description.

I will try again with your latest commits soon, thank you.

Same error as before, here is all the output from -vvv -x, with raw binary data snipped out: https://hastebin.com/raw/apivosazig

That said, it does actually upload the asset. It just errors immediately after.

Thanks, I missed the test without the -j flag. Looks like the JSON response from the intermediary step is getting mangled somewhere. I'll take another stab at reproducing.

Ok, I can reproduce it now. The response headers are getting output along with the JSON response body. Still digging into why only in this method and not elsewhere.

This function may just be too fragile so I'm thinking of stripping it down to just the basics (#65). A lot less convenient but hopefully more straightforward to use if edge-cases happen. Thoughts welcome.

Seems entirely sensible to me. I didn't want to bother you with this, and I'm much more comfortable with lua than bash scripting, so I wrote a replacement for myself a year or so ago.

The code is quite insane, because I had this "brilliant idea" that it should generate the functions from the github docs per path, for example to implement GET /repos/:owner/:repo/issues/:number/labels in my library, all you do is write get("repos/:owner/:repo/issues/:number/labels"), and you're done.

Optionally, you can write

get("repos/:owner/:repo/issues/:number/labels", {
    "state", "open", {
        open = true,
        closed = true,
        all = true,
    },
    ...
})

To denote that the runtime-generated API function should take an argument "state" that it passes as a HTTP parameter, where the default value is "open", and the 3 allowed values are open/closed/all.

To then call this function in your own code, you do

local _gh = require("lua-github")
local httpHeaders, jsonResponse = _gh.GET["repos/:owner/:repo/issues/:number/labels"](
    "folknor",
    "repository-name",
    42,
    "closed"
)
print(jsonResponse.upload_url) -- The response in this case has no .upload_url, I guess

The library worked when I made it, but I've not used it for a year or so. GH might have changed their API surface as well, for all I know.

I'm not sure why I described the code in such detail above, but it started by wanting to explain why I hadn't pestered you about my ok.sh upload_asset bug report :-)

https://github.com/folknor/lua-github/blob/master/src/github.lua

That's a lot more readable and sane in Lua than sh ๐Ÿ˜€. Cool idea to use the path string from the docs. Very much inline with GH's "URI templates" approach and I've wondered why that hasn't seemed to catch on elsewhere.
Thanks for the reply ๐Ÿ‘.