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,202 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_CREATE_PULL_STATUS_CODE = :GITHUB_CREATE_PULL_STATUS_CODE
8
+ GITHUB_CREATE_PULL_RESPONSE = :GITHUB_CREATE_PULL_RESPONSE
9
+ GITHUB_CREATE_PULL_JSON = :GITHUB_CREATE_PULL_JSON
10
+ end
11
+
12
+ class GithubCreatePullAction < 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
+ # Validate parameters
24
+ UI.user_error!("No title provided for pull request, pass using `title: 'PR Title'`") if params[:title].to_s.empty?
25
+ UI.user_error!("Head branch is required for pull request") if params[:head].to_s.empty?
26
+ UI.user_error!("Base branch is required for pull request") if params[:base].to_s.empty?
27
+
28
+ # Build the path
29
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls"
30
+
31
+ # Build body parameters
32
+ body_params = {
33
+ title: params[:title],
34
+ head: params[:head],
35
+ base: params[:base]
36
+ }
37
+
38
+ # Add optional parameters if provided
39
+ body_params[:body] = params[:body] if params[:body]
40
+ body_params[:maintainer_can_modify] = params[:maintainer_can_modify] unless params[:maintainer_can_modify].nil?
41
+ body_params[:draft] = params[:draft] unless params[:draft].nil?
42
+ body_params[:issue] = params[:issue] if params[:issue]
43
+
44
+ UI.message("Creating pull request in #{repo_owner}/#{repo_name}: #{params[:title]}")
45
+ response = Helper::GithubApiHelper.github_api_request(
46
+ token: api_token,
47
+ path: path,
48
+ params: body_params,
49
+ method: :post,
50
+ server_url: server_url
51
+ )
52
+
53
+ status_code = response[:status]
54
+ json_response = response[:json]
55
+ result = {
56
+ status: status_code,
57
+ body: response[:body],
58
+ json: json_response
59
+ }
60
+
61
+ if status_code.between?(200, 299)
62
+ pr_number = json_response['number']
63
+ UI.success("Successfully created pull request ##{pr_number} in #{repo_owner}/#{repo_name}")
64
+ else
65
+ UI.error("Error creating pull request: #{status_code}")
66
+ UI.error(response[:body])
67
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
68
+ return nil
69
+ end
70
+
71
+ # Store the results in shared values
72
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_STATUS_CODE] = status_code
73
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_RESPONSE] = response[:body]
74
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_JSON] = json_response
75
+
76
+ return result
77
+ end
78
+
79
+ #####################################################
80
+ # @!group Documentation
81
+ #####################################################
82
+
83
+ def description
84
+ "Creates a new pull request in a GitHub repository"
85
+ end
86
+
87
+ def details
88
+ [
89
+ "Creates a new pull request in a GitHub repository with the specified title, head branch, base branch, and other optional parameters.",
90
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
91
+ "API Documentation: https://docs.github.com/en/rest/pulls/pulls#create-a-pull-request"
92
+ ].join("\n")
93
+ end
94
+
95
+ def available_options
96
+ [
97
+ FastlaneCore::ConfigItem.new(key: :api_token,
98
+ env_name: "GITHUB_API_TOKEN",
99
+ description: "GitHub API token",
100
+ optional: false,
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: "Owner of the repository",
115
+ optional: false),
116
+ FastlaneCore::ConfigItem.new(key: :repo_name,
117
+ env_name: "GITHUB_API_REPO_NAME",
118
+ description: "Name of the repository",
119
+ optional: false),
120
+ FastlaneCore::ConfigItem.new(key: :title,
121
+ env_name: "GITHUB_API_PR_TITLE",
122
+ description: "The title of the pull request",
123
+ optional: false,
124
+ type: String),
125
+ FastlaneCore::ConfigItem.new(key: :head,
126
+ env_name: "GITHUB_API_PR_HEAD",
127
+ description: "The name of the branch where your changes are implemented (or user:branch for cross-repo PRs)",
128
+ optional: false,
129
+ type: String),
130
+ FastlaneCore::ConfigItem.new(key: :base,
131
+ env_name: "GITHUB_API_PR_BASE",
132
+ description: "The name of the branch you want the changes pulled into",
133
+ optional: false,
134
+ type: String),
135
+ FastlaneCore::ConfigItem.new(key: :body,
136
+ env_name: "GITHUB_API_PR_BODY",
137
+ description: "The body text content of the pull request",
138
+ optional: true,
139
+ type: String),
140
+ FastlaneCore::ConfigItem.new(key: :maintainer_can_modify,
141
+ env_name: "GITHUB_API_PR_MAINTAINER_CAN_MODIFY",
142
+ description: "Whether maintainers can modify the pull request",
143
+ optional: true,
144
+ type: Boolean),
145
+ FastlaneCore::ConfigItem.new(key: :draft,
146
+ env_name: "GITHUB_API_PR_DRAFT",
147
+ description: "Whether the pull request is a draft",
148
+ optional: true,
149
+ type: Boolean),
150
+ FastlaneCore::ConfigItem.new(key: :issue,
151
+ env_name: "GITHUB_API_PR_ISSUE",
152
+ description: "The issue number to convert to a pull request",
153
+ optional: true,
154
+ type: Integer)
155
+ ]
156
+ end
157
+
158
+ def output
159
+ [
160
+ ['GITHUB_CREATE_PULL_STATUS_CODE', 'The status code returned by the GitHub API'],
161
+ ['GITHUB_CREATE_PULL_RESPONSE', 'The full response body returned by the GitHub API'],
162
+ ['GITHUB_CREATE_PULL_JSON', 'The parsed JSON response returned by the GitHub API']
163
+ ]
164
+ end
165
+
166
+ def return_value
167
+ "Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
168
+ end
169
+
170
+ def authors
171
+ ["crazymanish"]
172
+ end
173
+
174
+ def is_supported?(platform)
175
+ true
176
+ end
177
+
178
+ def example_code
179
+ [
180
+ 'github_create_pull(
181
+ repo_owner: "octocat",
182
+ repo_name: "Hello-World",
183
+ title: "Amazing new feature",
184
+ head: "feature-branch",
185
+ base: "main",
186
+ body: "Please pull these awesome changes"
187
+ )',
188
+ 'github_create_pull(
189
+ repo_owner: "octocat",
190
+ repo_name: "Hello-World",
191
+ title: "Bug fix for issue #42",
192
+ head: "fix-branch",
193
+ base: "main",
194
+ body: "This PR fixes issue #42",
195
+ draft: true
196
+ )'
197
+ ]
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,229 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_CREATE_PULL_COMMENT_STATUS_CODE = :GITHUB_CREATE_PULL_COMMENT_STATUS_CODE
8
+ GITHUB_CREATE_PULL_COMMENT_RESPONSE = :GITHUB_CREATE_PULL_COMMENT_RESPONSE
9
+ GITHUB_CREATE_PULL_COMMENT_JSON = :GITHUB_CREATE_PULL_COMMENT_JSON
10
+ end
11
+
12
+ class GithubCreatePullCommentAction < 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
+ # Validate required parameters
25
+ UI.user_error!("Comment body is required") if params[:body].to_s.empty?
26
+
27
+ # Build the path
28
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/comments"
29
+
30
+ # Build body parameters
31
+ body_params = {
32
+ body: params[:body]
33
+ }
34
+
35
+ # Add required parameters for different comment types
36
+ if params[:commit_id] && params[:path] && !params[:in_reply_to]
37
+ body_params[:commit_id] = params[:commit_id]
38
+ body_params[:path] = params[:path]
39
+ body_params[:position] = params[:position] if params[:position]
40
+ body_params[:line] = params[:line] if params[:line]
41
+ body_params[:side] = params[:side] if params[:side]
42
+ body_params[:start_line] = params[:start_line] if params[:start_line]
43
+ body_params[:start_side] = params[:start_side] if params[:start_side]
44
+ elsif params[:in_reply_to]
45
+ body_params[:in_reply_to] = params[:in_reply_to]
46
+ else
47
+ UI.user_error!("Either provide commit_id and path OR in_reply_to parameter")
48
+ end
49
+
50
+ UI.message("Creating comment on pull request ##{pull_number} in #{repo_owner}/#{repo_name}")
51
+ response = Helper::GithubApiHelper.github_api_request(
52
+ token: api_token,
53
+ path: path,
54
+ params: body_params,
55
+ method: :post,
56
+ server_url: server_url
57
+ )
58
+
59
+ status_code = response[:status]
60
+ json_response = response[:json]
61
+ result = {
62
+ status: status_code,
63
+ body: response[:body],
64
+ json: json_response
65
+ }
66
+
67
+ if status_code.between?(200, 299)
68
+ comment_id = json_response['id']
69
+ UI.success("Successfully created comment #{comment_id} on pull request ##{pull_number}")
70
+ else
71
+ UI.error("Error creating pull request comment: #{status_code}")
72
+ UI.error(response[:body])
73
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
74
+ return nil
75
+ end
76
+
77
+ # Store the results in shared values
78
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_COMMENT_STATUS_CODE] = status_code
79
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_COMMENT_RESPONSE] = response[:body]
80
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_COMMENT_JSON] = json_response
81
+
82
+ return result
83
+ end
84
+
85
+ #####################################################
86
+ # @!group Documentation
87
+ #####################################################
88
+
89
+ def description
90
+ "Creates a review comment on a pull request"
91
+ end
92
+
93
+ def details
94
+ [
95
+ "Creates a review comment on a pull request. Can create a comment on a specific line/position or in reply to another comment.",
96
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
97
+ "API Documentation: https://docs.github.com/en/rest/pulls/comments#create-a-review-comment-for-a-pull-request"
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",
106
+ optional: false,
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: "Owner of the repository",
121
+ optional: false),
122
+ FastlaneCore::ConfigItem.new(key: :repo_name,
123
+ env_name: "GITHUB_API_REPO_NAME",
124
+ description: "Name of the repository",
125
+ optional: false),
126
+ FastlaneCore::ConfigItem.new(key: :pull_number,
127
+ env_name: "GITHUB_API_PULL_NUMBER",
128
+ description: "The number of the pull request",
129
+ optional: false,
130
+ type: Integer),
131
+ FastlaneCore::ConfigItem.new(key: :body,
132
+ env_name: "GITHUB_API_PR_COMMENT_BODY",
133
+ description: "The text of the review comment",
134
+ optional: false,
135
+ type: String),
136
+ FastlaneCore::ConfigItem.new(key: :commit_id,
137
+ env_name: "GITHUB_API_PR_COMMENT_COMMIT_ID",
138
+ description: "The SHA of the commit to comment on (required when not replying to a comment)",
139
+ optional: true,
140
+ type: String),
141
+ FastlaneCore::ConfigItem.new(key: :path,
142
+ env_name: "GITHUB_API_PR_COMMENT_PATH",
143
+ description: "The relative path to the file being commented on (required when not replying to a comment)",
144
+ optional: true,
145
+ type: String),
146
+ FastlaneCore::ConfigItem.new(key: :position,
147
+ env_name: "GITHUB_API_PR_COMMENT_POSITION",
148
+ description: "The position in the diff to comment on (required when not replying to a comment and line/side not specified)",
149
+ optional: true,
150
+ type: Integer),
151
+ FastlaneCore::ConfigItem.new(key: :line,
152
+ env_name: "GITHUB_API_PR_COMMENT_LINE",
153
+ description: "The line number in the file to comment on (required when position is not specified)",
154
+ optional: true,
155
+ type: Integer),
156
+ FastlaneCore::ConfigItem.new(key: :side,
157
+ env_name: "GITHUB_API_PR_COMMENT_SIDE",
158
+ description: "Side of the diff (LEFT or RIGHT)",
159
+ optional: true,
160
+ type: String,
161
+ verify_block: proc do |value|
162
+ UI.user_error!("Side must be one of: LEFT, RIGHT") unless ["LEFT", "RIGHT"].include?(value)
163
+ end),
164
+ FastlaneCore::ConfigItem.new(key: :start_line,
165
+ env_name: "GITHUB_API_PR_COMMENT_START_LINE",
166
+ description: "The start line number for multi-line comments",
167
+ optional: true,
168
+ type: Integer),
169
+ FastlaneCore::ConfigItem.new(key: :start_side,
170
+ env_name: "GITHUB_API_PR_COMMENT_START_SIDE",
171
+ description: "Side of the diff for the start line (LEFT or RIGHT)",
172
+ optional: true,
173
+ type: String,
174
+ verify_block: proc do |value|
175
+ UI.user_error!("Start side must be one of: LEFT, RIGHT") unless ["LEFT", "RIGHT"].include?(value)
176
+ end),
177
+ FastlaneCore::ConfigItem.new(key: :in_reply_to,
178
+ env_name: "GITHUB_API_PR_COMMENT_IN_REPLY_TO",
179
+ description: "The ID of the comment to reply to (when creating a reply)",
180
+ optional: true,
181
+ type: Integer)
182
+ ]
183
+ end
184
+
185
+ def output
186
+ [
187
+ ['GITHUB_CREATE_PULL_COMMENT_STATUS_CODE', 'The status code returned by the GitHub API'],
188
+ ['GITHUB_CREATE_PULL_COMMENT_RESPONSE', 'The full response body returned by the GitHub API'],
189
+ ['GITHUB_CREATE_PULL_COMMENT_JSON', 'The parsed JSON response returned by the GitHub API']
190
+ ]
191
+ end
192
+
193
+ def return_value
194
+ "Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
195
+ end
196
+
197
+ def authors
198
+ ["crazymanish"]
199
+ end
200
+
201
+ def is_supported?(platform)
202
+ true
203
+ end
204
+
205
+ def example_code
206
+ [
207
+ 'github_create_pull_comment(
208
+ repo_owner: "octocat",
209
+ repo_name: "Hello-World",
210
+ pull_number: 42,
211
+ body: "Great improvement to this section!",
212
+ commit_id: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
213
+ path: "file.rb",
214
+ line: 42,
215
+ side: "RIGHT"
216
+ )',
217
+ 'github_create_pull_comment(
218
+ repo_owner: "octocat",
219
+ repo_name: "Hello-World",
220
+ pull_number: 42,
221
+ body: "I agree with your suggestion",
222
+ in_reply_to: 123456
223
+ )'
224
+ ]
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,168 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_CREATE_PULL_COMMENT_REACTION_STATUS_CODE = :GITHUB_CREATE_PULL_COMMENT_REACTION_STATUS_CODE
8
+ GITHUB_CREATE_PULL_COMMENT_REACTION_RESPONSE = :GITHUB_CREATE_PULL_COMMENT_REACTION_RESPONSE
9
+ GITHUB_CREATE_PULL_COMMENT_REACTION_JSON = :GITHUB_CREATE_PULL_COMMENT_REACTION_JSON
10
+ end
11
+
12
+ class GithubCreatePullCommentReactionAction < 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
+
25
+ # Build the request body
26
+ body = {
27
+ content: content
28
+ }
29
+
30
+ # Build the path
31
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls/comments/#{comment_id}/reactions"
32
+
33
+ UI.message("Creating '#{content}' reaction for pull request review comment ##{comment_id} in #{repo_owner}/#{repo_name}")
34
+ response = Helper::GithubApiHelper.github_api_request(
35
+ token: api_token,
36
+ path: path,
37
+ params: body,
38
+ method: :post,
39
+ server_url: server_url,
40
+ headers: { 'Accept' => 'application/vnd.github.squirrel-girl-preview+json' }
41
+ )
42
+
43
+ status_code = response[:status]
44
+ json_response = response[:json]
45
+ result = {
46
+ status: status_code,
47
+ body: response[:body],
48
+ json: json_response
49
+ }
50
+
51
+ if status_code.between?(200, 299)
52
+ UI.success("Successfully created '#{content}' reaction for pull request review comment ##{comment_id}")
53
+ else
54
+ UI.error("Error creating reaction: #{status_code}")
55
+ UI.error(response[:body])
56
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
57
+ return nil
58
+ end
59
+
60
+ # Store the results in shared values
61
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_COMMENT_REACTION_STATUS_CODE] = status_code
62
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_COMMENT_REACTION_RESPONSE] = response[:body]
63
+ Actions.lane_context[SharedValues::GITHUB_CREATE_PULL_COMMENT_REACTION_JSON] = json_response
64
+
65
+ return result
66
+ end
67
+
68
+ #####################################################
69
+ # @!group Documentation
70
+ #####################################################
71
+
72
+ def description
73
+ "Create a reaction for a pull request review comment"
74
+ end
75
+
76
+ def details
77
+ [
78
+ "Creates a reaction for a pull request review comment.",
79
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
80
+ "API Documentation: https://docs.github.com/en/rest/reactions/reactions#create-reaction-for-a-pull-request-review-comment"
81
+ ].join("\n")
82
+ end
83
+
84
+ def available_options
85
+ [
86
+ FastlaneCore::ConfigItem.new(key: :api_token,
87
+ env_name: "GITHUB_API_TOKEN",
88
+ description: "GitHub API token",
89
+ optional: false,
90
+ sensitive: true,
91
+ code_gen_sensitive: true,
92
+ default_value: ENV["GITHUB_API_TOKEN"],
93
+ verify_block: proc do |value|
94
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
95
+ end),
96
+ FastlaneCore::ConfigItem.new(key: :server_url,
97
+ env_name: "GITHUB_API_SERVER_URL",
98
+ description: "GitHub API server URL",
99
+ optional: true,
100
+ default_value: "https://api.github.com"),
101
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
102
+ env_name: "GITHUB_API_REPO_OWNER",
103
+ description: "Owner of the repository",
104
+ optional: false),
105
+ FastlaneCore::ConfigItem.new(key: :repo_name,
106
+ env_name: "GITHUB_API_REPO_NAME",
107
+ description: "Name of the repository",
108
+ optional: false),
109
+ FastlaneCore::ConfigItem.new(key: :comment_id,
110
+ env_name: "GITHUB_API_COMMENT_ID",
111
+ description: "The ID of the pull request review comment",
112
+ optional: false,
113
+ type: Integer),
114
+ FastlaneCore::ConfigItem.new(key: :content,
115
+ env_name: "GITHUB_API_REACTION_CONTENT",
116
+ description: "The reaction type (+1, -1, laugh, confused, heart, hooray, rocket, eyes)",
117
+ optional: false,
118
+ type: String,
119
+ verify_block: proc do |value|
120
+ valid_reactions = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes']
121
+ UI.user_error!("Invalid reaction content: '#{value}'. Must be one of: #{valid_reactions.join(', ')}") unless valid_reactions.include?(value)
122
+ end)
123
+ ]
124
+ end
125
+
126
+ def output
127
+ [
128
+ ['GITHUB_CREATE_PULL_COMMENT_REACTION_STATUS_CODE', 'The status code returned by the GitHub API'],
129
+ ['GITHUB_CREATE_PULL_COMMENT_REACTION_RESPONSE', 'The full response body returned by the GitHub API'],
130
+ ['GITHUB_CREATE_PULL_COMMENT_REACTION_JSON', 'The parsed JSON response returned by the GitHub API']
131
+ ]
132
+ end
133
+
134
+ def return_value
135
+ "Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
136
+ end
137
+
138
+ def authors
139
+ ["crazymanish"]
140
+ end
141
+
142
+ def is_supported?(platform)
143
+ true
144
+ end
145
+
146
+ def example_code
147
+ [
148
+ 'github_create_pull_comment_reaction(
149
+ repo_owner: "octocat",
150
+ repo_name: "Hello-World",
151
+ comment_id: 123,
152
+ content: "+1"
153
+ )',
154
+ 'reaction = github_create_pull_comment_reaction(
155
+ repo_owner: "octocat",
156
+ repo_name: "Hello-World",
157
+ comment_id: 123,
158
+ content: "heart"
159
+ )
160
+
161
+ puts "Created reaction: #{reaction[:json]["content"]}"
162
+ puts "Reaction ID: #{reaction[:json]["id"]}"'
163
+ ]
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end