This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hbomb79's profile picture

Bug Reporting

Started by hbomb79, 31 August 2014 - 02:37 AM
hbomb79 #1
Posted 31 August 2014 - 04:37 AM
Hey there, Just wondering how to auto send bug reports

I have implemented a log file system which writes to a log file, But in the event of an error I would like the system to send the log file to an email or something similar, I thought maybe pastebin but I wont know what IDs they are, Is there a way of using githubs issue section here through a computer script???

-Thanks - Harry
natedogith1 #2
Posted 31 August 2014 - 05:18 AM
I'd recommend seeing what you can do with the gmail and/or github apis.
hbomb79 #3
Posted 31 August 2014 - 05:35 AM
I had a look and I dont know how to implement them into CC could someone write an example script that I could implement into the system? Doesnt need to have working variables, just explaining the concept of how to add them to GitHub, Ive seen this done before, A couple of times including oeed, I saw he had an alternate account that appeared to be auto posting issues in the issue section of GitHub… Maybe ill ask him for assistance if we cant figure it out.
hbomb79 #4
Posted 31 August 2014 - 05:57 AM
I think what im stuck on is how to use and install the Github API for computercraft… If thats possible, Like I said ive seen this done before, oeeds script seems to use pastebin aswell, But id rather use GitHub as I use it more often
natedogith1 #5
Posted 31 August 2014 - 06:41 AM
You might not be able to just install one, as it might not exist. But if you can understand their http api (which is what's described on the api page) you can implement it yourself using CC's http api.
hbomb79 #6
Posted 31 August 2014 - 06:52 AM
You might not be able to just install one, as it might not exist. But if you can understand their http api (which is what's described on the api page) you can implement it yourself using CC's http api.

My problem is I have zero understanding of whats discussed in the links you gave me, Mainly because im a little stupid :P/>
natedogith1 #7
Posted 31 August 2014 - 07:05 PM
So I have an example of what should work, but I haven't actually tested it out yet so…

--local base64Credentials = "" -- TO_BASE_64(USERNAME .. ":" .. PASSWORD)
--local auth = "Basic " .. base64Credentials -- could also be "token " .. OAUTH_TOKEN
-- above probably shouldn't be used, rather insecure
local oauthToken = "" -- your oauth token
local auth = "token " .. oauthToken -- value for Authroization header

local headers={ -- headers sent with every http request to github api
Authorization=auth, -- for authorization
Accept="application/vnd.github.v3+json", -- make sure we get correct version
["User-Agent"]="" -- set to something unique, should probably include username (see https://developer.github.com/v3/#user-agent-required)
}

local owner = "" -- owner of repository
local repo = "" -- repository

local title = "" -- title of issue
title = title:gsub("\\", "\\\\"):gsub("\"", "\\\"") -- make JSON string
local body = "" -- body of issue
body = body:gsub("\\", "\\\\"):gsub("\"", "\\\"") -- make JSON string
local jsonObject=[[
{
"title" : "]] .. title .. [[",
"body" : "]] .. body .. [[",
}]]
http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues", jsonObject, headers)
--if headers aren't avaliable try this instead
--http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues?access_token=" .. oauthToken, jsonObject)
KingofGamesYami #8
Posted 31 August 2014 - 07:14 PM
So I have an example of what should work, but I haven't actually tested it out yet so…

--#local base64Credentials = "" -- TO_BASE_64(USERNAME .. ":" .. PASSWORD)
--#local auth = "Basic " .. base64Credentials -- could also be "token " .. OAUTH_TOKEN
--#above probably shouldn't be used, rather insecure
local oauthToken = "" --#your oauth token
local auth = "token " .. oauthToken --#value for Authroization header

local headers={ --#headers sent with every http request to github api
Authorization=auth, --#for authorization
Accept="application/vnd.github.v3+json", --#make sure we get correct version
["User-Agent"]="" --#set to something unique, should probably include username (see https://developer.github.com/v3/#user-agent-required)
}

local owner = "" --#owner of repository
local repo = "" --#repository

local title = "" --#title of issue
title = title:gsub("\\", "\\\\"):gsub("\"", "\\\"") --#make JSON string
local body = "" --#body of issue
body = body:gsub("\\", "\\\\"):gsub("\"", "\\\"") --#make JSON string
local jsonObject=[[
{
"title" : "]] .. title .. [[",
"body" : "]] .. body .. [[",
}]]
http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues", jsonObject, headers)
--#if headers aren't avaliable try this instead
--#http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues?access_token=" .. oauthToken, jsonObject)

Tip: Use –# for comments, since the forum parses # as a comment, and lua interprets – as a comment. It looks good when posting, and still works fine in game.
natedogith1 #9
Posted 31 August 2014 - 07:28 PM
– snip –
Tip: Use –# for comments, since the forum parses # as a comment, and lua interprets – as a comment. It looks good when posting, and still works fine in game.
Thanks, I was wondering why people were formatting like that.
hbomb79 #10
Posted 31 August 2014 - 09:43 PM
So I have an example of what should work, but I haven't actually tested it out yet so…

--local base64Credentials = "" -- TO_BASE_64(USERNAME .. ":" .. PASSWORD)
--local auth = "Basic " .. base64Credentials -- could also be "token " .. OAUTH_TOKEN
-- above probably shouldn't be used, rather insecure
local oauthToken = "" -- your oauth token
local auth = "token " .. oauthToken -- value for Authroization header

local headers={ -- headers sent with every http request to github api
Authorization=auth, -- for authorization
Accept="application/vnd.github.v3+json", -- make sure we get correct version
["User-Agent"]="" -- set to something unique, should probably include username (see https://developer.github.com/v3/#user-agent-required)
}

local owner = "" -- owner of repository
local repo = "" -- repository

local title = "" -- title of issue
title = title:gsub("\\", "\\\\"):gsub("\"", "\\\"") -- make JSON string
local body = "" -- body of issue
body = body:gsub("\\", "\\\\"):gsub("\"", "\\\"") -- make JSON string
local jsonObject=[[
{
"title" : "]] .. title .. [[",
"body" : "]] .. body .. [[",
}]]
http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues", jsonObject, headers)
--if headers aren't avaliable try this instead
--http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues?access_token=" .. oauthToken, jsonObject)

Sorry, but when you say the above shouldn't be used, what else do I put there, or is it not necessary, as you can see I'm very much new to Internet Apis etc within computer craft, I've only ever done GitHub downloading, I hope I can get your code to work, just for classification, what is the auth and oauth etc…

Like you said, the first part is very insecure, I don't want people knowing my password to GitHub, whether it is a seperate account or not, it would still have push access etc…
natedogith1 #11
Posted 31 August 2014 - 09:49 PM
– snip –

Sorry, but when you say the above shouldn't be used, what else do I put there, or is it not necessary, as you can see I'm very much new to Internet Apis etc within computer craft, I've only ever done GitHub downloading, I hope I can get your code to work, just for classification, what is the auth and oauth etc…

Like you said, the first part is very insecure, I don't want people knowing my password to GitHub, whether it is a seperate account or not, it would still have push access etc…

You'd just leave that part blank, that's why it's commented out. Instead you'd just fill in the oauthToken part with the value of your token. Though according to the github api documentation, you don't actually need push access to make an issue, you only need pull access.
hbomb79 #12
Posted 31 August 2014 - 11:15 PM
So, what is my authToken, etc… Where do I find this.

If someone knows my auto token can they access my account?

So basically is this secure or insecure like the first section.
natedogith1 #13
Posted 31 August 2014 - 11:26 PM
if you go to https://github.com/settings/tokens/new you can create a token for yourself, and since you can set the scope you can severely limit what someone with the token can do.
hbomb79 #14
Posted 31 August 2014 - 11:38 PM
I registered my Security Suite as a program in GitHub, it gave me a client secret and a client ID, I can't show you the ID because I'm on my iPad.

Is the client ID my oAuth token?

EDIT: I replied as you posted, I'm following your instruction now and I deleted what I did…

EDIT 2: None of the scopes seem to mention issue posting, I don't want the token granting access to any of my code… Just the issue section

-Harry
Edited on 31 August 2014 - 09:52 PM
natedogith1 #15
Posted 01 September 2014 - 12:07 AM
The scope you need is the one that gives read access to a repository, no idea which one that is though.
hbomb79 #16
Posted 01 September 2014 - 12:28 AM
The scope you need is the one that gives read access to a repository, no idea which one that is though.

Won't it need write access to create an issue
natedogith1 #17
Posted 01 September 2014 - 01:25 AM
According to the documentation, it only needs pull access, so I'd go with no. It makes sense when you think about the issues section as bug reports, you'd generally like to be able to have testers that can't just modify the official sources however they wish.
hbomb79 #18
Posted 01 September 2014 - 01:54 AM
So, is read only or no scope going to work…. This is more complicated than I thought, non of the scopes talk about pull or push so I have no idea which scopes to select
natedogith1 #19
Posted 01 September 2014 - 03:06 AM
Yeah, scopes tend to confuse me a bit as well. I'd personally probably just check if it works if I let it do everything first, then try to cut back on the scopes.
hbomb79 #20
Posted 01 September 2014 - 05:15 AM
So with your code, I would set the body to my Log Report… And then the token to the one created by that page and give the token all the default options and slowly remove them to the bare minimum… I still dont want people being able to edit source code, as you said thats pretty bad if you cant have testers that cant edit the code, I dont want people being able to edit it freely.

P.S: You've been so helpful, Thank you so much for your help
Edited on 01 September 2014 - 03:23 AM
hbomb79 #21
Posted 01 September 2014 - 05:37 AM

local oauthToken = 'fe88b4293f12a0ddd5a94c3bba3f773108ad5325' -- your oauth token
local auth = "token " .. oauthToken -- value for Authroization header
print('Sending Log...')
local headers={ -- headers sent with every http request to github api
Authorization=auth, -- for authorization
Accept="application/vnd.github.v3+json", -- make sure we get correct version
["User-Agent"]="hbombSSPLogSystem" -- set to something unique, should probably include username (see https://developer.github.com/v3/#user-agent-required)
}
local f = fs.open('systemFiles/logFile.log', 'r')
logBody = f.readAll()
f.close()
print('Log Copied')
local owner = "hbomb79" -- owner of repository
local repo = "securitySystemPro" -- repository
local title = "Auto Bug Report" -- title of issue
title = title:gsub("\\", "\\\\"):gsub("\"", "\\\"") -- make JSON string
local body = 'Testing Log' -- body of issue
body = body:gsub("\\", "\\\\"):gsub("\"", "\\\"") -- make JSON string
local jsonObject=[[
{
"title" : "]] .. title .. [[",
"body" : "]] .. body .. [[",
}]]
print('JSON Assembled')
for i=1, 3 do
  print('Send Attempt: '..i)
  --if http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues", jsonObject, headers) then posted = true else posted = false end
  if http.post("https://api.github.com/repos/" .. owner .. "/" .. repo .. "/issues?access_token=" .. oauthToken, jsonObject) then posted = true else posted = false end
  i = i + 1
end
print('Posted: '..tostring(posted))
if posted == false then
  print('Failed To Post Log Report')
  sleep(1)
  print('Loading Log:')
  sleep(0.5)
  error(logBody)
end


Sorry, But changing the body didnt help, any ideas??
Edited on 01 September 2014 - 03:49 AM
hbomb79 #22
Posted 01 September 2014 - 05:45 AM
gist, repo, user Are the scopes ive issued the token…

Edit: I added write:public_key
Edited on 01 September 2014 - 03:51 AM
natedogith1 #23
Posted 01 September 2014 - 05:51 AM
Huh, I wonder what issue is causing it to return nil (if github didn't require https one could probably just watch it in wireshark). I think I remember hearing about some versions of ComputerCraft having issues if both postData and headers are used in a single request.
hbomb79 #24
Posted 01 September 2014 - 05:55 AM
Huh, I wonder what issue is causing it to return nil (if github didn't require https one could probably just watch it in wireshark). I think I remember hearing about some versions of ComputerCraft having issues if both postData and headers are used in a single request.

So theres no fix… I mean Ive seen this done before, I just cant find it any where on the Internet

EDIT: Ill keep trying but I have no experience with HTTP or anything of the sort which means I really dont know where to start, Im sure someone here has some advice on why the code doesnt want to work
Edited on 01 September 2014 - 04:55 AM
hbomb79 #25
Posted 18 September 2014 - 10:04 PM
Well, using help from oeed I have used my new website to receive information from computercraft and then submit it to my github issues page.