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,206 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_LIST_PULLS_STATUS_CODE = :GITHUB_LIST_PULLS_STATUS_CODE
8
+ GITHUB_LIST_PULLS_RESPONSE = :GITHUB_LIST_PULLS_RESPONSE
9
+ GITHUB_LIST_PULLS_JSON = :GITHUB_LIST_PULLS_JSON
10
+ end
11
+
12
+ class GithubListPullsAction < 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
+
23
+ # Build the path
24
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls"
25
+
26
+ # Build query parameters
27
+ query_params = {}
28
+ query_params[:state] = params[:state] if params[:state]
29
+ query_params[:head] = params[:head] if params[:head]
30
+ query_params[:base] = params[:base] if params[:base]
31
+ query_params[:sort] = params[:sort] if params[:sort]
32
+ query_params[:direction] = params[:direction] if params[:direction]
33
+ query_params[:per_page] = params[:per_page] if params[:per_page]
34
+ query_params[:page] = params[:page] if params[:page]
35
+
36
+ UI.message("Listing pull requests for #{repo_owner}/#{repo_name}")
37
+ response = Helper::GithubApiHelper.github_api_request(
38
+ token: api_token,
39
+ path: path,
40
+ params: query_params,
41
+ method: :get,
42
+ server_url: server_url
43
+ )
44
+
45
+ status_code = response[:status]
46
+ json_response = response[:json]
47
+ result = {
48
+ status: status_code,
49
+ body: response[:body],
50
+ json: json_response
51
+ }
52
+
53
+ if status_code.between?(200, 299)
54
+ pull_count = json_response.count
55
+ UI.success("Successfully retrieved #{pull_count} pull requests from #{repo_owner}/#{repo_name}")
56
+ else
57
+ UI.error("Error listing pull requests: #{status_code}")
58
+ UI.error(response[:body])
59
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
60
+ return nil
61
+ end
62
+
63
+ # Store the results in shared values
64
+ Actions.lane_context[SharedValues::GITHUB_LIST_PULLS_STATUS_CODE] = status_code
65
+ Actions.lane_context[SharedValues::GITHUB_LIST_PULLS_RESPONSE] = response[:body]
66
+ Actions.lane_context[SharedValues::GITHUB_LIST_PULLS_JSON] = json_response
67
+
68
+ return result
69
+ end
70
+
71
+ #####################################################
72
+ # @!group Documentation
73
+ #####################################################
74
+
75
+ def description
76
+ "Lists pull requests in a GitHub repository"
77
+ end
78
+
79
+ def details
80
+ [
81
+ "Lists pull requests in a GitHub repository with filtering options.",
82
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
83
+ "API Documentation: https://docs.github.com/en/rest/pulls/pulls#list-pull-requests"
84
+ ].join("\n")
85
+ end
86
+
87
+ def available_options
88
+ [
89
+ FastlaneCore::ConfigItem.new(key: :api_token,
90
+ env_name: "GITHUB_API_TOKEN",
91
+ description: "GitHub API token",
92
+ optional: false,
93
+ sensitive: true,
94
+ code_gen_sensitive: true,
95
+ default_value: ENV["GITHUB_API_TOKEN"],
96
+ verify_block: proc do |value|
97
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
98
+ end),
99
+ FastlaneCore::ConfigItem.new(key: :server_url,
100
+ env_name: "GITHUB_API_SERVER_URL",
101
+ description: "GitHub API server URL",
102
+ optional: true,
103
+ default_value: "https://api.github.com"),
104
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
105
+ env_name: "GITHUB_API_REPO_OWNER",
106
+ description: "Owner of the repository",
107
+ optional: false),
108
+ FastlaneCore::ConfigItem.new(key: :repo_name,
109
+ env_name: "GITHUB_API_REPO_NAME",
110
+ description: "Name of the repository",
111
+ optional: false),
112
+ FastlaneCore::ConfigItem.new(key: :state,
113
+ env_name: "GITHUB_API_PR_STATE",
114
+ description: "State of the PR: open, closed, or all",
115
+ optional: true,
116
+ default_value: "open",
117
+ type: String,
118
+ verify_block: proc do |value|
119
+ UI.user_error!("State must be one of: open, closed, all") unless ["open", "closed", "all"].include?(value)
120
+ end),
121
+ FastlaneCore::ConfigItem.new(key: :head,
122
+ env_name: "GITHUB_API_PR_HEAD",
123
+ description: "Filter by head user or head organization and branch name in the format of user:ref-name or organization:ref-name",
124
+ optional: true,
125
+ type: String),
126
+ FastlaneCore::ConfigItem.new(key: :base,
127
+ env_name: "GITHUB_API_PR_BASE",
128
+ description: "Filter by base branch name",
129
+ optional: true,
130
+ type: String),
131
+ FastlaneCore::ConfigItem.new(key: :sort,
132
+ env_name: "GITHUB_API_PR_SORT",
133
+ description: "What to sort results by: created, updated, popularity, long-running",
134
+ optional: true,
135
+ default_value: "created",
136
+ type: String,
137
+ verify_block: proc do |value|
138
+ UI.user_error!("Sort must be one of: created, updated, popularity, long-running") unless ["created", "updated", "popularity", "long-running"].include?(value)
139
+ end),
140
+ FastlaneCore::ConfigItem.new(key: :direction,
141
+ env_name: "GITHUB_API_PR_DIRECTION",
142
+ description: "The direction of the sort: asc or desc",
143
+ optional: true,
144
+ default_value: "desc",
145
+ type: String,
146
+ verify_block: proc do |value|
147
+ UI.user_error!("Direction must be one of: asc, desc") unless ["asc", "desc"].include?(value)
148
+ end),
149
+ FastlaneCore::ConfigItem.new(key: :per_page,
150
+ env_name: "GITHUB_API_PR_PER_PAGE",
151
+ description: "Results per page (max 100)",
152
+ optional: true,
153
+ type: Integer),
154
+ FastlaneCore::ConfigItem.new(key: :page,
155
+ env_name: "GITHUB_API_PR_PAGE",
156
+ description: "Page number of the results to fetch",
157
+ optional: true,
158
+ type: Integer)
159
+ ]
160
+ end
161
+
162
+ def output
163
+ [
164
+ ['GITHUB_LIST_PULLS_STATUS_CODE', 'The status code returned by the GitHub API'],
165
+ ['GITHUB_LIST_PULLS_RESPONSE', 'The full response body returned by the GitHub API'],
166
+ ['GITHUB_LIST_PULLS_JSON', 'The parsed JSON response returned by the GitHub API']
167
+ ]
168
+ end
169
+
170
+ def return_value
171
+ "Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
172
+ end
173
+
174
+ def authors
175
+ ["crazymanish"]
176
+ end
177
+
178
+ def is_supported?(platform)
179
+ true
180
+ end
181
+
182
+ def example_code
183
+ [
184
+ 'github_list_pulls(
185
+ repo_owner: "octocat",
186
+ repo_name: "Hello-World",
187
+ state: "open"
188
+ )',
189
+ 'pulls = github_list_pulls(
190
+ repo_owner: "octocat",
191
+ repo_name: "Hello-World",
192
+ base: "main",
193
+ sort: "created",
194
+ direction: "desc",
195
+ per_page: 10
196
+ )
197
+
198
+ pulls[:json].each do |pull|
199
+ puts "PR ##{pull["number"]}: #{pull["title"]}"
200
+ end'
201
+ ]
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,185 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_LIST_REPO_ISSUE_EVENTS_RESPONSE = :GITHUB_LIST_REPO_ISSUE_EVENTS_RESPONSE
8
+ GITHUB_LIST_REPO_ISSUE_EVENTS_JSON = :GITHUB_LIST_REPO_ISSUE_EVENTS_JSON
9
+ GITHUB_LIST_REPO_ISSUE_EVENTS_STATUS_CODE = :GITHUB_LIST_REPO_ISSUE_EVENTS_STATUS_CODE
10
+ end
11
+
12
+ class GithubListRepoIssueEventsAction < 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/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 issue events for repository #{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 event count
62
+ if response.is_a?(Array)
63
+ UI.success("Successfully fetched #{response.count} issue events from #{repo_owner}/#{repo_name}")
64
+ else
65
+ UI.success("Successfully fetched repository issue events from #{repo_owner}/#{repo_name}")
66
+ end
67
+
68
+ # Set the shared values
69
+ Actions.lane_context[SharedValues::GITHUB_LIST_REPO_ISSUE_EVENTS_STATUS_CODE] = status_code
70
+ Actions.lane_context[SharedValues::GITHUB_LIST_REPO_ISSUE_EVENTS_RESPONSE] = response
71
+ Actions.lane_context[SharedValues::GITHUB_LIST_REPO_ISSUE_EVENTS_JSON] = response
72
+
73
+ return result
74
+ end
75
+
76
+ #####################################################
77
+ # @!group Documentation
78
+ #####################################################
79
+
80
+ def description
81
+ "Lists issue events for a GitHub repository"
82
+ end
83
+
84
+ def details
85
+ [
86
+ "This action fetches a list of issue events for an entire 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-for-a-repository)"
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: :per_page,
127
+ description: "Results per page (max 100)",
128
+ optional: true,
129
+ default_value: 30,
130
+ type: Integer),
131
+ FastlaneCore::ConfigItem.new(key: :page,
132
+ description: "Page number of the results",
133
+ optional: true,
134
+ default_value: 1,
135
+ type: Integer)
136
+ ]
137
+ end
138
+
139
+ def output
140
+ [
141
+ ['GITHUB_LIST_REPO_ISSUE_EVENTS_STATUS_CODE', 'The status code returned from the GitHub API'],
142
+ ['GITHUB_LIST_REPO_ISSUE_EVENTS_RESPONSE', 'The full response from the GitHub API'],
143
+ ['GITHUB_LIST_REPO_ISSUE_EVENTS_JSON', 'The JSON data returned from the GitHub API']
144
+ ]
145
+ end
146
+
147
+ def return_value
148
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
149
+ end
150
+
151
+ def authors
152
+ ["crazymanish"]
153
+ end
154
+
155
+ def example_code
156
+ [
157
+ 'github_list_repo_issue_events(
158
+ api_token: ENV["GITHUB_API_TOKEN"],
159
+ repo_owner: "fastlane",
160
+ repo_name: "fastlane"
161
+ )',
162
+ '# You can also access the response data
163
+ result = github_list_repo_issue_events(
164
+ api_token: ENV["GITHUB_API_TOKEN"],
165
+ repo_owner: "fastlane",
166
+ repo_name: "fastlane",
167
+ per_page: 100
168
+ )
169
+ result[:json].each do |event|
170
+ UI.message("Event: #{event["event"]}, issue: ##{event["issue"]["number"]}")
171
+ end'
172
+ ]
173
+ end
174
+
175
+ def category
176
+ :source_control
177
+ end
178
+
179
+ def is_supported?(platform)
180
+ true
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,184 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_LIST_REPO_LABELS_RESPONSE = :GITHUB_LIST_REPO_LABELS_RESPONSE
8
+ GITHUB_LIST_REPO_LABELS_JSON = :GITHUB_LIST_REPO_LABELS_JSON
9
+ GITHUB_LIST_REPO_LABELS_STATUS_CODE = :GITHUB_LIST_REPO_LABELS_STATUS_CODE
10
+ end
11
+
12
+ class GithubListRepoLabelsAction < 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}/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 repository #{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
+ if response.is_a?(Array)
62
+ UI.success("Successfully fetched #{response.count} labels from #{repo_owner}/#{repo_name}")
63
+ else
64
+ UI.success("Successfully fetched labels from #{repo_owner}/#{repo_name}")
65
+ end
66
+
67
+ # Set the shared values
68
+ Actions.lane_context[SharedValues::GITHUB_LIST_REPO_LABELS_STATUS_CODE] = status_code
69
+ Actions.lane_context[SharedValues::GITHUB_LIST_REPO_LABELS_RESPONSE] = response
70
+ Actions.lane_context[SharedValues::GITHUB_LIST_REPO_LABELS_JSON] = response
71
+
72
+ return result
73
+ end
74
+
75
+ #####################################################
76
+ # @!group Documentation
77
+ #####################################################
78
+
79
+ def description
80
+ "Lists all labels for a GitHub repository"
81
+ end
82
+
83
+ def details
84
+ [
85
+ "This action fetches all labels defined in a GitHub repository.",
86
+ "It requires a valid GitHub API token with appropriate permissions.",
87
+ "Documentation: [https://docs.github.com/en/rest/issues/labels](https://docs.github.com/en/rest/issues/labels#list-labels-for-a-repository)"
88
+ ].join("\n")
89
+ end
90
+
91
+ def available_options
92
+ [
93
+ FastlaneCore::ConfigItem.new(key: :api_token,
94
+ env_name: "GITHUB_API_TOKEN",
95
+ description: "GitHub API token with repo permissions",
96
+ optional: false,
97
+ type: String,
98
+ sensitive: true,
99
+ code_gen_sensitive: true,
100
+ default_value: ENV["GITHUB_API_TOKEN"],
101
+ verify_block: proc do |value|
102
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
103
+ end),
104
+ FastlaneCore::ConfigItem.new(key: :server_url,
105
+ env_name: "GITHUB_API_SERVER_URL",
106
+ description: "GitHub API server URL",
107
+ optional: true,
108
+ default_value: "https://api.github.com"),
109
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
110
+ env_name: "GITHUB_API_REPO_OWNER",
111
+ description: "Repository owner (organization or username)",
112
+ optional: false,
113
+ type: String,
114
+ verify_block: proc do |value|
115
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
116
+ end),
117
+ FastlaneCore::ConfigItem.new(key: :repo_name,
118
+ env_name: "GITHUB_API_REPO_NAME",
119
+ description: "Repository name",
120
+ optional: false,
121
+ type: String,
122
+ verify_block: proc do |value|
123
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
124
+ end),
125
+ FastlaneCore::ConfigItem.new(key: :per_page,
126
+ description: "Results per page (max 100)",
127
+ optional: true,
128
+ default_value: 30,
129
+ type: Integer),
130
+ FastlaneCore::ConfigItem.new(key: :page,
131
+ description: "Page number of the results",
132
+ optional: true,
133
+ default_value: 1,
134
+ type: Integer)
135
+ ]
136
+ end
137
+
138
+ def output
139
+ [
140
+ ['GITHUB_LIST_REPO_LABELS_STATUS_CODE', 'The status code returned from the GitHub API'],
141
+ ['GITHUB_LIST_REPO_LABELS_RESPONSE', 'The full response from the GitHub API'],
142
+ ['GITHUB_LIST_REPO_LABELS_JSON', 'The JSON data returned from the GitHub API']
143
+ ]
144
+ end
145
+
146
+ def return_value
147
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
148
+ end
149
+
150
+ def authors
151
+ ["crazymanish"]
152
+ end
153
+
154
+ def example_code
155
+ [
156
+ 'github_list_repo_labels(
157
+ api_token: ENV["GITHUB_API_TOKEN"],
158
+ repo_owner: "fastlane",
159
+ repo_name: "fastlane",
160
+ per_page: 100
161
+ )',
162
+ '# You can also access the response data
163
+ result = github_list_repo_labels(
164
+ api_token: ENV["GITHUB_API_TOKEN"],
165
+ repo_owner: "fastlane",
166
+ repo_name: "fastlane"
167
+ )
168
+ result[:json].each do |label|
169
+ UI.message("Label: #{label["name"]}, color: ##{label["color"]}")
170
+ end'
171
+ ]
172
+ end
173
+
174
+ def category
175
+ :source_control
176
+ end
177
+
178
+ def is_supported?(platform)
179
+ true
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end