fastlane-plugin-github_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +824 -0
  4. data/lib/fastlane/plugin/github_api/actions/github_add_assignees_action.rb +191 -0
  5. data/lib/fastlane/plugin/github_api/actions/github_add_issue_comment_action.rb +184 -0
  6. data/lib/fastlane/plugin/github_api/actions/github_add_labels_action.rb +191 -0
  7. data/lib/fastlane/plugin/github_api/actions/github_api_action.rb +47 -0
  8. data/lib/fastlane/plugin/github_api/actions/github_check_pull_merged_action.rb +152 -0
  9. data/lib/fastlane/plugin/github_api/actions/github_create_commit_comment_reaction_action.rb +168 -0
  10. data/lib/fastlane/plugin/github_api/actions/github_create_issue_action.rb +199 -0
  11. data/lib/fastlane/plugin/github_api/actions/github_create_issue_comment_reaction_action.rb +168 -0
  12. data/lib/fastlane/plugin/github_api/actions/github_create_issue_reaction_action.rb +168 -0
  13. data/lib/fastlane/plugin/github_api/actions/github_create_label_action.rb +194 -0
  14. data/lib/fastlane/plugin/github_api/actions/github_create_milestone_action.rb +199 -0
  15. data/lib/fastlane/plugin/github_api/actions/github_create_pull_action.rb +202 -0
  16. data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_action.rb +229 -0
  17. data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_reaction_action.rb +168 -0
  18. data/lib/fastlane/plugin/github_api/actions/github_create_pull_review_action.rb +224 -0
  19. data/lib/fastlane/plugin/github_api/actions/github_create_repository_action.rb +230 -0
  20. data/lib/fastlane/plugin/github_api/actions/github_delete_commit_comment_reaction_action.rb +152 -0
  21. data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_action.rb +153 -0
  22. data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_reaction_action.rb +152 -0
  23. data/lib/fastlane/plugin/github_api/actions/github_delete_issue_reaction_action.rb +152 -0
  24. data/lib/fastlane/plugin/github_api/actions/github_delete_label_action.rb +164 -0
  25. data/lib/fastlane/plugin/github_api/actions/github_delete_milestone_action.rb +159 -0
  26. data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_action.rb +144 -0
  27. data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_reaction_action.rb +152 -0
  28. data/lib/fastlane/plugin/github_api/actions/github_delete_repository_action.rb +166 -0
  29. data/lib/fastlane/plugin/github_api/actions/github_dismiss_pull_review_action.rb +168 -0
  30. data/lib/fastlane/plugin/github_api/actions/github_get_issue_action.rb +166 -0
  31. data/lib/fastlane/plugin/github_api/actions/github_get_issue_comment_action.rb +174 -0
  32. data/lib/fastlane/plugin/github_api/actions/github_get_issue_event_action.rb +169 -0
  33. data/lib/fastlane/plugin/github_api/actions/github_get_issue_timeline_action.rb +199 -0
  34. data/lib/fastlane/plugin/github_api/actions/github_get_milestone_action.rb +167 -0
  35. data/lib/fastlane/plugin/github_api/actions/github_get_pull_action.rb +150 -0
  36. data/lib/fastlane/plugin/github_api/actions/github_get_pull_comment_action.rb +147 -0
  37. data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_action.rb +137 -0
  38. data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_comments_action.rb +181 -0
  39. data/lib/fastlane/plugin/github_api/actions/github_list_all_pull_comments_action.rb +186 -0
  40. data/lib/fastlane/plugin/github_api/actions/github_list_commit_comment_reactions_action.rb +183 -0
  41. data/lib/fastlane/plugin/github_api/actions/github_list_issue_comment_reactions_action.rb +183 -0
  42. data/lib/fastlane/plugin/github_api/actions/github_list_issue_comments_action.rb +197 -0
  43. data/lib/fastlane/plugin/github_api/actions/github_list_issue_events_action.rb +191 -0
  44. data/lib/fastlane/plugin/github_api/actions/github_list_issue_labels_action.rb +192 -0
  45. data/lib/fastlane/plugin/github_api/actions/github_list_issue_reactions_action.rb +183 -0
  46. data/lib/fastlane/plugin/github_api/actions/github_list_issues_action.rb +236 -0
  47. data/lib/fastlane/plugin/github_api/actions/github_list_milestones_action.rb +205 -0
  48. data/lib/fastlane/plugin/github_api/actions/github_list_pull_comment_reactions_action.rb +183 -0
  49. data/lib/fastlane/plugin/github_api/actions/github_list_pull_comments_action.rb +203 -0
  50. data/lib/fastlane/plugin/github_api/actions/github_list_pull_commits_action.rb +175 -0
  51. data/lib/fastlane/plugin/github_api/actions/github_list_pull_files_action.rb +174 -0
  52. data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviewers_action.rb +163 -0
  53. data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviews_action.rb +175 -0
  54. data/lib/fastlane/plugin/github_api/actions/github_list_pulls_action.rb +206 -0
  55. data/lib/fastlane/plugin/github_api/actions/github_list_repo_issue_events_action.rb +185 -0
  56. data/lib/fastlane/plugin/github_api/actions/github_list_repo_labels_action.rb +184 -0
  57. data/lib/fastlane/plugin/github_api/actions/github_lock_issue_action.rb +180 -0
  58. data/lib/fastlane/plugin/github_api/actions/github_merge_pull_action.rb +191 -0
  59. data/lib/fastlane/plugin/github_api/actions/github_remove_all_labels_action.rb +160 -0
  60. data/lib/fastlane/plugin/github_api/actions/github_remove_assignees_action.rb +195 -0
  61. data/lib/fastlane/plugin/github_api/actions/github_remove_label_action.rb +172 -0
  62. data/lib/fastlane/plugin/github_api/actions/github_remove_pull_reviewers_action.rb +169 -0
  63. data/lib/fastlane/plugin/github_api/actions/github_request_pull_review_action.rb +169 -0
  64. data/lib/fastlane/plugin/github_api/actions/github_set_labels_action.rb +191 -0
  65. data/lib/fastlane/plugin/github_api/actions/github_submit_pull_comment_action.rb +185 -0
  66. data/lib/fastlane/plugin/github_api/actions/github_submit_pull_review_action.rb +187 -0
  67. data/lib/fastlane/plugin/github_api/actions/github_unlock_issue_action.rb +157 -0
  68. data/lib/fastlane/plugin/github_api/actions/github_update_issue_action.rb +202 -0
  69. data/lib/fastlane/plugin/github_api/actions/github_update_issue_comment_action.rb +172 -0
  70. data/lib/fastlane/plugin/github_api/actions/github_update_label_action.rb +204 -0
  71. data/lib/fastlane/plugin/github_api/actions/github_update_milestone_action.rb +198 -0
  72. data/lib/fastlane/plugin/github_api/actions/github_update_pull_action.rb +191 -0
  73. data/lib/fastlane/plugin/github_api/actions/github_update_pull_branch_action.rb +158 -0
  74. data/lib/fastlane/plugin/github_api/actions/github_update_pull_comment_action.rb +156 -0
  75. data/lib/fastlane/plugin/github_api/actions/github_update_pull_review_action.rb +151 -0
  76. data/lib/fastlane/plugin/github_api/helper/github_api_helper.rb +123 -0
  77. data/lib/fastlane/plugin/github_api/version.rb +5 -0
  78. data/lib/fastlane/plugin/github_api.rb +16 -0
  79. metadata +120 -0
