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,152 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_CHECK_PULL_MERGED_STATUS_CODE = :GITHUB_CHECK_PULL_MERGED_STATUS_CODE
8
+ GITHUB_CHECK_PULL_MERGED_RESPONSE = :GITHUB_CHECK_PULL_MERGED_RESPONSE
9
+ GITHUB_PULL_IS_MERGED = :GITHUB_PULL_IS_MERGED
10
+ end
11
+
12
+ class GithubCheckPullMergedAction < Action
13
+ class << self
14
+ def run(params)
15
+ # Prepare API call parameters
16
+ server_url = params[:server_url]
17
+ api_token = params[:api_token]
18
+ repo_owner = params[:repo_owner]
19
+ repo_name = params[:repo_name]
20
+ pull_number = params[:pull_number]
21
+
22
+ # Build the path
23
+ path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/merge"
24
+
25
+ UI.message("Checking if pull request ##{pull_number} from #{repo_owner}/#{repo_name} is merged")
26
+ response = Helper::GithubApiHelper.github_api_request(
27
+ token: api_token,
28
+ path: path,
29
+ method: :get,
30
+ server_url: server_url
31
+ )
32
+
33
+ status_code = response[:status]
34
+ is_merged = status_code == 204
35
+ result = {
36
+ status: status_code,
37
+ body: response[:body],
38
+ is_merged: is_merged
39
+ }
40
+
41
+ if is_merged
42
+ UI.success("Pull request ##{pull_number} has been merged")
43
+ elsif status_code == 404
44
+ UI.message("Pull request ##{pull_number} has not been merged")
45
+ else
46
+ UI.error("Error checking if pull request is merged: #{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_CHECK_PULL_MERGED_STATUS_CODE] = status_code
54
+ Actions.lane_context[SharedValues::GITHUB_CHECK_PULL_MERGED_RESPONSE] = response[:body]
55
+ Actions.lane_context[SharedValues::GITHUB_PULL_IS_MERGED] = is_merged
56
+
57
+ return result
58
+ end
59
+
60
+ #####################################################
61
+ # @!group Documentation
62
+ #####################################################
63
+
64
+ def description
65
+ "Check if a pull request has been merged"
66
+ end
67
+
68
+ def details
69
+ [
70
+ "Checks if a pull request has been merged.",
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#check-if-a-pull-request-has-been-merged"
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_CHECK_PULL_MERGED_STATUS_CODE', 'The status code returned by the GitHub API'],
112
+ ['GITHUB_CHECK_PULL_MERGED_RESPONSE', 'The full response body returned by the GitHub API'],
113
+ ['GITHUB_PULL_IS_MERGED', 'Boolean indicating whether the pull request has been merged']
114
+ ]
115
+ end
116
+
117
+ def return_value
118
+ "Returns a hash containing the status code, response body, and a boolean indicating if the pull request is merged."
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_check_pull_merged(
132
+ repo_owner: "octocat",
133
+ repo_name: "Hello-World",
134
+ pull_number: 42
135
+ )',
136
+ 'result = github_check_pull_merged(
137
+ repo_owner: "octocat",
138
+ repo_name: "Hello-World",
139
+ pull_number: 42
140
+ )
141
+
142
+ if result[:is_merged]
143
+ puts "Pull request #42 has been merged!"
144
+ else
145
+ puts "Pull request #42 has not been merged yet."
146
+ end'
147
+ ]
148
+ end
149
+ end
150
+ end
151
+ end
152
+ 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_COMMIT_COMMENT_REACTION_STATUS_CODE = :GITHUB_CREATE_COMMIT_COMMENT_REACTION_STATUS_CODE
8
+ GITHUB_CREATE_COMMIT_COMMENT_REACTION_RESPONSE = :GITHUB_CREATE_COMMIT_COMMENT_REACTION_RESPONSE
9
+ GITHUB_CREATE_COMMIT_COMMENT_REACTION_JSON = :GITHUB_CREATE_COMMIT_COMMENT_REACTION_JSON
10
+ end
11
+
12
+ class GithubCreateCommitCommentReactionAction < 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}/comments/#{comment_id}/reactions"
32
+
33
+ UI.message("Creating '#{content}' reaction for commit 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 commit 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_COMMIT_COMMENT_REACTION_STATUS_CODE] = status_code
62
+ Actions.lane_context[SharedValues::GITHUB_CREATE_COMMIT_COMMENT_REACTION_RESPONSE] = response[:body]
63
+ Actions.lane_context[SharedValues::GITHUB_CREATE_COMMIT_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 commit comment"
74
+ end
75
+
76
+ def details
77
+ [
78
+ "Creates a reaction for a commit 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-commit-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 commit 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_COMMIT_COMMENT_REACTION_STATUS_CODE', 'The status code returned by the GitHub API'],
129
+ ['GITHUB_CREATE_COMMIT_COMMENT_REACTION_RESPONSE', 'The full response body returned by the GitHub API'],
130
+ ['GITHUB_CREATE_COMMIT_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_commit_comment_reaction(
149
+ repo_owner: "octocat",
150
+ repo_name: "Hello-World",
151
+ comment_id: 123,
152
+ content: "+1"
153
+ )',
154
+ 'reaction = github_create_commit_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
@@ -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_CREATE_ISSUE_STATUS_CODE = :GITHUB_CREATE_ISSUE_STATUS_CODE
8
+ GITHUB_CREATE_ISSUE_RESPONSE = :GITHUB_CREATE_ISSUE_RESPONSE
9
+ GITHUB_CREATE_ISSUE_JSON = :GITHUB_CREATE_ISSUE_JSON
10
+ end
11
+
12
+ class GithubCreateIssueAction < 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 issue, pass using `title: 'Issue Title'`") if params[:title].to_s.empty?
25
+
26
+ # Build the path
27
+ path = "/repos/#{repo_owner}/#{repo_name}/issues"
28
+
29
+ # Build body parameters
30
+ body_params = {
31
+ title: params[:title],
32
+ body: params[:body]
33
+ }
34
+
35
+ # Add optional parameters if provided
36
+ body_params[:assignees] = params[:assignees] if params[:assignees]
37
+ body_params[:milestone] = params[:milestone] if params[:milestone]
38
+ body_params[:labels] = params[:labels] if params[:labels]
39
+
40
+ UI.message("Creating new issue in #{repo_owner}/#{repo_name}: #{params[:title]}")
41
+ response = Helper::GithubApiHelper.github_api_request(
42
+ token: api_token,
43
+ path: path,
44
+ params: body_params,
45
+ method: :post,
46
+ server_url: server_url
47
+ )
48
+
49
+ status_code = response[:status]
50
+ json_response = response[:json]
51
+ result = {
52
+ status: status_code,
53
+ body: response[:body],
54
+ json: json_response
55
+ }
56
+
57
+ if status_code.between?(200, 299)
58
+ issue_number = json_response['number']
59
+ UI.success("Successfully created issue ##{issue_number} in #{repo_owner}/#{repo_name}")
60
+ else
61
+ UI.error("Error creating issue: #{status_code}")
62
+ UI.error(response[:body])
63
+ UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
64
+ return nil
65
+ end
66
+
67
+ # Store the results in shared values
68
+ Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_STATUS_CODE] = status_code
69
+ Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_RESPONSE] = response[:body]
70
+ Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_JSON] = json_response
71
+
72
+ return result
73
+ end
74
+
75
+ #####################################################
76
+ # @!group Documentation
77
+ #####################################################
78
+
79
+ def description
80
+ "Creates a new GitHub issue"
81
+ end
82
+
83
+ def details
84
+ [
85
+ "Creates a new issue in a GitHub repository with the specified title, body, and other optional parameters.",
86
+ "You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
87
+ "API Documentation: https://docs.github.com/en/rest/issues/issues#create-an-issue"
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",
96
+ optional: false,
97
+ sensitive: true,
98
+ code_gen_sensitive: true,
99
+ default_value: ENV["GITHUB_API_TOKEN"],
100
+ verify_block: proc do |value|
101
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
102
+ end),
103
+ FastlaneCore::ConfigItem.new(key: :server_url,
104
+ env_name: "GITHUB_API_SERVER_URL",
105
+ description: "GitHub API server URL",
106
+ optional: true,
107
+ default_value: "https://api.github.com"),
108
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
109
+ env_name: "GITHUB_API_REPO_OWNER",
110
+ description: "Repository owner (organization or username)",
111
+ optional: false,
112
+ type: String,
113
+ verify_block: proc do |value|
114
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
115
+ end),
116
+ FastlaneCore::ConfigItem.new(key: :repo_name,
117
+ env_name: "GITHUB_API_REPO_NAME",
118
+ description: "Repository name",
119
+ optional: false,
120
+ type: String,
121
+ verify_block: proc do |value|
122
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
123
+ end),
124
+ FastlaneCore::ConfigItem.new(key: :title,
125
+ description: "The title of the issue",
126
+ optional: false,
127
+ type: String,
128
+ verify_block: proc do |value|
129
+ UI.user_error!("No title provided, pass using `title: 'Issue Title'`") if value.to_s.empty?
130
+ end),
131
+ FastlaneCore::ConfigItem.new(key: :body,
132
+ description: "The body content of the issue",
133
+ optional: true,
134
+ type: String),
135
+ FastlaneCore::ConfigItem.new(key: :assignees,
136
+ description: "Array of logins for users to assign to the issue",
137
+ optional: true,
138
+ type: Array),
139
+ FastlaneCore::ConfigItem.new(key: :milestone,
140
+ description: "The milestone number to associate with this issue",
141
+ optional: true,
142
+ type: Integer),
143
+ FastlaneCore::ConfigItem.new(key: :labels,
144
+ description: "Array of labels to associate with this issue",
145
+ optional: true,
146
+ type: Array)
147
+ ]
148
+ end
149
+
150
+ def output
151
+ [
152
+ ['GITHUB_CREATE_ISSUE_STATUS_CODE', 'The status code returned from the GitHub API'],
153
+ ['GITHUB_CREATE_ISSUE_RESPONSE', 'The full response body from the GitHub API'],
154
+ ['GITHUB_CREATE_ISSUE_JSON', 'The parsed JSON returned from the GitHub API']
155
+ ]
156
+ end
157
+
158
+ def return_value
159
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
160
+ end
161
+
162
+ def authors
163
+ ["crazymanish"]
164
+ end
165
+
166
+ def example_code
167
+ [
168
+ 'github_create_issue(
169
+ api_token: ENV["GITHUB_API_TOKEN"],
170
+ repo_owner: "fastlane",
171
+ repo_name: "fastlane",
172
+ title: "New Feature Request",
173
+ body: "Please implement this awesome feature",
174
+ labels: ["enhancement", "feature-request"],
175
+ assignees: ["username1", "username2"]
176
+ )',
177
+ '# You can also access the response data
178
+ result = github_create_issue(
179
+ api_token: ENV["GITHUB_API_TOKEN"],
180
+ repo_owner: "fastlane",
181
+ repo_name: "fastlane",
182
+ title: "Bug Report",
183
+ body: "Something is not working"
184
+ )
185
+ UI.message("Created issue number: #{result[:json]["number"]}")'
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,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_ISSUE_COMMENT_REACTION_STATUS_CODE = :GITHUB_CREATE_ISSUE_COMMENT_REACTION_STATUS_CODE
8
+ GITHUB_CREATE_ISSUE_COMMENT_REACTION_RESPONSE = :GITHUB_CREATE_ISSUE_COMMENT_REACTION_RESPONSE
9
+ GITHUB_CREATE_ISSUE_COMMENT_REACTION_JSON = :GITHUB_CREATE_ISSUE_COMMENT_REACTION_JSON
10
+ end
11
+
12
+ class GithubCreateIssueCommentReactionAction < 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}/issues/comments/#{comment_id}/reactions"
32
+
33
+ UI.message("Creating '#{content}' reaction for issue 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 issue 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_ISSUE_COMMENT_REACTION_STATUS_CODE] = status_code
62
+ Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_COMMENT_REACTION_RESPONSE] = response[:body]
63
+ Actions.lane_context[SharedValues::GITHUB_CREATE_ISSUE_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 an issue comment"
74
+ end
75
+
76
+ def details
77
+ [
78
+ "Creates a reaction for an issue 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-an-issue-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 issue 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_ISSUE_COMMENT_REACTION_STATUS_CODE', 'The status code returned by the GitHub API'],
129
+ ['GITHUB_CREATE_ISSUE_COMMENT_REACTION_RESPONSE', 'The full response body returned by the GitHub API'],
130
+ ['GITHUB_CREATE_ISSUE_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_issue_comment_reaction(
149
+ repo_owner: "octocat",
150
+ repo_name: "Hello-World",
151
+ comment_id: 123,
152
+ content: "+1"
153
+ )',
154
+ 'reaction = github_create_issue_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