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,199 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_GET_ISSUE_TIMELINE_RESPONSE = :GITHUB_GET_ISSUE_TIMELINE_RESPONSE
8
+ GITHUB_GET_ISSUE_TIMELINE_JSON = :GITHUB_GET_ISSUE_TIMELINE_JSON
9
+ GITHUB_GET_ISSUE_TIMELINE_STATUS_CODE = :GITHUB_GET_ISSUE_TIMELINE_STATUS_CODE
10
+ end
11
+
12
+ class GithubGetIssueTimelineAction < 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}/timeline"
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
+ # Custom header required for timeline API
33
+ headers = {
34
+ 'Accept' => 'application/vnd.github.mockingbird-preview+json'
35
+ }
36
+
37
+ # Make the request
38
+ UI.message("Fetching timeline for issue ##{issue_number} in #{repo_owner}/#{repo_name}")
39
+ response = Helper::GithubApiHelper.github_api_request(
40
+ token: token,
41
+ path: path,
42
+ params: query_params,
43
+ method: :get,
44
+ server_url: server_url,
45
+ headers: headers
46
+ )
47
+
48
+ status_code = response.key?('status') ? response['status'] : nil
49
+ result = {
50
+ status: status_code,
51
+ body: response,
52
+ json: response
53
+ }
54
+
55
+ if response.key?('error')
56
+ UI.error("GitHub responded with an error: #{response['error']}")
57
+ UI.user_error!("GitHub API error: #{response['error']}")
58
+ return nil
59
+ end
60
+
61
+ if response.is_a?(Hash) && response['message'] && status_code && status_code >= 400
62
+ UI.error("GitHub API error: #{response['message']}")
63
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
64
+ return nil
65
+ end
66
+
67
+ # Print timeline events count
68
+ if response.is_a?(Array)
69
+ UI.success("Successfully fetched #{response.count} timeline events for issue ##{issue_number}")
70
+ else
71
+ UI.success("Successfully fetched timeline for issue ##{issue_number}")
72
+ end
73
+
74
+ # Set the shared values
75
+ Actions.lane_context[SharedValues::GITHUB_GET_ISSUE_TIMELINE_STATUS_CODE] = status_code
76
+ Actions.lane_context[SharedValues::GITHUB_GET_ISSUE_TIMELINE_RESPONSE] = response
77
+ Actions.lane_context[SharedValues::GITHUB_GET_ISSUE_TIMELINE_JSON] = response
78
+
79
+ return result
80
+ end
81
+
82
+ #####################################################
83
+ # @!group Documentation
84
+ #####################################################
85
+
86
+ def description
87
+ "Gets the timeline of events for a GitHub issue"
88
+ end
89
+
90
+ def details
91
+ [
92
+ "This action fetches the timeline of events for a specific issue in a GitHub repository.",
93
+ "The timeline includes a variety of events beyond basic issue events, such as cross-references, " +
94
+ "assigned events, labeled events, and more.",
95
+ "It requires a valid GitHub API token with appropriate permissions.",
96
+ "Documentation: [https://docs.github.com/en/rest/issues/timeline](https://docs.github.com/en/rest/issues/timeline#list-timeline-events-for-an-issue)"
97
+ ].join("\n")
98
+ end
99
+
100
+ def available_options
101
+ [
102
+ FastlaneCore::ConfigItem.new(key: :api_token,
103
+ env_name: "GITHUB_API_TOKEN",
104
+ description: "GitHub API token with repo permissions",
105
+ optional: false,
106
+ type: String,
107
+ sensitive: true,
108
+ code_gen_sensitive: true,
109
+ default_value: ENV["GITHUB_API_TOKEN"],
110
+ verify_block: proc do |value|
111
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
112
+ end),
113
+ FastlaneCore::ConfigItem.new(key: :server_url,
114
+ env_name: "GITHUB_API_SERVER_URL",
115
+ description: "GitHub API server URL",
116
+ optional: true,
117
+ default_value: "https://api.github.com"),
118
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
119
+ env_name: "GITHUB_API_REPO_OWNER",
120
+ description: "Repository owner (organization or username)",
121
+ optional: false,
122
+ type: String,
123
+ verify_block: proc do |value|
124
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
125
+ end),
126
+ FastlaneCore::ConfigItem.new(key: :repo_name,
127
+ env_name: "GITHUB_API_REPO_NAME",
128
+ description: "Repository name",
129
+ optional: false,
130
+ type: String,
131
+ verify_block: proc do |value|
132
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
133
+ end),
134
+ FastlaneCore::ConfigItem.new(key: :issue_number,
135
+ env_name: "GITHUB_API_ISSUE_NUMBER",
136
+ description: "The issue number",
137
+ optional: false,
138
+ type: Integer),
139
+ FastlaneCore::ConfigItem.new(key: :per_page,
140
+ description: "Results per page (max 100)",
141
+ optional: true,
142
+ default_value: 30,
143
+ type: Integer),
144
+ FastlaneCore::ConfigItem.new(key: :page,
145
+ description: "Page number of the results",
146
+ optional: true,
147
+ default_value: 1,
148
+ type: Integer)
149
+ ]
150
+ end
151
+
152
+ def output
153
+ [
154
+ ['GITHUB_GET_ISSUE_TIMELINE_STATUS_CODE', 'The status code returned from the GitHub API'],
155
+ ['GITHUB_GET_ISSUE_TIMELINE_RESPONSE', 'The full response from the GitHub API'],
156
+ ['GITHUB_GET_ISSUE_TIMELINE_JSON', 'The JSON data returned from the GitHub API']
157
+ ]
158
+ end
159
+
160
+ def return_value
161
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
162
+ end
163
+
164
+ def authors
165
+ ["crazymanish"]
166
+ end
167
+
168
+ def example_code
169
+ [
170
+ 'github_get_issue_timeline(
171
+ api_token: ENV["GITHUB_API_TOKEN"],
172
+ repo_owner: "fastlane",
173
+ repo_name: "fastlane",
174
+ issue_number: 123
175
+ )',
176
+ '# You can also access the response data
177
+ result = github_get_issue_timeline(
178
+ api_token: ENV["GITHUB_API_TOKEN"],
179
+ repo_owner: "fastlane",
180
+ repo_name: "fastlane",
181
+ issue_number: 123
182
+ )
183
+ result[:json].each do |event|
184
+ UI.message("Event: #{event["event_type"] || event["event"]}")
185
+ end'
186
+ ]
187
+ end
188
+
189
+ def category
190
+ :source_control
191
+ end
192
+
193
+ def is_supported?(platform)
194
+ true
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,167 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_GET_MILESTONE_RESPONSE = :GITHUB_GET_MILESTONE_RESPONSE
8
+ GITHUB_GET_MILESTONE_JSON = :GITHUB_GET_MILESTONE_JSON
9
+ GITHUB_GET_MILESTONE_STATUS_CODE = :GITHUB_GET_MILESTONE_STATUS_CODE
10
+ end
11
+
12
+ class GithubGetMilestoneAction < 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
+ milestone_number = params[:milestone_number]
19
+ server_url = params[:server_url]
20
+
21
+ # Validate parameters (additional validation beyond what's in ConfigItem)
22
+ UI.user_error!("No GitHub milestone number given, pass using `milestone_number: 42`") unless milestone_number.to_s.length > 0
23
+
24
+ # Prepare request parameters
25
+ path = "/repos/#{repo_owner}/#{repo_name}/milestones/#{milestone_number}"
26
+
27
+ # Make the request
28
+ UI.message("Fetching milestone ##{milestone_number} from #{repo_owner}/#{repo_name}")
29
+ response = Helper::GithubApiHelper.github_api_request(
30
+ token: token,
31
+ path: path,
32
+ method: :get,
33
+ server_url: server_url
34
+ )
35
+
36
+ status_code = response.key?('status') ? response['status'] : nil
37
+ result = {
38
+ status: status_code,
39
+ body: response,
40
+ json: response
41
+ }
42
+
43
+ if response.key?('error')
44
+ UI.error("GitHub responded with an error: #{response['error']}")
45
+ UI.user_error!("GitHub API error: #{response['error']}")
46
+ return nil
47
+ end
48
+
49
+ if response['message'] && status_code && status_code >= 400
50
+ UI.error("GitHub API error: #{response['message']}")
51
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
52
+ return nil
53
+ end
54
+
55
+ UI.success("Successfully fetched milestone ##{milestone_number} - #{response['title']} from #{repo_owner}/#{repo_name}")
56
+
57
+ # Set the shared values
58
+ Actions.lane_context[SharedValues::GITHUB_GET_MILESTONE_STATUS_CODE] = status_code
59
+ Actions.lane_context[SharedValues::GITHUB_GET_MILESTONE_RESPONSE] = response
60
+ Actions.lane_context[SharedValues::GITHUB_GET_MILESTONE_JSON] = response
61
+
62
+ return result
63
+ end
64
+
65
+ #####################################################
66
+ # @!group Documentation
67
+ #####################################################
68
+
69
+ def description
70
+ "Gets a specific GitHub milestone by number"
71
+ end
72
+
73
+ def details
74
+ [
75
+ "This action fetches a specific milestone from a GitHub repository by its milestone number.",
76
+ "It requires a valid GitHub API token with appropriate permissions.",
77
+ "Documentation: [https://docs.github.com/en/rest/issues/milestones](https://docs.github.com/en/rest/issues/milestones#get-a-milestone)"
78
+ ].join("\n")
79
+ end
80
+
81
+ def available_options
82
+ [
83
+ FastlaneCore::ConfigItem.new(key: :api_token,
84
+ env_name: "GITHUB_API_TOKEN",
85
+ description: "GitHub API token with repo permissions",
86
+ optional: false,
87
+ type: String,
88
+ sensitive: true,
89
+ code_gen_sensitive: true,
90
+ default_value: ENV["GITHUB_API_TOKEN"],
91
+ verify_block: proc do |value|
92
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
93
+ end),
94
+ FastlaneCore::ConfigItem.new(key: :server_url,
95
+ env_name: "GITHUB_API_SERVER_URL",
96
+ description: "GitHub API server URL",
97
+ optional: true,
98
+ default_value: "https://api.github.com"),
99
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
100
+ env_name: "GITHUB_API_REPO_OWNER",
101
+ description: "Repository owner (organization or username)",
102
+ optional: false,
103
+ type: String,
104
+ verify_block: proc do |value|
105
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
106
+ end),
107
+ FastlaneCore::ConfigItem.new(key: :repo_name,
108
+ env_name: "GITHUB_API_REPO_NAME",
109
+ description: "Repository name",
110
+ optional: false,
111
+ type: String,
112
+ verify_block: proc do |value|
113
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
114
+ end),
115
+ FastlaneCore::ConfigItem.new(key: :milestone_number,
116
+ description: "The milestone number",
117
+ optional: false,
118
+ type: Integer)
119
+ ]
120
+ end
121
+
122
+ def output
123
+ [
124
+ ['GITHUB_GET_MILESTONE_STATUS_CODE', 'The status code returned from the GitHub API'],
125
+ ['GITHUB_GET_MILESTONE_RESPONSE', 'The full response from the GitHub API'],
126
+ ['GITHUB_GET_MILESTONE_JSON', 'The JSON data returned from the GitHub API']
127
+ ]
128
+ end
129
+
130
+ def return_value
131
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
132
+ end
133
+
134
+ def authors
135
+ ["crazymanish"]
136
+ end
137
+
138
+ def example_code
139
+ [
140
+ 'github_get_milestone(
141
+ api_token: ENV["GITHUB_API_TOKEN"],
142
+ repo_owner: "fastlane",
143
+ repo_name: "fastlane",
144
+ milestone_number: 42
145
+ )',
146
+ '# You can also access the milestone data
147
+ result = github_get_milestone(
148
+ api_token: ENV["GITHUB_API_TOKEN"],
149
+ repo_owner: "fastlane",
150
+ repo_name: "fastlane",
151
+ milestone_number: 42
152
+ )
153
+ UI.message("Milestone title: #{result[:json]["title"]}")'
154
+ ]
155
+ end
156
+
157
+ def category
158
+ :source_control
159
+ end
160
+
161
+ def is_supported?(platform)
162
+ true
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,150 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_GET_PULL_STATUS_CODE = :GITHUB_GET_PULL_STATUS_CODE
8
+ GITHUB_GET_PULL_RESPONSE = :GITHUB_GET_PULL_RESPONSE
9
+ GITHUB_GET_PULL_JSON = :GITHUB_GET_PULL_JSON
10
+ end
11
+
12
+ class GithubGetPullAction < 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
+ pull_number = params[:pull_number]
23
+
24
+ # Build the path
25
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}"
26
+
27
+ UI.message("Getting pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
28
+ response = Helper::GithubApiHelper.github_api_request(
29
+ token: api_token,
30
+ path: path,
31
+ method: :get,
32
+ server_url: server_url
33
+ )
34
+
35
+ status_code = response[:status]
36
+ json_response = response[:json]
37
+ result = {
38
+ status: status_code,
39
+ body: response[:body],
40
+ json: json_response
41
+ }
42
+
43
+ if status_code.between?(200, 299)
44
+ UI.success("Successfully retrieved pull request ##{pull_number} from #{repo_owner}/#{repo_name}")
45
+ else
46
+ UI.error("Error getting pull request: #{status_code}")
47
+ UI.error(response[:body])
48
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
49
+ return nil
50
+ end
51
+
52
+ # Store the results in shared values
53
+ Actions.lane_context[SharedValues::GITHUB_GET_PULL_STATUS_CODE] = status_code
54
+ Actions.lane_context[SharedValues::GITHUB_GET_PULL_RESPONSE] = response[:body]
55
+ Actions.lane_context[SharedValues::GITHUB_GET_PULL_JSON] = json_response
56
+
57
+ return result
58
+ end
59
+
60
+ #####################################################
61
+ # @!group Documentation
62
+ #####################################################
63
+
64
+ def description
65
+ "Gets a single pull request from a GitHub repository"
66
+ end
67
+
68
+ def details
69
+ [
70
+ "Gets detailed information about a specific pull request by its number.",
71
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
72
+ "API Documentation: https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request"
73
+ ].join("\n")
74
+ end
75
+
76
+ def available_options
77
+ [
78
+ FastlaneCore::ConfigItem.new(key: :api_token,
79
+ env_name: "GITHUB_API_TOKEN",
80
+ description: "GitHub API token",
81
+ optional: false,
82
+ sensitive: true,
83
+ code_gen_sensitive: true,
84
+ default_value: ENV["GITHUB_API_TOKEN"],
85
+ verify_block: proc do |value|
86
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
87
+ end),
88
+ FastlaneCore::ConfigItem.new(key: :server_url,
89
+ env_name: "GITHUB_API_SERVER_URL",
90
+ description: "GitHub API server URL",
91
+ optional: true,
92
+ default_value: "https://api.github.com"),
93
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
94
+ env_name: "GITHUB_API_REPO_OWNER",
95
+ description: "Owner of the repository",
96
+ optional: false),
97
+ FastlaneCore::ConfigItem.new(key: :repo_name,
98
+ env_name: "GITHUB_API_REPO_NAME",
99
+ description: "Name of the repository",
100
+ optional: false),
101
+ FastlaneCore::ConfigItem.new(key: :pull_number,
102
+ env_name: "GITHUB_API_PULL_NUMBER",
103
+ description: "The number of the pull request",
104
+ optional: false,
105
+ type: Integer)
106
+ ]
107
+ end
108
+
109
+ def output
110
+ [
111
+ ['GITHUB_GET_PULL_STATUS_CODE', 'The status code returned by the GitHub API'],
112
+ ['GITHUB_GET_PULL_RESPONSE', 'The full response body returned by the GitHub API'],
113
+ ['GITHUB_GET_PULL_JSON', 'The parsed JSON response returned by the GitHub API']
114
+ ]
115
+ end
116
+
117
+ def return_value
118
+ "Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
119
+ end
120
+
121
+ def authors
122
+ ["crazymanish"]
123
+ end
124
+
125
+ def is_supported?(platform)
126
+ true
127
+ end
128
+
129
+ def example_code
130
+ [
131
+ 'github_get_pull(
132
+ repo_owner: "octocat",
133
+ repo_name: "Hello-World",
134
+ pull_number: 42
135
+ )',
136
+ 'pull_request = github_get_pull(
137
+ repo_owner: "octocat",
138
+ repo_name: "Hello-World",
139
+ pull_number: 42
140
+ )
141
+
142
+ title = pull_request[:json]["title"]
143
+ state = pull_request[:json]["state"]
144
+ puts "Pull Request #42: #{title} (#{state})"'
145
+ ]
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,147 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_GET_PULL_COMMENT_STATUS_CODE = :GITHUB_GET_PULL_COMMENT_STATUS_CODE
8
+ GITHUB_GET_PULL_COMMENT_RESPONSE = :GITHUB_GET_PULL_COMMENT_RESPONSE
9
+ GITHUB_GET_PULL_COMMENT_JSON = :GITHUB_GET_PULL_COMMENT_JSON
10
+ end
11
+
12
+ class GithubGetPullCommentAction < 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
+
24
+ # Build the path
25
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls/comments/#{comment_id}"
26
+
27
+ UI.message("Getting pull request comment #{comment_id} from #{repo_owner}/#{repo_name}")
28
+ response = Helper::GithubApiHelper.github_api_request(
29
+ token: api_token,
30
+ path: path,
31
+ method: :get,
32
+ server_url: server_url
33
+ )
34
+
35
+ status_code = response[:status]
36
+ json_response = response[:json]
37
+ result = {
38
+ status: status_code,
39
+ body: response[:body],
40
+ json: json_response
41
+ }
42
+
43
+ if status_code.between?(200, 299)
44
+ UI.success("Successfully retrieved pull request comment #{comment_id}")
45
+ else
46
+ UI.error("Error getting pull request comment: #{status_code}")
47
+ UI.error(response[:body])
48
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
49
+ return nil
50
+ end
51
+
52
+ # Store the results in shared values
53
+ Actions.lane_context[SharedValues::GITHUB_GET_PULL_COMMENT_STATUS_CODE] = status_code
54
+ Actions.lane_context[SharedValues::GITHUB_GET_PULL_COMMENT_RESPONSE] = response[:body]
55
+ Actions.lane_context[SharedValues::GITHUB_GET_PULL_COMMENT_JSON] = json_response
56
+
57
+ return result
58
+ end
59
+
60
+ #####################################################
61
+ # @!group Documentation
62
+ #####################################################
63
+
64
+ def description
65
+ "Gets a specific pull request comment"
66
+ end
67
+
68
+ def details
69
+ [
70
+ "Gets detailed information about a specific review comment on a pull request.",
71
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
72
+ "API Documentation: https://docs.github.com/en/rest/pulls/comments#get-a-review-comment-for-a-pull-request"
73
+ ].join("\n")
74
+ end
75
+
76
+ def available_options
77
+ [
78
+ FastlaneCore::ConfigItem.new(key: :api_token,
79
+ env_name: "GITHUB_API_TOKEN",
80
+ description: "GitHub API token",
81
+ optional: false,
82
+ sensitive: true,
83
+ code_gen_sensitive: true,
84
+ default_value: ENV["GITHUB_API_TOKEN"],
85
+ verify_block: proc do |value|
86
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
87
+ end),
88
+ FastlaneCore::ConfigItem.new(key: :server_url,
89
+ env_name: "GITHUB_API_SERVER_URL",
90
+ description: "GitHub API server URL",
91
+ optional: true,
92
+ default_value: "https://api.github.com"),
93
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
94
+ env_name: "GITHUB_API_REPO_OWNER",
95
+ description: "Owner of the repository",
96
+ optional: false),
97
+ FastlaneCore::ConfigItem.new(key: :repo_name,
98
+ env_name: "GITHUB_API_REPO_NAME",
99
+ description: "Name of the repository",
100
+ optional: false),
101
+ FastlaneCore::ConfigItem.new(key: :comment_id,
102
+ env_name: "GITHUB_API_PR_COMMENT_ID",
103
+ description: "The ID of the comment",
104
+ optional: false,
105
+ type: Integer)
106
+ ]
107
+ end
108
+
109
+ def output
110
+ [
111
+ ['GITHUB_GET_PULL_COMMENT_STATUS_CODE', 'The status code returned by the GitHub API'],
112
+ ['GITHUB_GET_PULL_COMMENT_RESPONSE', 'The full response body returned by the GitHub API'],
113
+ ['GITHUB_GET_PULL_COMMENT_JSON', 'The parsed JSON response returned by the GitHub API']
114
+ ]
115
+ end
116
+
117
+ def return_value
118
+ "Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
119
+ end
120
+
121
+ def authors
122
+ ["crazymanish"]
123
+ end
124
+
125
+ def is_supported?(platform)
126
+ true
127
+ end
128
+
129
+ def example_code
130
+ [
131
+ 'github_get_pull_comment(
132
+ repo_owner: "octocat",
133
+ repo_name: "Hello-World",
134
+ comment_id: 12345
135
+ )',
136
+ 'comment = github_get_pull_comment(
137
+ repo_owner: "octocat",
138
+ repo_name: "Hello-World",
139
+ comment_id: 12345
140
+ )
141
+ puts "Comment by #{comment[:json]["user"]["login"]}: #{comment[:json]["body"]}"'
142
+ ]
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end