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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +824 -0
- data/lib/fastlane/plugin/github_api/actions/github_add_assignees_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_add_issue_comment_action.rb +184 -0
- data/lib/fastlane/plugin/github_api/actions/github_add_labels_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_api_action.rb +47 -0
- data/lib/fastlane/plugin/github_api/actions/github_check_pull_merged_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_commit_comment_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_issue_action.rb +199 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_issue_comment_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_issue_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_label_action.rb +194 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_milestone_action.rb +199 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_action.rb +202 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_action.rb +229 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_comment_reaction_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_pull_review_action.rb +224 -0
- data/lib/fastlane/plugin/github_api/actions/github_create_repository_action.rb +230 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_commit_comment_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_action.rb +153 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_issue_comment_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_issue_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_label_action.rb +164 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_milestone_action.rb +159 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_action.rb +144 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_pull_comment_reaction_action.rb +152 -0
- data/lib/fastlane/plugin/github_api/actions/github_delete_repository_action.rb +166 -0
- data/lib/fastlane/plugin/github_api/actions/github_dismiss_pull_review_action.rb +168 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_action.rb +166 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_comment_action.rb +174 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_event_action.rb +169 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_issue_timeline_action.rb +199 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_milestone_action.rb +167 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_action.rb +150 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_comment_action.rb +147 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_action.rb +137 -0
- data/lib/fastlane/plugin/github_api/actions/github_get_pull_review_comments_action.rb +181 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_all_pull_comments_action.rb +186 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_commit_comment_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_comment_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_comments_action.rb +197 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_events_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_labels_action.rb +192 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issue_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_issues_action.rb +236 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_milestones_action.rb +205 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_comment_reactions_action.rb +183 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_comments_action.rb +203 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_commits_action.rb +175 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_files_action.rb +174 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviewers_action.rb +163 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pull_reviews_action.rb +175 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_pulls_action.rb +206 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_repo_issue_events_action.rb +185 -0
- data/lib/fastlane/plugin/github_api/actions/github_list_repo_labels_action.rb +184 -0
- data/lib/fastlane/plugin/github_api/actions/github_lock_issue_action.rb +180 -0
- data/lib/fastlane/plugin/github_api/actions/github_merge_pull_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_all_labels_action.rb +160 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_assignees_action.rb +195 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_label_action.rb +172 -0
- data/lib/fastlane/plugin/github_api/actions/github_remove_pull_reviewers_action.rb +169 -0
- data/lib/fastlane/plugin/github_api/actions/github_request_pull_review_action.rb +169 -0
- data/lib/fastlane/plugin/github_api/actions/github_set_labels_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_submit_pull_comment_action.rb +185 -0
- data/lib/fastlane/plugin/github_api/actions/github_submit_pull_review_action.rb +187 -0
- data/lib/fastlane/plugin/github_api/actions/github_unlock_issue_action.rb +157 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_issue_action.rb +202 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_issue_comment_action.rb +172 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_label_action.rb +204 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_milestone_action.rb +198 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_action.rb +191 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_branch_action.rb +158 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_comment_action.rb +156 -0
- data/lib/fastlane/plugin/github_api/actions/github_update_pull_review_action.rb +151 -0
- data/lib/fastlane/plugin/github_api/helper/github_api_helper.rb +123 -0
- data/lib/fastlane/plugin/github_api/version.rb +5 -0
- data/lib/fastlane/plugin/github_api.rb +16 -0
- metadata +120 -0
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_REMOVE_ASSIGNEES_RESPONSE = :GITHUB_REMOVE_ASSIGNEES_RESPONSE
|
8
|
+
GITHUB_REMOVE_ASSIGNEES_JSON = :GITHUB_REMOVE_ASSIGNEES_JSON
|
9
|
+
GITHUB_REMOVE_ASSIGNEES_STATUS_CODE = :GITHUB_REMOVE_ASSIGNEES_STATUS_CODE
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubRemoveAssigneesAction < 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
|
+
assignees = params[:assignees]
|
20
|
+
server_url = params[:server_url]
|
21
|
+
|
22
|
+
# Validate parameters (additional validation beyond what's in ConfigItem)
|
23
|
+
UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
|
24
|
+
UI.user_error!("No assignees provided, pass using `assignees: ['username1', 'username2']`") if assignees.nil? || assignees.empty?
|
25
|
+
|
26
|
+
# Prepare request parameters
|
27
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/assignees"
|
28
|
+
|
29
|
+
# Build body parameters
|
30
|
+
body_params = {
|
31
|
+
assignees: assignees
|
32
|
+
}
|
33
|
+
|
34
|
+
# Make the request
|
35
|
+
UI.message("Removing assignees #{assignees.join(', ')} from issue ##{issue_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: :delete,
|
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
|
+
# Print assignees for confirmation
|
64
|
+
if response['assignees']
|
65
|
+
remaining = response['assignees'].map { |a| a['login'] }.join(', ')
|
66
|
+
if remaining.empty?
|
67
|
+
UI.success("Successfully removed all assignees from issue ##{issue_number}")
|
68
|
+
else
|
69
|
+
UI.success("Successfully removed assignees from issue ##{issue_number}. Remaining assignees: #{remaining}")
|
70
|
+
end
|
71
|
+
else
|
72
|
+
UI.success("Successfully updated issue ##{issue_number}")
|
73
|
+
end
|
74
|
+
|
75
|
+
# Set the shared values
|
76
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_ASSIGNEES_STATUS_CODE] = status_code
|
77
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_ASSIGNEES_RESPONSE] = response
|
78
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_ASSIGNEES_JSON] = response
|
79
|
+
|
80
|
+
return result
|
81
|
+
end
|
82
|
+
|
83
|
+
#####################################################
|
84
|
+
# @!group Documentation
|
85
|
+
#####################################################
|
86
|
+
|
87
|
+
def description
|
88
|
+
"Removes assignees from a GitHub issue"
|
89
|
+
end
|
90
|
+
|
91
|
+
def details
|
92
|
+
[
|
93
|
+
"This action removes one or more assignees from a specific issue in a GitHub repository.",
|
94
|
+
"It requires a valid GitHub API token with appropriate permissions.",
|
95
|
+
"Documentation: [https://docs.github.com/en/rest/issues/assignees](https://docs.github.com/en/rest/issues/assignees#remove-assignees-from-an-issue)"
|
96
|
+
].join("\n")
|
97
|
+
end
|
98
|
+
|
99
|
+
def available_options
|
100
|
+
[
|
101
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
102
|
+
env_name: "GITHUB_API_TOKEN",
|
103
|
+
description: "GitHub API token with repo permissions",
|
104
|
+
optional: false,
|
105
|
+
type: String,
|
106
|
+
sensitive: true,
|
107
|
+
code_gen_sensitive: true,
|
108
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
109
|
+
verify_block: proc do |value|
|
110
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
111
|
+
end),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
113
|
+
env_name: "GITHUB_API_SERVER_URL",
|
114
|
+
description: "GitHub API server URL",
|
115
|
+
optional: true,
|
116
|
+
default_value: "https://api.github.com"),
|
117
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
118
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
119
|
+
description: "Repository owner (organization or username)",
|
120
|
+
optional: false,
|
121
|
+
type: String,
|
122
|
+
verify_block: proc do |value|
|
123
|
+
UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
|
124
|
+
end),
|
125
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
126
|
+
env_name: "GITHUB_API_REPO_NAME",
|
127
|
+
description: "Repository name",
|
128
|
+
optional: false,
|
129
|
+
type: String,
|
130
|
+
verify_block: proc do |value|
|
131
|
+
UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
|
132
|
+
end),
|
133
|
+
FastlaneCore::ConfigItem.new(key: :issue_number,
|
134
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
135
|
+
description: "The issue number to remove assignees from",
|
136
|
+
optional: false,
|
137
|
+
type: Integer),
|
138
|
+
FastlaneCore::ConfigItem.new(key: :assignees,
|
139
|
+
description: "Array of usernames to remove from the issue",
|
140
|
+
optional: false,
|
141
|
+
type: Array,
|
142
|
+
verify_block: proc do |value|
|
143
|
+
UI.user_error!("No assignees provided, pass using `assignees: ['username1']`") if value.nil? || value.empty?
|
144
|
+
end)
|
145
|
+
]
|
146
|
+
end
|
147
|
+
|
148
|
+
def output
|
149
|
+
[
|
150
|
+
['GITHUB_REMOVE_ASSIGNEES_STATUS_CODE', 'The status code returned from the GitHub API'],
|
151
|
+
['GITHUB_REMOVE_ASSIGNEES_RESPONSE', 'The full response from the GitHub API'],
|
152
|
+
['GITHUB_REMOVE_ASSIGNEES_JSON', 'The JSON data returned from the GitHub API']
|
153
|
+
]
|
154
|
+
end
|
155
|
+
|
156
|
+
def return_value
|
157
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
158
|
+
end
|
159
|
+
|
160
|
+
def authors
|
161
|
+
["crazymanish"]
|
162
|
+
end
|
163
|
+
|
164
|
+
def example_code
|
165
|
+
[
|
166
|
+
'github_remove_assignees(
|
167
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
168
|
+
repo_owner: "fastlane",
|
169
|
+
repo_name: "fastlane",
|
170
|
+
issue_number: 123,
|
171
|
+
assignees: ["username1", "username2"]
|
172
|
+
)',
|
173
|
+
'# You can also access the response data
|
174
|
+
result = github_remove_assignees(
|
175
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
176
|
+
repo_owner: "fastlane",
|
177
|
+
repo_name: "fastlane",
|
178
|
+
issue_number: 123,
|
179
|
+
assignees: ["username1"]
|
180
|
+
)
|
181
|
+
UI.message("Remaining assignees: #{result[:json]["assignees"].map { |a| a["login"] }.join(", ")}")'
|
182
|
+
]
|
183
|
+
end
|
184
|
+
|
185
|
+
def category
|
186
|
+
:source_control
|
187
|
+
end
|
188
|
+
|
189
|
+
def is_supported?(platform)
|
190
|
+
true
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -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_REMOVE_LABEL_RESPONSE = :GITHUB_REMOVE_LABEL_RESPONSE
|
8
|
+
GITHUB_REMOVE_LABEL_JSON = :GITHUB_REMOVE_LABEL_JSON
|
9
|
+
GITHUB_REMOVE_LABEL_STATUS_CODE = :GITHUB_REMOVE_LABEL_STATUS_CODE
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubRemoveLabelAction < 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
|
+
label_name = params[:label_name]
|
20
|
+
server_url = params[:server_url]
|
21
|
+
|
22
|
+
# Validate parameters (additional validation beyond what's in ConfigItem)
|
23
|
+
UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
|
24
|
+
UI.user_error!("No label name provided, pass using `label_name: 'bug'`") if label_name.to_s.empty?
|
25
|
+
|
26
|
+
# Prepare request parameters
|
27
|
+
# URL encode the label name to handle special characters like spaces, etc.
|
28
|
+
encoded_label = URI.encode_www_form_component(label_name)
|
29
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/labels/#{encoded_label}"
|
30
|
+
|
31
|
+
# Make the request
|
32
|
+
UI.message("Removing label '#{label_name}' from issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
33
|
+
response = Helper::GithubApiHelper.github_api_request(
|
34
|
+
token: token,
|
35
|
+
path: path,
|
36
|
+
method: :delete,
|
37
|
+
server_url: server_url
|
38
|
+
)
|
39
|
+
|
40
|
+
status_code = response.key?('status') ? response['status'] : nil
|
41
|
+
result = {
|
42
|
+
status: status_code,
|
43
|
+
body: response,
|
44
|
+
json: response
|
45
|
+
}
|
46
|
+
|
47
|
+
if response.key?('error')
|
48
|
+
UI.error("GitHub responded with an error: #{response['error']}")
|
49
|
+
UI.user_error!("GitHub API error: #{response['error']}")
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
|
53
|
+
if response.is_a?(Hash) && response['message'] && status_code && status_code >= 400
|
54
|
+
UI.error("GitHub API error: #{response['message']}")
|
55
|
+
UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
|
59
|
+
UI.success("Successfully removed label '#{label_name}' from issue ##{issue_number}")
|
60
|
+
|
61
|
+
# Set the shared values
|
62
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_LABEL_STATUS_CODE] = status_code
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_LABEL_RESPONSE] = response
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_LABEL_JSON] = response
|
65
|
+
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
#####################################################
|
70
|
+
# @!group Documentation
|
71
|
+
#####################################################
|
72
|
+
|
73
|
+
def description
|
74
|
+
"Removes a label from a GitHub issue"
|
75
|
+
end
|
76
|
+
|
77
|
+
def details
|
78
|
+
[
|
79
|
+
"This action removes a specific label from an issue in a GitHub repository.",
|
80
|
+
"It requires a valid GitHub API token with appropriate permissions.",
|
81
|
+
"Documentation: [https://docs.github.com/en/rest/issues/labels](https://docs.github.com/en/rest/issues/labels#remove-a-label-from-an-issue)"
|
82
|
+
].join("\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
def available_options
|
86
|
+
[
|
87
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
88
|
+
env_name: "GITHUB_API_TOKEN",
|
89
|
+
description: "GitHub API token with repo permissions",
|
90
|
+
optional: false,
|
91
|
+
type: String,
|
92
|
+
sensitive: true,
|
93
|
+
code_gen_sensitive: true,
|
94
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
95
|
+
verify_block: proc do |value|
|
96
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
97
|
+
end),
|
98
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
99
|
+
env_name: "GITHUB_API_SERVER_URL",
|
100
|
+
description: "GitHub API server URL",
|
101
|
+
optional: true,
|
102
|
+
default_value: "https://api.github.com"),
|
103
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
104
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
105
|
+
description: "Repository owner (organization or username)",
|
106
|
+
optional: false,
|
107
|
+
type: String,
|
108
|
+
verify_block: proc do |value|
|
109
|
+
UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
|
110
|
+
end),
|
111
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
112
|
+
env_name: "GITHUB_API_REPO_NAME",
|
113
|
+
description: "Repository name",
|
114
|
+
optional: false,
|
115
|
+
type: String,
|
116
|
+
verify_block: proc do |value|
|
117
|
+
UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
|
118
|
+
end),
|
119
|
+
FastlaneCore::ConfigItem.new(key: :issue_number,
|
120
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
121
|
+
description: "The issue number to remove the label from",
|
122
|
+
optional: false,
|
123
|
+
type: Integer),
|
124
|
+
FastlaneCore::ConfigItem.new(key: :label_name,
|
125
|
+
description: "The name of the label to remove",
|
126
|
+
optional: false,
|
127
|
+
type: String,
|
128
|
+
verify_block: proc do |value|
|
129
|
+
UI.user_error!("No label name provided, pass using `label_name: 'bug'`") if value.to_s.empty?
|
130
|
+
end)
|
131
|
+
]
|
132
|
+
end
|
133
|
+
|
134
|
+
def output
|
135
|
+
[
|
136
|
+
['GITHUB_REMOVE_LABEL_STATUS_CODE', 'The status code returned from the GitHub API'],
|
137
|
+
['GITHUB_REMOVE_LABEL_RESPONSE', 'The full response from the GitHub API'],
|
138
|
+
['GITHUB_REMOVE_LABEL_JSON', 'The JSON data returned from the GitHub API']
|
139
|
+
]
|
140
|
+
end
|
141
|
+
|
142
|
+
def return_value
|
143
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
144
|
+
end
|
145
|
+
|
146
|
+
def authors
|
147
|
+
["crazymanish"]
|
148
|
+
end
|
149
|
+
|
150
|
+
def example_code
|
151
|
+
[
|
152
|
+
'github_remove_label(
|
153
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
154
|
+
repo_owner: "fastlane",
|
155
|
+
repo_name: "fastlane",
|
156
|
+
issue_number: 123,
|
157
|
+
label_name: "bug"
|
158
|
+
)'
|
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,169 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_REMOVE_PULL_REVIEWERS_STATUS_CODE = :GITHUB_REMOVE_PULL_REVIEWERS_STATUS_CODE
|
8
|
+
GITHUB_REMOVE_PULL_REVIEWERS_RESPONSE = :GITHUB_REMOVE_PULL_REVIEWERS_RESPONSE
|
9
|
+
GITHUB_REMOVE_PULL_REVIEWERS_JSON = :GITHUB_REMOVE_PULL_REVIEWERS_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubRemovePullReviewersAction < 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
|
+
reviewers = params[:reviewers]
|
24
|
+
team_reviewers = params[:team_reviewers]
|
25
|
+
|
26
|
+
# Build the body for the request
|
27
|
+
body = {}
|
28
|
+
body[:reviewers] = reviewers if reviewers && !reviewers.empty?
|
29
|
+
body[:team_reviewers] = team_reviewers if team_reviewers && !team_reviewers.empty?
|
30
|
+
|
31
|
+
# Build the path
|
32
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/requested_reviewers"
|
33
|
+
|
34
|
+
UI.message("Removing reviewers from pull request ##{pull_number} in #{repo_owner}/#{repo_name}")
|
35
|
+
response = Helper::GithubApiHelper.github_api_request(
|
36
|
+
token: api_token,
|
37
|
+
path: path,
|
38
|
+
params: body,
|
39
|
+
method: :delete,
|
40
|
+
server_url: server_url
|
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
|
+
reviewer_count = reviewers ? reviewers.count : 0
|
53
|
+
team_count = team_reviewers ? team_reviewers.count : 0
|
54
|
+
UI.success("Successfully removed #{reviewer_count} reviewers and #{team_count} team reviewers from pull request ##{pull_number}")
|
55
|
+
else
|
56
|
+
UI.error("Error removing reviewers: #{status_code}")
|
57
|
+
UI.error(response[:body])
|
58
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# Store the results in shared values
|
63
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_PULL_REVIEWERS_STATUS_CODE] = status_code
|
64
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_PULL_REVIEWERS_RESPONSE] = response[:body]
|
65
|
+
Actions.lane_context[SharedValues::GITHUB_REMOVE_PULL_REVIEWERS_JSON] = json_response
|
66
|
+
|
67
|
+
return result
|
68
|
+
end
|
69
|
+
|
70
|
+
#####################################################
|
71
|
+
# @!group Documentation
|
72
|
+
#####################################################
|
73
|
+
|
74
|
+
def description
|
75
|
+
"Removes requested reviewers from a pull request"
|
76
|
+
end
|
77
|
+
|
78
|
+
def details
|
79
|
+
[
|
80
|
+
"Removes requested reviewers from a pull request.",
|
81
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
82
|
+
"API Documentation: https://docs.github.com/en/rest/pulls/review-requests#remove-requested-reviewers-from-a-pull-request"
|
83
|
+
].join("\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
def available_options
|
87
|
+
[
|
88
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
89
|
+
env_name: "GITHUB_API_TOKEN",
|
90
|
+
description: "GitHub API token",
|
91
|
+
optional: false,
|
92
|
+
sensitive: true,
|
93
|
+
code_gen_sensitive: true,
|
94
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
95
|
+
verify_block: proc do |value|
|
96
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
97
|
+
end),
|
98
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
99
|
+
env_name: "GITHUB_API_SERVER_URL",
|
100
|
+
description: "GitHub API server URL",
|
101
|
+
optional: true,
|
102
|
+
default_value: "https://api.github.com"),
|
103
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
104
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
105
|
+
description: "Owner of the repository",
|
106
|
+
optional: false),
|
107
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
108
|
+
env_name: "GITHUB_API_REPO_NAME",
|
109
|
+
description: "Name of the repository",
|
110
|
+
optional: false),
|
111
|
+
FastlaneCore::ConfigItem.new(key: :pull_number,
|
112
|
+
env_name: "GITHUB_API_PULL_NUMBER",
|
113
|
+
description: "The number of the pull request",
|
114
|
+
optional: false,
|
115
|
+
type: Integer),
|
116
|
+
FastlaneCore::ConfigItem.new(key: :reviewers,
|
117
|
+
env_name: "GITHUB_API_PULL_REVIEWERS",
|
118
|
+
description: "An array of user logins to remove as reviewers",
|
119
|
+
optional: true,
|
120
|
+
type: Array),
|
121
|
+
FastlaneCore::ConfigItem.new(key: :team_reviewers,
|
122
|
+
env_name: "GITHUB_API_PULL_TEAM_REVIEWERS",
|
123
|
+
description: "An array of team slugs to remove as reviewers",
|
124
|
+
optional: true,
|
125
|
+
type: Array)
|
126
|
+
]
|
127
|
+
end
|
128
|
+
|
129
|
+
def output
|
130
|
+
[
|
131
|
+
['GITHUB_REMOVE_PULL_REVIEWERS_STATUS_CODE', 'The status code returned by the GitHub API'],
|
132
|
+
['GITHUB_REMOVE_PULL_REVIEWERS_RESPONSE', 'The full response body returned by the GitHub API'],
|
133
|
+
['GITHUB_REMOVE_PULL_REVIEWERS_JSON', 'The parsed JSON response returned by the GitHub API']
|
134
|
+
]
|
135
|
+
end
|
136
|
+
|
137
|
+
def return_value
|
138
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
139
|
+
end
|
140
|
+
|
141
|
+
def authors
|
142
|
+
["crazymanish"]
|
143
|
+
end
|
144
|
+
|
145
|
+
def is_supported?(platform)
|
146
|
+
true
|
147
|
+
end
|
148
|
+
|
149
|
+
def example_code
|
150
|
+
[
|
151
|
+
'github_remove_pull_reviewers(
|
152
|
+
repo_owner: "octocat",
|
153
|
+
repo_name: "Hello-World",
|
154
|
+
pull_number: 42,
|
155
|
+
reviewers: ["username1", "username2"]
|
156
|
+
)',
|
157
|
+
'github_remove_pull_reviewers(
|
158
|
+
repo_owner: "octocat",
|
159
|
+
repo_name: "Hello-World",
|
160
|
+
pull_number: 42,
|
161
|
+
reviewers: ["username1"],
|
162
|
+
team_reviewers: ["engineering-team"]
|
163
|
+
)'
|
164
|
+
]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|