gh.lua
1 --[[ 2 ToasterGen Spin 3 4 Copyright (C) 2025 Clifton Toaster Reid <cliftontreid@duck.com> 5 6 This library is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with this library. If not, see <https://www.gnu.org/licenses/>. 18 ]] 19 20 local gh = {} 21 22 --- @class ReactionRollup 23 --- @field url string The API URL of the reactions. Format: uri 24 --- @field total_count integer The total number of reactions. 25 --- @field ['+1'] integer The number of thumbs up reactions. 26 --- @field ['-1'] integer The number of thumbs down reactions. 27 --- @field laugh integer The number of laugh reactions. 28 --- @field confused integer The number of confused reactions. 29 --- @field heart integer The number of heart reactions. 30 --- @field hooray integer The number of hooray reactions. 31 --- @field eyes integer The number of eyes reactions. 32 --- @field rocket integer The number of rocket reactions. 33 34 --- @class ReleaseAsset 35 --- @description Data related to a release. 36 --- @field url string The API URL of the asset. Format: uri 37 --- @field browser_download_url string The browser download URL of the asset. Format: uri 38 --- @field id integer The ID of the asset. 39 --- @field node_id string The node ID of the asset. 40 --- @field name string The file name of the asset. Example: "Team Environment" 41 --- @field label string|nil The label of the asset. 42 --- @field state string State of the release asset. Enum: "uploaded", "open" 43 --- @field content_type string The content type of the asset. 44 --- @field size integer The size of the asset in bytes. 45 --- @field download_count integer The number of times the asset has been downloaded. 46 --- @field created_at string The date and time the asset was created. Format: date-time 47 --- @field updated_at string The date and time the asset was updated. Format: date-time 48 --- @field uploader SimpleUser|nil The user who uploaded the asset. 49 50 --- @class SimpleUser 51 --- @description A GitHub user. 52 --- @field name string|nil The name of the user. 53 --- @field email string|nil The email of the user. 54 --- @field login string The login username of the user. Example: "octocat" 55 --- @field id integer The ID of the user. Format: int64. Example: 1 56 --- @field node_id string The node ID of the user. Example: "MDQ6VXNlcjE=" 57 --- @field avatar_url string The avatar URL of the user. Format: uri. Example: "https://github.com/images/error/octocat_happy.gif" 58 --- @field gravatar_id string|nil The gravatar ID of the user. Example: "41d064eb2195891e12d0413f63227ea7" 59 --- @field url string The API URL of the user. Format: uri. Example: "https://api.github.com/users/octocat" 60 --- @field html_url string The HTML URL of the user. Format: uri. Example: "https://github.com/octocat" 61 --- @field followers_url string The API URL for the user's followers. Format: uri. Example: "https://api.github.com/users/octocat/followers" 62 --- @field following_url string The API URL for the users the user is following. Example: "https://api.github.com/users/octocat/following{/other_user}" 63 --- @field gists_url string The API URL for the user's gists. Example: "https://api.github.com/users/octocat/gists{/gist_id}" 64 --- @field starred_url string The API URL for the repos the user has starred. Example: "https://api.github.com/users/octocat/starred{/owner}{/repo}" 65 --- @field subscriptions_url string The API URL for the user's subscriptions. Format: uri. Example: "https://api.github.com/users/octocat/subscriptions" 66 --- @field organizations_url string The API URL for the user's organizations. Format: uri. Example: "https://api.github.com/users/octocat/orgs" 67 --- @field repos_url string The API URL for the user's public repos. Format: uri. Example: "https://api.github.com/users/octocat/repos" 68 --- @field events_url string The API URL for the user's events. Example: "https://api.github.com/users/octocat/events{/privacy}" 69 --- @field received_events_url string The API URL for the events the user has received. Format: uri. Example: "https://api.github.com/users/octocat/received_events" 70 --- @field type string The type of the user. Example: "User" 71 --- @field site_admin boolean Whether the user is a site administrator. 72 --- @field starred_at string Example: "\"2020-07-09T00:17:55Z\"" 73 --- @field user_view_type string Example: "public" 74 75 --- @class Release 76 --- @description A release. 77 --- @field url string The API URL of the release. 78 --- @field html_url string The HTML URL of the release. 79 --- @field assets_url string The API URL for the release's assets. 80 --- @field upload_url string The upload URL for the release's assets. 81 --- @field tarball_url string|nil The tarball URL of the release. 82 --- @field zipball_url string|nil The zipball URL of the release. 83 --- @field id integer The ID of the release. 84 --- @field node_id string The node ID of the release. 85 --- @field tag_name string The name of the tag. Example: "v1.0.0" 86 --- @field target_commitish string Specifies the commitish value that determines where the Git tag is created from. Example: "master" 87 --- @field name string|nil The name of the release. 88 --- @field body string|nil The body of the release notes. 89 --- @field draft boolean true to create a draft (unpublished) release, false to create a published one. Example: false 90 --- @field prerelease boolean Whether to identify the release as a prerelease or a full release. Example: false 91 --- @field created_at string The date and time the release was created. Format: date-time 92 --- @field published_at string|nil The date and time the release was published. Format: date-time 93 --- @field author SimpleUser The author of the release. 94 --- @field assets ReleaseAsset[] array of release assets. 95 --- @field body_html string The HTML version of the release body. 96 --- @field body_text string The plain text version of the release body. 97 --- @field mentions_count integer The number of mentions in the release body. 98 --- @field discussion_url string The URL of the release discussion. 99 --- @field reactions ReactionRollup The reactions to the release. 100 101 --- Fetches the releases for a given GitHub repository. 102 --- @param githubUser string The GitHub username of the repository owner. 103 --- @param githubRepo string The GitHub repository name. 104 --- @param logger Logger The logger to use for output. 105 --- @return Release[]|nil The releases for the repository, or nil if an error occurred. 106 function gh.getReleases(githubUser, githubRepo, logger) 107 local url = string.format("https://api.github.com/repos/%s/%s/releases", githubUser, githubRepo) 108 logger.info("Fetching releases from GitHub API...") 109 local response = http.get(url) 110 if not response then 111 logger.error("Failed to fetch releases from GitHub API") 112 return nil 113 end 114 local data = response.readAll() 115 response.close() 116 logger.debug("Received " .. #data .. " bytes of release data") 117 return textutils.unserializeJSON(data) 118 end 119 120 return gh