@@ -0,0 +1,183 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_LIST_ISSUE_COMMENT_REACTIONS_STATUS_CODE = :GITHUB_LIST_ISSUE_COMMENT_REACTIONS_STATUS_CODE
8
+ GITHUB_LIST_ISSUE_COMMENT_REACTIONS_RESPONSE = :GITHUB_LIST_ISSUE_COMMENT_REACTIONS_RESPONSE
9
+ GITHUB_LIST_ISSUE_COMMENT_REACTIONS_JSON = :GITHUB_LIST_ISSUE_COMMENT_REACTIONS_JSON
10
+ end
11
+
12
+ class GithubListIssueCommentReactionsAction < Action
13
+ class << self
14
+ def run(params)
15
+ require 'json'
16
+
17
+ # Prepare API call parameters
18
+ server_url = params[:server_url]
19
+ api_token = params[:api_token]
20
+ repo_owner = params[:repo_owner]
21
+ repo_name = params[:repo_name]
22
+ comment_id = params[:comment_id]
23
+ content = params[:content]
24
+ per_page = params[:per_page]
25
+ page = params[:page]
26
+
27
+ # Build query parameters
28
+ query_params = {}
29
+ query_params[:content] = content if content
30
+ query_params[:per_page] = per_page if per_page
31
+ query_params[:page] = page if page
32
+
33
+ # Build the path
34
+ path = "/repos/#{repo_owner}/#{repo_name}/issues/comments/#{comment_id}/reactions"
35
+
36
+ UI.message("Listing reactions for issue comment ##{comment_id} in #{repo_owner}/#{repo_name}")
37
+ response = Helper::GithubApiHelper.github_api_request(
38
+ token: api_token,
39
+ path: path,
40
+ params: query_params.empty? ? nil : query_params,
41
+ method: :get,
42
+ server_url: server_url,
43
+ headers: { 'Accept' => 'application/vnd.github.squirrel-girl-preview+json' }
44
+ )
45
+
46
+ status_code = response[:status]
47
+ json_response = response[:json]
48
+ result = {
49
+ status: status_code,
50
+ body: response[:body],
51
+ json: json_response
52
+ }
53
+
54
+ if status_code.between?(200, 299)
55
+ reaction_count = json_response.is_a?(Array) ? json_response.count : 0
56
+ UI.success("Successfully retrieved #{reaction_count} reactions for issue comment ##{comment_id}")
57
+ else
58
+ UI.error("Error listing issue comment reactions: #{status_code}")
59
+ UI.error(response[:body])
60
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
61
+ return nil
62
+ end
63
+
64
+ # Store the results in shared values
65
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_COMMENT_REACTIONS_STATUS_CODE] = status_code
66
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_COMMENT_REACTIONS_RESPONSE] = response[:body]
67
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_COMMENT_REACTIONS_JSON] = json_response
68
+
69
+ return result
70
+ end
71
+
72
+ #####################################################
73
+ # @!group Documentation
74
+ #####################################################
75
+
76
+ def description
77
+ "List reactions for an issue comment"
78
+ end
79
+
80
+ def details
81
+ [
82
+ "Lists reactions for an issue comment.",
83
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
84
+ "API Documentation: https://docs.github.com/en/rest/reactions/reactions#list-reactions-for-an-issue-comment"
85
+ ].join("\n")
86
+ end
87
+
88
+ def available_options
89
+ [
90
+ FastlaneCore::ConfigItem.new(key: :api_token,
91
+ env_name: "GITHUB_API_TOKEN",
92
+ description: "GitHub API token",
93
+ optional: false,
94
+ sensitive: true,
95
+ code_gen_sensitive: true,
96
+ default_value: ENV["GITHUB_API_TOKEN"],
97
+ verify_block: proc do |value|
98
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
99
+ end),
100
+ FastlaneCore::ConfigItem.new(key: :server_url,
101
+ env_name: "GITHUB_API_SERVER_URL",
102
+ description: "GitHub API server URL",
103
+ optional: true,
104
+ default_value: "https://api.github.com"),
105
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
106
+ env_name: "GITHUB_API_REPO_OWNER",
107
+ description: "Owner of the repository",
108
+ optional: false),
109
+ FastlaneCore::ConfigItem.new(key: :repo_name,
110
+ env_name: "GITHUB_API_REPO_NAME",
111
+ description: "Name of the repository",
112
+ optional: false),
113
+ FastlaneCore::ConfigItem.new(key: :comment_id,
114
+ env_name: "GITHUB_API_COMMENT_ID",
115
+ description: "The ID of the issue comment",
116
+ optional: false,
117
+ type: Integer),
118
+ FastlaneCore::ConfigItem.new(key: :content,
119
+ env_name: "GITHUB_API_REACTION_CONTENT",
120
+ description: "Filter reactions by content (e.g., +1, -1, laugh, confused, heart, hooray, rocket, eyes)",
121
+ optional: true,
122
+ type: String),
123
+ FastlaneCore::ConfigItem.new(key: :per_page,
124
+ env_name: "GITHUB_API_PER_PAGE",
125
+ description: "Results per page (max 100)",
126
+ optional: true,
127
+ type: Integer),
128
+ FastlaneCore::ConfigItem.new(key: :page,
129
+ env_name: "GITHUB_API_PAGE",
130
+ description: "Page number of the results to fetch",
131
+ optional: true,
132
+ type: Integer)
133
+ ]
134
+ end
135
+
136
+ def output
137
+ [
138
+ ['GITHUB_LIST_ISSUE_COMMENT_REACTIONS_STATUS_CODE', 'The status code returned by the GitHub API'],
139
+ ['GITHUB_LIST_ISSUE_COMMENT_REACTIONS_RESPONSE', 'The full response body returned by the GitHub API'],
140
+ ['GITHUB_LIST_ISSUE_COMMENT_REACTIONS_JSON', 'The parsed JSON response returned by the GitHub API']
141
+ ]
142
+ end
143
+
144
+ def return_value
145
+ "Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
146
+ end
147
+
148
+ def authors
149
+ ["crazymanish"]
150
+ end
151
+
152
+ def is_supported?(platform)
153
+ true
154
+ end
155
+
156
+ def example_code
157
+ [
158
+ 'github_list_issue_comment_reactions(
159
+ repo_owner: "octocat",
160
+ repo_name: "Hello-World",
161
+ comment_id: 123
162
+ )',
163
+ 'reactions = github_list_issue_comment_reactions(
164
+ repo_owner: "octocat",
165
+ repo_name: "Hello-World",
166
+ comment_id: 123,
167
+ content: "+1",
168
+ per_page: 20,
169
+ page: 1
170
+ )
171
+
172
+ reactions[:json].each do |reaction|
173
+ puts "Reaction: #{reaction["content"]}"
174
+ puts "User: #{reaction["user"]["login"]}"
175
+ puts "Created at: #{reaction["created_at"]}"
176
+ puts "---"
177
+ end'
178
+ ]
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,197 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_LIST_ISSUE_COMMENTS_RESPONSE = :GITHUB_LIST_ISSUE_COMMENTS_RESPONSE
8
+ GITHUB_LIST_ISSUE_COMMENTS_JSON = :GITHUB_LIST_ISSUE_COMMENTS_JSON
9
+ GITHUB_LIST_ISSUE_COMMENTS_STATUS_CODE = :GITHUB_LIST_ISSUE_COMMENTS_STATUS_CODE
10
+ end
11
+
12
+ class GithubListIssueCommentsAction < Action
13
+ class << self
14
+ def run(params)
15
+ token = params[:api_token]
16
+ repo_owner = params[:repo_owner]
17
+ repo_name = params[:repo_name]
18
+ issue_number = params[:issue_number]
19
+ server_url = params[:server_url]
20
+
21
+ # Validate parameters (additional validation beyond what's in ConfigItem)
22
+ UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
23
+
24
+ # Prepare request parameters
25
+ path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/comments"
26
+
27
+ # Build query parameters
28
+ query_params = {}
29
+ query_params[:per_page] = params[:per_page] if params[:per_page]
30
+ query_params[:page] = params[:page] if params[:page]
31
+ query_params[:since] = params[:since] if params[:since]
32
+
33
+ # Make the request
34
+ UI.message("Fetching comments for issue ##{issue_number} in #{repo_owner}/#{repo_name}")
35
+ response = Helper::GithubApiHelper.github_api_request(
36
+ token: token,
37
+ path: path,
38
+ params: query_params,
39
+ method: :get,
40
+ server_url: server_url
41
+ )
42
+
43
+ status_code = response.is_a?(Hash) && response.key?('status') ? response['status'] : nil
44
+ result = {
45
+ status: status_code,
46
+ body: response,
47
+ json: response
48
+ }
49
+
50
+ if response.is_a?(Hash) && response.key?('error')
51
+ UI.error("GitHub responded with an error: #{response['error']}")
52
+ UI.user_error!("GitHub API error: #{response['error']}")
53
+ return nil
54
+ end
55
+
56
+ if response.is_a?(Hash) && response['message'] && status_code && status_code >= 400
57
+ UI.error("GitHub API error: #{response['message']}")
58
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
59
+ return nil
60
+ end
61
+
62
+ # Print comments info
63
+ if response.is_a?(Array)
64
+ UI.success("Successfully fetched #{response.count} comments for issue ##{issue_number}")
65
+ else
66
+ UI.success("Successfully fetched comments for issue ##{issue_number}")
67
+ end
68
+
69
+ # Set the shared values
70
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_COMMENTS_STATUS_CODE] = status_code
71
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_COMMENTS_RESPONSE] = response
72
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_COMMENTS_JSON] = response
73
+
74
+ return result
75
+ end
76
+
77
+ #####################################################
78
+ # @!group Documentation
79
+ #####################################################
80
+
81
+ def description
82
+ "Lists comments on a GitHub issue"
83
+ end
84
+
85
+ def details
86
+ [
87
+ "This action fetches a list of comments on a specific issue in a GitHub repository.",
88
+ "It requires a valid GitHub API token with appropriate permissions.",
89
+ "Documentation: [https://docs.github.com/en/rest/issues/comments](https://docs.github.com/en/rest/issues/comments#list-issue-comments)"
90
+ ].join("\n")
91
+ end
92
+
93
+ def available_options
94
+ [
95
+ FastlaneCore::ConfigItem.new(key: :api_token,
96
+ env_name: "GITHUB_API_TOKEN",
97
+ description: "GitHub API token with repo permissions",
98
+ optional: false,
99
+ type: String,
100
+ sensitive: true,
101
+ code_gen_sensitive: true,
102
+ default_value: ENV["GITHUB_API_TOKEN"],
103
+ verify_block: proc do |value|
104
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
105
+ end),
106
+ FastlaneCore::ConfigItem.new(key: :server_url,
107
+ env_name: "GITHUB_API_SERVER_URL",
108
+ description: "GitHub API server URL",
109
+ optional: true,
110
+ default_value: "https://api.github.com"),
111
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
112
+ env_name: "GITHUB_API_REPO_OWNER",
113
+ description: "Repository owner (organization or username)",
114
+ optional: false,
115
+ type: String,
116
+ verify_block: proc do |value|
117
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
118
+ end),
119
+ FastlaneCore::ConfigItem.new(key: :repo_name,
120
+ env_name: "GITHUB_API_REPO_NAME",
121
+ description: "Repository name",
122
+ optional: false,
123
+ type: String,
124
+ verify_block: proc do |value|
125
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
126
+ end),
127
+ FastlaneCore::ConfigItem.new(key: :issue_number,
128
+ env_name: "GITHUB_API_ISSUE_NUMBER",
129
+ description: "The issue number",
130
+ optional: false,
131
+ type: Integer),
132
+ FastlaneCore::ConfigItem.new(key: :per_page,
133
+ description: "Results per page (max 100)",
134
+ optional: true,
135
+ default_value: 30,
136
+ type: Integer),
137
+ FastlaneCore::ConfigItem.new(key: :page,
138
+ description: "Page number of the results",
139
+ optional: true,
140
+ default_value: 1,
141
+ type: Integer),
142
+ FastlaneCore::ConfigItem.new(key: :since,
143
+ description: "Only show comments updated after a specific ISO 8601 timestamp",
144
+ optional: true,
145
+ type: String)
146
+ ]
147
+ end
148
+
149
+ def output
150
+ [
151
+ ['GITHUB_LIST_ISSUE_COMMENTS_STATUS_CODE', 'The status code returned from the GitHub API'],
152
+ ['GITHUB_LIST_ISSUE_COMMENTS_RESPONSE', 'The full response from the GitHub API'],
153
+ ['GITHUB_LIST_ISSUE_COMMENTS_JSON', 'The JSON data returned from the GitHub API']
154
+ ]
155
+ end
156
+
157
+ def return_value
158
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
159
+ end
160
+
161
+ def authors
162
+ ["crazymanish"]
163
+ end
164
+
165
+ def example_code
166
+ [
167
+ 'github_list_issue_comments(
168
+ api_token: ENV["GITHUB_API_TOKEN"],
169
+ repo_owner: "fastlane",
170
+ repo_name: "fastlane",
171
+ issue_number: 123,
172
+ per_page: 50
173
+ )',
174
+ '# You can also access the response data
175
+ result = github_list_issue_comments(
176
+ api_token: ENV["GITHUB_API_TOKEN"],
177
+ repo_owner: "fastlane",
178
+ repo_name: "fastlane",
179
+ issue_number: 123
180
+ )
181
+ result[:json].each do |comment|
182
+ UI.message("Comment by #{comment["user"]["login"]}: #{comment["body"]}")
183
+ end'
184
+ ]
185
+ end
186
+
187
+ def category
188
+ :source_control
189
+ end
190
+
191
+ def is_supported?(platform)
192
+ true
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,191 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_LIST_ISSUE_EVENTS_RESPONSE = :GITHUB_LIST_ISSUE_EVENTS_RESPONSE
8
+ GITHUB_LIST_ISSUE_EVENTS_JSON = :GITHUB_LIST_ISSUE_EVENTS_JSON
9
+ GITHUB_LIST_ISSUE_EVENTS_STATUS_CODE = :GITHUB_LIST_ISSUE_EVENTS_STATUS_CODE
10
+ end
11
+
12
+ class GithubListIssueEventsAction < Action
13
+ class << self
14
+ def run(params)
15
+ token = params[:api_token]
16
+ repo_owner = params[:repo_owner]
17
+ repo_name = params[:repo_name]
18
+ issue_number = params[:issue_number]
19
+ server_url = params[:server_url]
20
+
21
+ # Validate parameters (additional validation beyond what's in ConfigItem)
22
+ UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
23
+
24
+ # Prepare request parameters
25
+ path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/events"
26
+
27
+ # Build query parameters
28
+ query_params = {}
29
+ query_params[:per_page] = params[:per_page] if params[:per_page]
30
+ query_params[:page] = params[:page] if params[:page]
31
+
32
+ # Make the request
33
+ UI.message("Fetching events for issue ##{issue_number} in #{repo_owner}/#{repo_name}")
34
+ response = Helper::GithubApiHelper.github_api_request(
35
+ token: token,
36
+ path: path,
37
+ params: query_params,
38
+ method: :get,
39
+ server_url: server_url
40
+ )
41
+
42
+ status_code = response.key?('status') ? response['status'] : nil
43
+ result = {
44
+ status: status_code,
45
+ body: response,
46
+ json: response
47
+ }
48
+
49
+ if response.key?('error')
50
+ UI.error("GitHub responded with an error: #{response['error']}")
51
+ UI.user_error!("GitHub API error: #{response['error']}")
52
+ return nil
53
+ end
54
+
55
+ if response.is_a?(Hash) && response['message'] && status_code && status_code >= 400
56
+ UI.error("GitHub API error: #{response['message']}")
57
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
58
+ return nil
59
+ end
60
+
61
+ # Print events info
62
+ if response.is_a?(Array)
63
+ UI.success("Successfully fetched #{response.count} events for issue ##{issue_number}")
64
+ else
65
+ UI.success("Successfully fetched events for issue ##{issue_number}")
66
+ end
67
+
68
+ # Set the shared values
69
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_EVENTS_STATUS_CODE] = status_code
70
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_EVENTS_RESPONSE] = response
71
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_EVENTS_JSON] = response
72
+
73
+ return result
74
+ end
75
+
76
+ #####################################################
77
+ # @!group Documentation
78
+ #####################################################
79
+
80
+ def description
81
+ "Lists events for a GitHub issue"
82
+ end
83
+
84
+ def details
85
+ [
86
+ "This action fetches a list of events for a specific issue in a GitHub repository.",
87
+ "It requires a valid GitHub API token with appropriate permissions.",
88
+ "Documentation: [https://docs.github.com/en/rest/issues/events](https://docs.github.com/en/rest/issues/events#list-issue-events)"
89
+ ].join("\n")
90
+ end
91
+
92
+ def available_options
93
+ [
94
+ FastlaneCore::ConfigItem.new(key: :api_token,
95
+ env_name: "GITHUB_API_TOKEN",
96
+ description: "GitHub API token with repo permissions",
97
+ optional: false,
98
+ type: String,
99
+ sensitive: true,
100
+ code_gen_sensitive: true,
101
+ default_value: ENV["GITHUB_API_TOKEN"],
102
+ verify_block: proc do |value|
103
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
104
+ end),
105
+ FastlaneCore::ConfigItem.new(key: :server_url,
106
+ env_name: "GITHUB_API_SERVER_URL",
107
+ description: "GitHub API server URL",
108
+ optional: true,
109
+ default_value: "https://api.github.com"),
110
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
111
+ env_name: "GITHUB_API_REPO_OWNER",
112
+ description: "Repository owner (organization or username)",
113
+ optional: false,
114
+ type: String,
115
+ verify_block: proc do |value|
116
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
117
+ end),
118
+ FastlaneCore::ConfigItem.new(key: :repo_name,
119
+ env_name: "GITHUB_API_REPO_NAME",
120
+ description: "Repository name",
121
+ optional: false,
122
+ type: String,
123
+ verify_block: proc do |value|
124
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
125
+ end),
126
+ FastlaneCore::ConfigItem.new(key: :issue_number,
127
+ env_name: "GITHUB_API_ISSUE_NUMBER",
128
+ description: "The issue number",
129
+ optional: false,
130
+ type: Integer),
131
+ FastlaneCore::ConfigItem.new(key: :per_page,
132
+ description: "Results per page (max 100)",
133
+ optional: true,
134
+ default_value: 30,
135
+ type: Integer),
136
+ FastlaneCore::ConfigItem.new(key: :page,
137
+ description: "Page number of the results",
138
+ optional: true,
139
+ default_value: 1,
140
+ type: Integer)
141
+ ]
142
+ end
143
+
144
+ def output
145
+ [
146
+ ['GITHUB_LIST_ISSUE_EVENTS_STATUS_CODE', 'The status code returned from the GitHub API'],
147
+ ['GITHUB_LIST_ISSUE_EVENTS_RESPONSE', 'The full response from the GitHub API'],
148
+ ['GITHUB_LIST_ISSUE_EVENTS_JSON', 'The JSON data returned from the GitHub API']
149
+ ]
150
+ end
151
+
152
+ def return_value
153
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
154
+ end
155
+
156
+ def authors
157
+ ["crazymanish"]
158
+ end
159
+
160
+ def example_code
161
+ [
162
+ 'github_list_issue_events(
163
+ api_token: ENV["GITHUB_API_TOKEN"],
164
+ repo_owner: "fastlane",
165
+ repo_name: "fastlane",
166
+ issue_number: 123
167
+ )',
168
+ '# You can also access the response data
169
+ result = github_list_issue_events(
170
+ api_token: ENV["GITHUB_API_TOKEN"],
171
+ repo_owner: "fastlane",
172
+ repo_name: "fastlane",
173
+ issue_number: 123
174
+ )
175
+ result[:json].each do |event|
176
+ UI.message("Event: #{event["event"]}, actor: #{event["actor"]["login"]}")
177
+ end'
178
+ ]
179
+ end
180
+
181
+ def category
182
+ :source_control
183
+ end
184
+
185
+ def is_supported?(platform)
186
+ true
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end