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,192 @@
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_LABELS_RESPONSE = :GITHUB_LIST_ISSUE_LABELS_RESPONSE
8
+ GITHUB_LIST_ISSUE_LABELS_JSON = :GITHUB_LIST_ISSUE_LABELS_JSON
9
+ GITHUB_LIST_ISSUE_LABELS_STATUS_CODE = :GITHUB_LIST_ISSUE_LABELS_STATUS_CODE
10
+ end
11
+
12
+ class GithubListIssueLabelsAction < 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}/labels"
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 labels 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 labels for confirmation
62
+ if response.is_a?(Array)
63
+ label_count = response.count
64
+ label_names = response.map { |label| label['name'] }.join(', ')
65
+ UI.success("Successfully fetched #{label_count} labels for issue ##{issue_number}: #{label_names}")
66
+ else
67
+ UI.success("Successfully fetched labels for issue ##{issue_number}")
68
+ end
69
+
70
+ # Set the shared values
71
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_LABELS_STATUS_CODE] = status_code
72
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_LABELS_RESPONSE] = response
73
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_LABELS_JSON] = response
74
+
75
+ return result
76
+ end
77
+
78
+ #####################################################
79
+ # @!group Documentation
80
+ #####################################################
81
+
82
+ def description
83
+ "Lists labels on a GitHub issue"
84
+ end
85
+
86
+ def details
87
+ [
88
+ "This action fetches all labels applied to a specific issue in a GitHub repository.",
89
+ "It requires a valid GitHub API token with appropriate permissions.",
90
+ "Documentation: [https://docs.github.com/en/rest/issues/labels](https://docs.github.com/en/rest/issues/labels#list-labels-for-an-issue)"
91
+ ].join("\n")
92
+ end
93
+
94
+ def available_options
95
+ [
96
+ FastlaneCore::ConfigItem.new(key: :api_token,
97
+ env_name: "GITHUB_API_TOKEN",
98
+ description: "GitHub API token with repo permissions",
99
+ optional: false,
100
+ type: String,
101
+ sensitive: true,
102
+ code_gen_sensitive: true,
103
+ default_value: ENV["GITHUB_API_TOKEN"],
104
+ verify_block: proc do |value|
105
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
106
+ end),
107
+ FastlaneCore::ConfigItem.new(key: :server_url,
108
+ env_name: "GITHUB_API_SERVER_URL",
109
+ description: "GitHub API server URL",
110
+ optional: true,
111
+ default_value: "https://api.github.com"),
112
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
113
+ env_name: "GITHUB_API_REPO_OWNER",
114
+ description: "Repository owner (organization or username)",
115
+ optional: false,
116
+ type: String,
117
+ verify_block: proc do |value|
118
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
119
+ end),
120
+ FastlaneCore::ConfigItem.new(key: :repo_name,
121
+ env_name: "GITHUB_API_REPO_NAME",
122
+ description: "Repository name",
123
+ optional: false,
124
+ type: String,
125
+ verify_block: proc do |value|
126
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
127
+ end),
128
+ FastlaneCore::ConfigItem.new(key: :issue_number,
129
+ env_name: "GITHUB_API_ISSUE_NUMBER",
130
+ description: "The issue number",
131
+ optional: false,
132
+ type: Integer),
133
+ FastlaneCore::ConfigItem.new(key: :per_page,
134
+ description: "Results per page (max 100)",
135
+ optional: true,
136
+ default_value: 30,
137
+ type: Integer),
138
+ FastlaneCore::ConfigItem.new(key: :page,
139
+ description: "Page number of the results",
140
+ optional: true,
141
+ default_value: 1,
142
+ type: Integer)
143
+ ]
144
+ end
145
+
146
+ def output
147
+ [
148
+ ['GITHUB_LIST_ISSUE_LABELS_STATUS_CODE', 'The status code returned from the GitHub API'],
149
+ ['GITHUB_LIST_ISSUE_LABELS_RESPONSE', 'The full response from the GitHub API'],
150
+ ['GITHUB_LIST_ISSUE_LABELS_JSON', 'The JSON data returned from the GitHub API']
151
+ ]
152
+ end
153
+
154
+ def return_value
155
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
156
+ end
157
+
158
+ def authors
159
+ ["crazymanish"]
160
+ end
161
+
162
+ def example_code
163
+ [
164
+ 'github_list_issue_labels(
165
+ api_token: ENV["GITHUB_API_TOKEN"],
166
+ repo_owner: "fastlane",
167
+ repo_name: "fastlane",
168
+ issue_number: 123
169
+ )',
170
+ '# You can also access the response data
171
+ result = github_list_issue_labels(
172
+ api_token: ENV["GITHUB_API_TOKEN"],
173
+ repo_owner: "fastlane",
174
+ repo_name: "fastlane",
175
+ issue_number: 123
176
+ )
177
+ label_names = result[:json].map { |label| label["name"] }.join(", ")
178
+ UI.message("Labels on issue: #{label_names}")'
179
+ ]
180
+ end
181
+
182
+ def category
183
+ :source_control
184
+ end
185
+
186
+ def is_supported?(platform)
187
+ true
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -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_REACTIONS_STATUS_CODE = :GITHUB_LIST_ISSUE_REACTIONS_STATUS_CODE
8
+ GITHUB_LIST_ISSUE_REACTIONS_RESPONSE = :GITHUB_LIST_ISSUE_REACTIONS_RESPONSE
9
+ GITHUB_LIST_ISSUE_REACTIONS_JSON = :GITHUB_LIST_ISSUE_REACTIONS_JSON
10
+ end
11
+
12
+ class GithubListIssueReactionsAction < 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
+ issue_number = params[:issue_number]
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/#{issue_number}/reactions"
35
+
36
+ UI.message("Listing reactions for issue ##{issue_number} 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 ##{issue_number}")
57
+ else
58
+ UI.error("Error listing issue 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_REACTIONS_STATUS_CODE] = status_code
66
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_REACTIONS_RESPONSE] = response[:body]
67
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUE_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"
78
+ end
79
+
80
+ def details
81
+ [
82
+ "Lists reactions for an issue.",
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"
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: :issue_number,
114
+ env_name: "GITHUB_API_ISSUE_NUMBER",
115
+ description: "The number of the issue",
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_REACTIONS_STATUS_CODE', 'The status code returned by the GitHub API'],
139
+ ['GITHUB_LIST_ISSUE_REACTIONS_RESPONSE', 'The full response body returned by the GitHub API'],
140
+ ['GITHUB_LIST_ISSUE_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_reactions(
159
+ repo_owner: "octocat",
160
+ repo_name: "Hello-World",
161
+ issue_number: 123
162
+ )',
163
+ 'reactions = github_list_issue_reactions(
164
+ repo_owner: "octocat",
165
+ repo_name: "Hello-World",
166
+ issue_number: 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,236 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_LIST_ISSUES_RESPONSE = :GITHUB_LIST_ISSUES_RESPONSE
8
+ GITHUB_LIST_ISSUES_JSON = :GITHUB_LIST_ISSUES_JSON
9
+ GITHUB_LIST_ISSUES_STATUS_CODE = :GITHUB_LIST_ISSUES_STATUS_CODE
10
+ end
11
+
12
+ class GithubListIssuesAction < 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
+ server_url = params[:server_url]
19
+
20
+ # Validate parameters (additional validation beyond what's in ConfigItem)
21
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if repo_owner.to_s.empty?
22
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if repo_name.to_s.empty?
23
+
24
+ # Prepare request parameters
25
+ path = "/repos/#{repo_owner}/#{repo_name}/issues"
26
+
27
+ # Build query parameters
28
+ query_params = {}
29
+ query_params[:state] = params[:state] if params[:state]
30
+ query_params[:assignee] = params[:assignee] if params[:assignee]
31
+ query_params[:creator] = params[:creator] if params[:creator]
32
+ query_params[:mentioned] = params[:mentioned] if params[:mentioned]
33
+ query_params[:labels] = params[:labels].join(',') if params[:labels]
34
+ query_params[:sort] = params[:sort] if params[:sort]
35
+ query_params[:direction] = params[:direction] if params[:direction]
36
+ query_params[:since] = params[:since] if params[:since]
37
+ query_params[:per_page] = params[:per_page] if params[:per_page]
38
+ query_params[:page] = params[:page] if params[:page]
39
+ query_params[:milestone] = params[:milestone] if params[:milestone]
40
+
41
+ # Make the request
42
+ UI.message("Fetching issues for #{repo_owner}/#{repo_name}")
43
+ response = Helper::GithubApiHelper.github_api_request(
44
+ token: token,
45
+ path: path,
46
+ params: query_params,
47
+ method: :get,
48
+ server_url: server_url
49
+ )
50
+
51
+ status_code = response.key?('status') ? response['status'] : nil
52
+ result = {
53
+ status: status_code,
54
+ body: response,
55
+ json: response
56
+ }
57
+
58
+ if response.key?('error')
59
+ UI.error("GitHub responded with an error: #{response['error']}")
60
+ UI.user_error!("GitHub API error: #{response['error']}")
61
+ return nil
62
+ end
63
+
64
+ if response.is_a?(Hash) && response['message'] && status_code && status_code >= 400
65
+ UI.error("GitHub API error: #{response['message']}")
66
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
67
+ return nil
68
+ end
69
+
70
+ # Print issue count
71
+ if response.is_a?(Array)
72
+ UI.success("Successfully fetched #{response.count} issues from #{repo_owner}/#{repo_name}")
73
+ else
74
+ UI.success("Successfully fetched issues from #{repo_owner}/#{repo_name}")
75
+ end
76
+
77
+ # Set the shared values
78
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUES_STATUS_CODE] = status_code
79
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUES_RESPONSE] = response
80
+ Actions.lane_context[SharedValues::GITHUB_LIST_ISSUES_JSON] = response
81
+
82
+ return result
83
+ end
84
+
85
+ #####################################################
86
+ # @!group Documentation
87
+ #####################################################
88
+
89
+ def description
90
+ "Lists issues in a GitHub repository"
91
+ end
92
+
93
+ def details
94
+ [
95
+ "This action fetches a list of issues from a GitHub repository with various filtering options.",
96
+ "It requires a valid GitHub API token with appropriate permissions.",
97
+ "Documentation: [https://docs.github.com/en/rest/issues/issues](https://docs.github.com/en/rest/issues/issues#list-repository-issues)"
98
+ ].join("\n")
99
+ end
100
+
101
+ def available_options
102
+ [
103
+ FastlaneCore::ConfigItem.new(key: :api_token,
104
+ env_name: "GITHUB_API_TOKEN",
105
+ description: "GitHub API token with repo permissions",
106
+ optional: false,
107
+ type: String,
108
+ sensitive: true,
109
+ code_gen_sensitive: true,
110
+ default_value: ENV["GITHUB_API_TOKEN"],
111
+ verify_block: proc do |value|
112
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
113
+ end),
114
+ FastlaneCore::ConfigItem.new(key: :server_url,
115
+ env_name: "GITHUB_API_SERVER_URL",
116
+ description: "GitHub API server URL",
117
+ optional: true,
118
+ default_value: "https://api.github.com"),
119
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
120
+ env_name: "GITHUB_API_REPO_OWNER",
121
+ description: "Repository owner (organization or username)",
122
+ optional: false,
123
+ type: String,
124
+ verify_block: proc do |value|
125
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
126
+ end),
127
+ FastlaneCore::ConfigItem.new(key: :repo_name,
128
+ env_name: "GITHUB_API_REPO_NAME",
129
+ description: "Repository name",
130
+ optional: false,
131
+ type: String,
132
+ verify_block: proc do |value|
133
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
134
+ end),
135
+ FastlaneCore::ConfigItem.new(key: :state,
136
+ description: "Issue state (open, closed, all)",
137
+ optional: true,
138
+ default_value: "open",
139
+ type: String),
140
+ FastlaneCore::ConfigItem.new(key: :assignee,
141
+ description: "GitHub username, or 'none' for unassigned issues",
142
+ optional: true,
143
+ type: String),
144
+ FastlaneCore::ConfigItem.new(key: :creator,
145
+ description: "GitHub username of issue creator",
146
+ optional: true,
147
+ type: String),
148
+ FastlaneCore::ConfigItem.new(key: :mentioned,
149
+ description: "GitHub username that's mentioned in the issue",
150
+ optional: true,
151
+ type: String),
152
+ FastlaneCore::ConfigItem.new(key: :labels,
153
+ description: "Array of label names, comma-separated",
154
+ optional: true,
155
+ type: Array),
156
+ FastlaneCore::ConfigItem.new(key: :sort,
157
+ description: "Sort by (created, updated, comments)",
158
+ optional: true,
159
+ default_value: "created",
160
+ type: String),
161
+ FastlaneCore::ConfigItem.new(key: :direction,
162
+ description: "Sort direction (asc or desc)",
163
+ optional: true,
164
+ default_value: "desc",
165
+ type: String),
166
+ FastlaneCore::ConfigItem.new(key: :since,
167
+ description: "Only issues updated after this ISO 8601 timestamp (YYYY-MM-DDTHH:MM:SSZ)",
168
+ optional: true,
169
+ type: String),
170
+ FastlaneCore::ConfigItem.new(key: :per_page,
171
+ description: "Results per page (max 100)",
172
+ optional: true,
173
+ default_value: 30,
174
+ type: Integer),
175
+ FastlaneCore::ConfigItem.new(key: :page,
176
+ description: "Page number of the results",
177
+ optional: true,
178
+ default_value: 1,
179
+ type: Integer),
180
+ FastlaneCore::ConfigItem.new(key: :milestone,
181
+ description: "Milestone number, 'none' for issues with no milestone, or '*' for issues with any milestone",
182
+ optional: true,
183
+ type: String)
184
+ ]
185
+ end
186
+
187
+ def output
188
+ [
189
+ ['GITHUB_LIST_ISSUES_STATUS_CODE', 'The status code returned from the GitHub API'],
190
+ ['GITHUB_LIST_ISSUES_RESPONSE', 'The full response from the GitHub API'],
191
+ ['GITHUB_LIST_ISSUES_JSON', 'The JSON data returned from the GitHub API']
192
+ ]
193
+ end
194
+
195
+ def return_value
196
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
197
+ end
198
+
199
+ def authors
200
+ ["crazymanish"]
201
+ end
202
+
203
+ def example_code
204
+ [
205
+ 'github_list_issues(
206
+ api_token: ENV["GITHUB_API_TOKEN"],
207
+ repo_owner: "fastlane",
208
+ repo_name: "fastlane",
209
+ state: "open",
210
+ sort: "created",
211
+ direction: "desc"
212
+ )',
213
+ '# You can also access the response data
214
+ result = github_list_issues(
215
+ api_token: ENV["GITHUB_API_TOKEN"],
216
+ repo_owner: "fastlane",
217
+ repo_name: "fastlane",
218
+ labels: ["bug", "critical"]
219
+ )
220
+ result[:json].each do |issue|
221
+ UI.message("Issue ##{issue["number"]}: #{issue["title"]}")
222
+ end'
223
+ ]
224
+ end
225
+
226
+ def category
227
+ :source_control
228
+ end
229
+
230
+ def is_supported?(platform)
231
+ true
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end