File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 2525function M .get_platform ()
2626 return M .get_os () .. " -" .. M .get_arch ()
2727end
28+
29+ -- Make authenticated GitHub API request
30+ function M .github_request (url )
31+ local http = require (" http" )
32+ local headers = {}
33+
34+ -- Try to get GitHub token from environment
35+ local token = os.getenv (" GITHUB_TOKEN" ) or os.getenv (" GITHUB_API_TOKEN" ) or os.getenv (" GH_TOKEN" )
36+ if token then
37+ headers [" Authorization" ] = " Bearer " .. token
38+ end
39+
40+ -- Set User-Agent (required by GitHub API)
41+ headers [" User-Agent" ] = " mise-vfox-eca-plugin"
42+
43+ local resp , err = http .get ({
44+ url = url ,
45+ headers = headers
46+ })
47+
48+ if err then
49+ return nil , " HTTP request failed: " .. err
50+ end
51+
52+ if resp .status_code == 403 then
53+ local err_msg = " GitHub API rate limit exceeded. "
54+ if not token then
55+ err_msg = err_msg .. " Please set GITHUB_TOKEN environment variable to authenticate and increase rate limit."
56+ else
57+ err_msg = err_msg .. " Authenticated request failed with 403."
58+ end
59+ return nil , err_msg
60+ end
61+
62+ if resp .status_code ~= 200 then
63+ return nil , " GitHub API returned status code: " .. resp .status_code
64+ end
65+
66+ return resp , nil
67+ end
68+
2869return M
You can’t perform that action at this time.
0 commit comments