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,172 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_UPDATE_ISSUE_COMMENT_STATUS_CODE = :GITHUB_UPDATE_ISSUE_COMMENT_STATUS_CODE
8
+ GITHUB_UPDATE_ISSUE_COMMENT_RESPONSE = :GITHUB_UPDATE_ISSUE_COMMENT_RESPONSE
9
+ GITHUB_UPDATE_ISSUE_COMMENT_JSON = :GITHUB_UPDATE_ISSUE_COMMENT_JSON
10
+ end
11
+
12
+ class GithubUpdateIssueCommentAction < 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
+ body = params[:body]
24
+
25
+ # Validate parameters
26
+ UI.user_error!("No comment ID provided, pass using `comment_id: 12345678`") unless comment_id.to_s.length > 0
27
+ UI.user_error!("No comment body provided, pass using `body: 'Updated comment'`") if body.to_s.empty?
28
+
29
+ # Build the path
30
+ path = "/repos/#{repo_owner}/#{repo_name}/issues/comments/#{comment_id}"
31
+
32
+ # Build body parameters
33
+ body_params = {
34
+ body: body
35
+ }
36
+
37
+ UI.message("Updating comment ID: #{comment_id} in #{repo_owner}/#{repo_name}")
38
+ response = Helper::GithubApiHelper.github_api_request(
39
+ token: api_token,
40
+ path: path,
41
+ params: body_params,
42
+ method: :patch,
43
+ server_url: server_url
44
+ )
45
+
46
+ status_code = response[:status]
47
+ json_response = response[:json]
48
+ result = {
49
+ status: status_code,
50
+ body: response[:body],
51
+ json: json_response
52
+ }
53
+
54
+ if status_code.between?(200, 299)
55
+ UI.success("Successfully updated comment ID: #{comment_id} in #{repo_owner}/#{repo_name}")
56
+ else
57
+ UI.error("Error updating comment: #{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_UPDATE_ISSUE_COMMENT_STATUS_CODE] = status_code
65
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_ISSUE_COMMENT_RESPONSE] = response[:body]
66
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_ISSUE_COMMENT_JSON] = json_response
67
+
68
+ return result
69
+ end
70
+
71
+ #####################################################
72
+ # @!group Documentation
73
+ #####################################################
74
+
75
+ def description
76
+ "Updates a comment on a GitHub issue"
77
+ end
78
+
79
+ def details
80
+ [
81
+ "Updates an existing comment on an issue in a GitHub repository.",
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/issues/comments#update-an-issue-comment"
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: "Repository owner (organization or username)",
107
+ optional: false,
108
+ type: String),
109
+ FastlaneCore::ConfigItem.new(key: :repo_name,
110
+ env_name: "GITHUB_API_REPO_NAME",
111
+ description: "Repository name",
112
+ optional: false,
113
+ type: String),
114
+ FastlaneCore::ConfigItem.new(key: :comment_id,
115
+ description: "The ID of the comment to update",
116
+ optional: false,
117
+ type: Integer),
118
+ FastlaneCore::ConfigItem.new(key: :body,
119
+ description: "The updated body text of the comment",
120
+ optional: false,
121
+ type: String)
122
+ ]
123
+ end
124
+
125
+ def output
126
+ [
127
+ ['GITHUB_UPDATE_ISSUE_COMMENT_STATUS_CODE', 'The status code returned from the GitHub API'],
128
+ ['GITHUB_UPDATE_ISSUE_COMMENT_RESPONSE', 'The full response body from the GitHub API'],
129
+ ['GITHUB_UPDATE_ISSUE_COMMENT_JSON', 'The parsed JSON returned from the GitHub API']
130
+ ]
131
+ end
132
+
133
+ def return_value
134
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
135
+ end
136
+
137
+ def authors
138
+ ["crazymanish"]
139
+ end
140
+
141
+ def example_code
142
+ [
143
+ 'github_update_issue_comment(
144
+ api_token: ENV["GITHUB_API_TOKEN"],
145
+ repo_owner: "fastlane",
146
+ repo_name: "fastlane",
147
+ comment_id: 12345678,
148
+ body: "Updated comment text"
149
+ )',
150
+ '# You can also access the response data
151
+ result = github_update_issue_comment(
152
+ api_token: ENV["GITHUB_API_TOKEN"],
153
+ repo_owner: "fastlane",
154
+ repo_name: "fastlane",
155
+ comment_id: 12345678,
156
+ body: "Updated comment text"
157
+ )
158
+ UI.message("Updated comment by: #{result[:json]["user"]["login"]}")'
159
+ ]
160
+ end
161
+
162
+ def category
163
+ :source_control
164
+ end
165
+
166
+ def is_supported?(platform)
167
+ true
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,204 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_UPDATE_LABEL_RESPONSE = :GITHUB_UPDATE_LABEL_RESPONSE
8
+ GITHUB_UPDATE_LABEL_JSON = :GITHUB_UPDATE_LABEL_JSON
9
+ GITHUB_UPDATE_LABEL_STATUS_CODE = :GITHUB_UPDATE_LABEL_STATUS_CODE
10
+ end
11
+
12
+ class GithubUpdateLabelAction < 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
+ label_name = params[:name]
19
+ server_url = params[:server_url]
20
+
21
+ # Validate parameters (additional validation beyond what's in ConfigItem)
22
+ UI.user_error!("No label name provided, pass using `name: 'bug'`") if label_name.to_s.empty?
23
+
24
+ # Prepare request parameters
25
+ # URL encode the label name to handle special characters like spaces, etc.
26
+ encoded_label = URI.encode_www_form_component(label_name)
27
+ path = "/repos/#{repo_owner}/#{repo_name}/labels/#{encoded_label}"
28
+
29
+ # Build body parameters
30
+ body_params = {}
31
+ body_params[:new_name] = params[:new_name] if params[:new_name]
32
+
33
+ if params[:color]
34
+ body_params[:color] = params[:color].start_with?('#') ? params[:color][1..-1] : params[:color]
35
+ end
36
+
37
+ body_params[:description] = params[:description] if params[:description]
38
+
39
+ # Make the request
40
+ UI.message("Updating label '#{label_name}' in #{repo_owner}/#{repo_name}")
41
+ response = Helper::GithubApiHelper.github_api_request(
42
+ token: token,
43
+ path: path,
44
+ params: body_params,
45
+ method: :patch,
46
+ server_url: server_url
47
+ )
48
+
49
+ status_code = response.key?('status') ? response['status'] : nil
50
+ result = {
51
+ status: status_code,
52
+ body: response,
53
+ json: response
54
+ }
55
+
56
+ if response.key?('error')
57
+ UI.error("GitHub responded with an error: #{response['error']}")
58
+ UI.user_error!("GitHub API error: #{response['error']}")
59
+ return nil
60
+ end
61
+
62
+ if response['message'] && status_code && status_code >= 400
63
+ UI.error("GitHub API error: #{response['message']}")
64
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
65
+ return nil
66
+ end
67
+
68
+ new_name = params[:new_name] || label_name
69
+ UI.success("Successfully updated label '#{new_name}' in #{repo_owner}/#{repo_name}")
70
+
71
+ # Set the shared values
72
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_LABEL_STATUS_CODE] = status_code
73
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_LABEL_RESPONSE] = response
74
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_LABEL_JSON] = response
75
+
76
+ return result
77
+ end
78
+
79
+ #####################################################
80
+ # @!group Documentation
81
+ #####################################################
82
+
83
+ def description
84
+ "Updates a label in a GitHub repository"
85
+ end
86
+
87
+ def details
88
+ [
89
+ "This action updates an existing label in a GitHub repository, allowing changes to its name, color, and description.",
90
+ "It requires a valid GitHub API token with appropriate permissions.",
91
+ "Documentation: [https://docs.github.com/en/rest/issues/labels](https://docs.github.com/en/rest/issues/labels#update-a-label)"
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 with repo permissions",
100
+ optional: false,
101
+ type: String,
102
+ sensitive: true,
103
+ code_gen_sensitive: true,
104
+ default_value: ENV["GITHUB_API_TOKEN"],
105
+ verify_block: proc do |value|
106
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
107
+ end),
108
+ FastlaneCore::ConfigItem.new(key: :server_url,
109
+ env_name: "GITHUB_API_SERVER_URL",
110
+ description: "GitHub API server URL",
111
+ optional: true,
112
+ default_value: "https://api.github.com"),
113
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
114
+ env_name: "GITHUB_API_REPO_OWNER",
115
+ description: "Repository owner (organization or username)",
116
+ optional: false,
117
+ type: String,
118
+ verify_block: proc do |value|
119
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
120
+ end),
121
+ FastlaneCore::ConfigItem.new(key: :repo_name,
122
+ env_name: "GITHUB_API_REPO_NAME",
123
+ description: "Repository name",
124
+ optional: false,
125
+ type: String,
126
+ verify_block: proc do |value|
127
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
128
+ end),
129
+ FastlaneCore::ConfigItem.new(key: :name,
130
+ description: "The current name of the label",
131
+ optional: false,
132
+ type: String,
133
+ verify_block: proc do |value|
134
+ UI.user_error!("No label name provided, pass using `name: 'bug'`") if value.to_s.empty?
135
+ end),
136
+ FastlaneCore::ConfigItem.new(key: :new_name,
137
+ description: "The new name for the label",
138
+ optional: true,
139
+ type: String),
140
+ FastlaneCore::ConfigItem.new(key: :color,
141
+ description: "The color of the label in hexadecimal format (with or without leading #)",
142
+ optional: true,
143
+ type: String,
144
+ verify_block: proc do |value|
145
+ value = value[1..-1] if value.start_with?('#')
146
+ UI.user_error!("Color must be a valid 6 character hex code") unless value.match?(/^[0-9A-Fa-f]{6}$/)
147
+ end),
148
+ FastlaneCore::ConfigItem.new(key: :description,
149
+ description: "A short description of the label",
150
+ optional: true,
151
+ type: String)
152
+ ]
153
+ end
154
+
155
+ def output
156
+ [
157
+ ['GITHUB_UPDATE_LABEL_STATUS_CODE', 'The status code returned from the GitHub API'],
158
+ ['GITHUB_UPDATE_LABEL_RESPONSE', 'The full response from the GitHub API'],
159
+ ['GITHUB_UPDATE_LABEL_JSON', 'The JSON data returned from the GitHub API']
160
+ ]
161
+ end
162
+
163
+ def return_value
164
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
165
+ end
166
+
167
+ def authors
168
+ ["crazymanish"]
169
+ end
170
+
171
+ def example_code
172
+ [
173
+ 'github_update_label(
174
+ api_token: ENV["GITHUB_API_TOKEN"],
175
+ repo_owner: "fastlane",
176
+ repo_name: "fastlane",
177
+ name: "bug",
178
+ new_name: "confirmed-bug",
179
+ color: "b60205",
180
+ description: "Confirmed bugs that need to be fixed"
181
+ )',
182
+ '# You can also access the response data
183
+ result = github_update_label(
184
+ api_token: ENV["GITHUB_API_TOKEN"],
185
+ repo_owner: "fastlane",
186
+ repo_name: "fastlane",
187
+ name: "enhancement",
188
+ color: "a2eeef"
189
+ )
190
+ UI.message("Updated label color: #{result[:json]["color"]}")'
191
+ ]
192
+ end
193
+
194
+ def category
195
+ :source_control
196
+ end
197
+
198
+ def is_supported?(platform)
199
+ true
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,198 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/github_api_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GITHUB_UPDATE_MILESTONE_RESPONSE = :GITHUB_UPDATE_MILESTONE_RESPONSE
8
+ GITHUB_UPDATE_MILESTONE_JSON = :GITHUB_UPDATE_MILESTONE_JSON
9
+ GITHUB_UPDATE_MILESTONE_STATUS_CODE = :GITHUB_UPDATE_MILESTONE_STATUS_CODE
10
+ end
11
+
12
+ class GithubUpdateMilestoneAction < 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
+ # Build body parameters
28
+ body_params = {}
29
+ body_params[:title] = params[:title] if params[:title]
30
+ body_params[:state] = params[:state] if params[:state]
31
+ body_params[:description] = params[:description] if params[:description]
32
+ body_params[:due_on] = params[:due_on] if params[:due_on]
33
+
34
+ # Make the request
35
+ UI.message("Updating milestone ##{milestone_number} in #{repo_owner}/#{repo_name}")
36
+ response = Helper::GithubApiHelper.github_api_request(
37
+ token: token,
38
+ path: path,
39
+ params: body_params,
40
+ method: :patch,
41
+ server_url: server_url
42
+ )
43
+
44
+ status_code = response.key?('status') ? response['status'] : nil
45
+ result = {
46
+ status: status_code,
47
+ body: response,
48
+ json: response
49
+ }
50
+
51
+ if response.key?('error')
52
+ UI.error("GitHub responded with an error: #{response['error']}")
53
+ UI.user_error!("GitHub API error: #{response['error']}")
54
+ return nil
55
+ end
56
+
57
+ if response['message'] && status_code && status_code >= 400
58
+ UI.error("GitHub API error: #{response['message']}")
59
+ UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
60
+ return nil
61
+ end
62
+
63
+ UI.success("Successfully updated milestone ##{milestone_number} - #{response['title']} in #{repo_owner}/#{repo_name}")
64
+
65
+ # Set the shared values
66
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_MILESTONE_STATUS_CODE] = status_code
67
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_MILESTONE_RESPONSE] = response
68
+ Actions.lane_context[SharedValues::GITHUB_UPDATE_MILESTONE_JSON] = response
69
+
70
+ return result
71
+ end
72
+
73
+ #####################################################
74
+ # @!group Documentation
75
+ #####################################################
76
+
77
+ def description
78
+ "Updates an existing milestone in a GitHub repository"
79
+ end
80
+
81
+ def details
82
+ [
83
+ "This action updates an existing milestone in a GitHub repository with the specified parameters.",
84
+ "It requires a valid GitHub API token with appropriate permissions.",
85
+ "Documentation: [https://docs.github.com/en/rest/issues/milestones](https://docs.github.com/en/rest/issues/milestones#update-a-milestone)"
86
+ ].join("\n")
87
+ end
88
+
89
+ def available_options
90
+ [
91
+ FastlaneCore::ConfigItem.new(key: :api_token,
92
+ env_name: "GITHUB_API_TOKEN",
93
+ description: "GitHub API token with repo permissions",
94
+ optional: false,
95
+ type: String,
96
+ sensitive: true,
97
+ code_gen_sensitive: true,
98
+ default_value: ENV["GITHUB_API_TOKEN"],
99
+ verify_block: proc do |value|
100
+ UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
101
+ end),
102
+ FastlaneCore::ConfigItem.new(key: :server_url,
103
+ env_name: "GITHUB_API_SERVER_URL",
104
+ description: "GitHub API server URL",
105
+ optional: true,
106
+ default_value: "https://api.github.com"),
107
+ FastlaneCore::ConfigItem.new(key: :repo_owner,
108
+ env_name: "GITHUB_API_REPO_OWNER",
109
+ description: "Repository owner (organization or username)",
110
+ optional: false,
111
+ type: String,
112
+ verify_block: proc do |value|
113
+ UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
114
+ end),
115
+ FastlaneCore::ConfigItem.new(key: :repo_name,
116
+ env_name: "GITHUB_API_REPO_NAME",
117
+ description: "Repository name",
118
+ optional: false,
119
+ type: String,
120
+ verify_block: proc do |value|
121
+ UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
122
+ end),
123
+ FastlaneCore::ConfigItem.new(key: :milestone_number,
124
+ description: "The milestone number to update",
125
+ optional: false,
126
+ type: Integer),
127
+ FastlaneCore::ConfigItem.new(key: :title,
128
+ description: "The title of the milestone",
129
+ optional: true,
130
+ type: String),
131
+ FastlaneCore::ConfigItem.new(key: :state,
132
+ description: "The state of the milestone (open or closed)",
133
+ optional: true,
134
+ type: String,
135
+ verify_block: proc do |value|
136
+ UI.user_error!("State must be 'open' or 'closed'") unless ['open', 'closed'].include?(value)
137
+ end),
138
+ FastlaneCore::ConfigItem.new(key: :description,
139
+ description: "A description of the milestone",
140
+ optional: true,
141
+ type: String),
142
+ FastlaneCore::ConfigItem.new(key: :due_on,
143
+ description: "The milestone due date in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)",
144
+ optional: true,
145
+ type: String)
146
+ ]
147
+ end
148
+
149
+ def output
150
+ [
151
+ ['GITHUB_UPDATE_MILESTONE_STATUS_CODE', 'The status code returned from the GitHub API'],
152
+ ['GITHUB_UPDATE_MILESTONE_RESPONSE', 'The full response from the GitHub API'],
153
+ ['GITHUB_UPDATE_MILESTONE_JSON', 'The JSON data returned from the GitHub API']
154
+ ]
155
+ end
156
+
157
+ def return_value
158
+ "A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
159
+ end
160
+
161
+ def authors
162
+ ["crazymanish"]
163
+ end
164
+
165
+ def example_code
166
+ [
167
+ 'github_update_milestone(
168
+ api_token: ENV["GITHUB_API_TOKEN"],
169
+ repo_owner: "fastlane",
170
+ repo_name: "fastlane",
171
+ milestone_number: 42,
172
+ title: "v1.1",
173
+ state: "closed",
174
+ description: "First minor update"
175
+ )',
176
+ '# You can also access the response data
177
+ result = github_update_milestone(
178
+ api_token: ENV["GITHUB_API_TOKEN"],
179
+ repo_owner: "fastlane",
180
+ repo_name: "fastlane",
181
+ milestone_number: 42,
182
+ state: "closed"
183
+ )
184
+ UI.message("Updated milestone title: #{result[:json]["title"]}")'
185
+ ]
186
+ end
187
+
188
+ def category
189
+ :source_control
190
+ end
191
+
192
+ def is_supported?(platform)
193
+ true
194
+ end
195
+ end
196
+ end
197
+ end
198
+ end