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,191 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_ADD_ASSIGNEES_RESPONSE = :GITHUB_ADD_ASSIGNEES_RESPONSE
|
8
|
+
GITHUB_ADD_ASSIGNEES_JSON = :GITHUB_ADD_ASSIGNEES_JSON
|
9
|
+
GITHUB_ADD_ASSIGNEES_STATUS_CODE = :GITHUB_ADD_ASSIGNEES_STATUS_CODE
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubAddAssigneesAction < Action
|
13
|
+
class << self
|
14
|
+
def run(params)
|
15
|
+
# Required parameters
|
16
|
+
token = params[:api_token]
|
17
|
+
repo_owner = params[:repo_owner]
|
18
|
+
repo_name = params[:repo_name]
|
19
|
+
issue_number = params[:issue_number]
|
20
|
+
assignees = params[:assignees]
|
21
|
+
server_url = params[:server_url]
|
22
|
+
|
23
|
+
# Validate parameters (additional validation beyond what's in ConfigItem)
|
24
|
+
UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
|
25
|
+
UI.user_error!("No assignees provided, pass using `assignees: ['username1', 'username2']`") if assignees.nil? || assignees.empty?
|
26
|
+
|
27
|
+
# Prepare request parameters
|
28
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/assignees"
|
29
|
+
|
30
|
+
# Build body parameters
|
31
|
+
body_params = {
|
32
|
+
assignees: assignees
|
33
|
+
}
|
34
|
+
|
35
|
+
# Make the request
|
36
|
+
UI.message("Adding assignees #{assignees.join(', ')} to issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
37
|
+
response = Helper::GithubApiHelper.github_api_request(
|
38
|
+
token: token,
|
39
|
+
path: path,
|
40
|
+
params: body_params,
|
41
|
+
method: :post,
|
42
|
+
server_url: server_url
|
43
|
+
)
|
44
|
+
|
45
|
+
status_code = response.key?('status') ? response['status'] : nil
|
46
|
+
result = {
|
47
|
+
status: status_code,
|
48
|
+
body: response,
|
49
|
+
json: response
|
50
|
+
}
|
51
|
+
|
52
|
+
if response.key?('error')
|
53
|
+
UI.error("GitHub responded with an error: #{response['error']}")
|
54
|
+
UI.user_error!("GitHub API error: #{response['error']}")
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
if response['message'] && status_code && status_code >= 400
|
59
|
+
UI.error("GitHub API error: #{response['message']}")
|
60
|
+
UI.user_error!("GitHub API error: #{response['message']} (Status code: #{status_code})")
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# Print assignees for confirmation
|
65
|
+
if response['assignees'] && !response['assignees'].empty?
|
66
|
+
UI.success("Successfully added assignees to issue ##{issue_number}: #{response['assignees'].map { |a| a['login'] }.join(', ')}")
|
67
|
+
else
|
68
|
+
UI.success("Successfully updated issue ##{issue_number}")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set the shared values
|
72
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_ASSIGNEES_STATUS_CODE] = status_code
|
73
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_ASSIGNEES_RESPONSE] = response
|
74
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_ASSIGNEES_JSON] = response
|
75
|
+
|
76
|
+
return result
|
77
|
+
end
|
78
|
+
|
79
|
+
#####################################################
|
80
|
+
# @!group Documentation
|
81
|
+
#####################################################
|
82
|
+
|
83
|
+
def description
|
84
|
+
"Adds assignees to a GitHub issue"
|
85
|
+
end
|
86
|
+
|
87
|
+
def details
|
88
|
+
[
|
89
|
+
"This action adds one or more assignees to a specific issue in a GitHub repository using the GitHub API.",
|
90
|
+
"It requires a valid GitHub API token with appropriate permissions.",
|
91
|
+
"Documentation: [https://docs.github.com/en/rest/issues/assignees](https://docs.github.com/en/rest/issues/assignees)"
|
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: :issue_number,
|
130
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
131
|
+
description: "The issue number to add assignees to",
|
132
|
+
optional: false,
|
133
|
+
type: Integer),
|
134
|
+
FastlaneCore::ConfigItem.new(key: :assignees,
|
135
|
+
description: "Array of usernames to assign to the issue",
|
136
|
+
optional: false,
|
137
|
+
type: Array,
|
138
|
+
verify_block: proc do |value|
|
139
|
+
UI.user_error!("No assignees provided, pass using `assignees: ['username1']`") if value.nil? || value.empty?
|
140
|
+
end)
|
141
|
+
]
|
142
|
+
end
|
143
|
+
|
144
|
+
def output
|
145
|
+
[
|
146
|
+
['GITHUB_ADD_ASSIGNEES_STATUS_CODE', 'The status code returned from the GitHub API'],
|
147
|
+
['GITHUB_ADD_ASSIGNEES_RESPONSE', 'The full response from the GitHub API'],
|
148
|
+
['GITHUB_ADD_ASSIGNEES_JSON', 'The JSON data returned from the GitHub API']
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
152
|
+
def return_value
|
153
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
154
|
+
end
|
155
|
+
|
156
|
+
def authors
|
157
|
+
["crazymanish"]
|
158
|
+
end
|
159
|
+
|
160
|
+
def example_code
|
161
|
+
[
|
162
|
+
'github_add_assignees(
|
163
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
164
|
+
repo_owner: "fastlane",
|
165
|
+
repo_name: "fastlane",
|
166
|
+
issue_number: 123,
|
167
|
+
assignees: ["username1", "username2"]
|
168
|
+
)',
|
169
|
+
'# You can also access the response data
|
170
|
+
result = github_add_assignees(
|
171
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
172
|
+
repo_owner: "fastlane",
|
173
|
+
repo_name: "fastlane",
|
174
|
+
issue_number: 123,
|
175
|
+
assignees: ["username1"]
|
176
|
+
)
|
177
|
+
UI.message("Assigned users: #{result[:json]["assignees"].map { |a| a["login"] }.join(", ")}")'
|
178
|
+
]
|
179
|
+
end
|
180
|
+
|
181
|
+
def category
|
182
|
+
:source_control
|
183
|
+
end
|
184
|
+
|
185
|
+
def is_supported?(platform)
|
186
|
+
true
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_ADD_ISSUE_COMMENT_STATUS_CODE = :GITHUB_ADD_ISSUE_COMMENT_STATUS_CODE
|
8
|
+
GITHUB_ADD_ISSUE_COMMENT_RESPONSE = :GITHUB_ADD_ISSUE_COMMENT_RESPONSE
|
9
|
+
GITHUB_ADD_ISSUE_COMMENT_JSON = :GITHUB_ADD_ISSUE_COMMENT_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubAddIssueCommentAction < 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
|
+
issue_number = params[:issue_number]
|
23
|
+
body = params[:body]
|
24
|
+
|
25
|
+
# Validate parameters
|
26
|
+
UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
|
27
|
+
UI.user_error!("No comment body provided, pass using `body: 'Comment text'`") if body.to_s.empty?
|
28
|
+
|
29
|
+
# Build the path
|
30
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/comments"
|
31
|
+
|
32
|
+
# Build body parameters
|
33
|
+
body_params = {
|
34
|
+
body: body
|
35
|
+
}
|
36
|
+
|
37
|
+
UI.message("Adding comment to issue ##{issue_number} 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: :post,
|
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
|
+
# Robust status code check for reusability
|
55
|
+
if status_code.is_a?(Integer) && status_code.between?(200, 299)
|
56
|
+
comment_id = json_response['id']
|
57
|
+
UI.success("Successfully added comment ID: #{comment_id} to issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
58
|
+
else
|
59
|
+
UI.error("Error adding comment: #{status_code.inspect}")
|
60
|
+
UI.error(response[:body])
|
61
|
+
UI.user_error!("GitHub API returned #{status_code.inspect}: #{response[:body]}")
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
|
65
|
+
# Store the results in shared values
|
66
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_ISSUE_COMMENT_STATUS_CODE] = status_code
|
67
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_ISSUE_COMMENT_RESPONSE] = response[:body]
|
68
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_ISSUE_COMMENT_JSON] = json_response
|
69
|
+
|
70
|
+
return result
|
71
|
+
end
|
72
|
+
|
73
|
+
#####################################################
|
74
|
+
# @!group Documentation
|
75
|
+
#####################################################
|
76
|
+
|
77
|
+
def description
|
78
|
+
"Adds a comment to a GitHub issue"
|
79
|
+
end
|
80
|
+
|
81
|
+
def details
|
82
|
+
[
|
83
|
+
"Adds a new comment to an issue in a GitHub repository.",
|
84
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
85
|
+
"API Documentation: https://docs.github.com/en/rest/issues/comments#create-an-issue-comment"
|
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",
|
94
|
+
optional: false,
|
95
|
+
sensitive: true,
|
96
|
+
code_gen_sensitive: true,
|
97
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
98
|
+
verify_block: proc do |value|
|
99
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
100
|
+
end),
|
101
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
102
|
+
env_name: "GITHUB_API_SERVER_URL",
|
103
|
+
description: "GitHub API server URL",
|
104
|
+
optional: true,
|
105
|
+
default_value: "https://api.github.com"),
|
106
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
107
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
108
|
+
description: "Repository owner (organization or username)",
|
109
|
+
optional: false,
|
110
|
+
type: String,
|
111
|
+
verify_block: proc do |value|
|
112
|
+
UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
|
113
|
+
end),
|
114
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
115
|
+
env_name: "GITHUB_API_REPO_NAME",
|
116
|
+
description: "Repository name",
|
117
|
+
optional: false,
|
118
|
+
type: String,
|
119
|
+
verify_block: proc do |value|
|
120
|
+
UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
|
121
|
+
end),
|
122
|
+
FastlaneCore::ConfigItem.new(key: :issue_number,
|
123
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
124
|
+
description: "The issue number to comment on",
|
125
|
+
optional: false,
|
126
|
+
type: Integer),
|
127
|
+
FastlaneCore::ConfigItem.new(key: :body,
|
128
|
+
description: "The body text of the comment",
|
129
|
+
optional: false,
|
130
|
+
type: String,
|
131
|
+
verify_block: proc do |value|
|
132
|
+
UI.user_error!("No comment body provided, pass using `body: 'Comment text'`") if value.to_s.empty?
|
133
|
+
end)
|
134
|
+
]
|
135
|
+
end
|
136
|
+
|
137
|
+
def output
|
138
|
+
[
|
139
|
+
['GITHUB_ADD_ISSUE_COMMENT_STATUS_CODE', 'The status code returned from the GitHub API'],
|
140
|
+
['GITHUB_ADD_ISSUE_COMMENT_RESPONSE', 'The full response body from the GitHub API'],
|
141
|
+
['GITHUB_ADD_ISSUE_COMMENT_JSON', 'The parsed JSON returned from the GitHub API']
|
142
|
+
]
|
143
|
+
end
|
144
|
+
|
145
|
+
def return_value
|
146
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
147
|
+
end
|
148
|
+
|
149
|
+
def authors
|
150
|
+
["crazymanish"]
|
151
|
+
end
|
152
|
+
|
153
|
+
def example_code
|
154
|
+
[
|
155
|
+
'github_add_issue_comment(
|
156
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
157
|
+
repo_owner: "fastlane",
|
158
|
+
repo_name: "fastlane",
|
159
|
+
issue_number: 123,
|
160
|
+
body: "This is a new comment"
|
161
|
+
)',
|
162
|
+
'# You can also access the response data
|
163
|
+
result = github_add_issue_comment(
|
164
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
165
|
+
repo_owner: "fastlane",
|
166
|
+
repo_name: "fastlane",
|
167
|
+
issue_number: 123,
|
168
|
+
body: "This is a new comment"
|
169
|
+
)
|
170
|
+
UI.message("Created comment ID: #{result[:json]["id"]}")'
|
171
|
+
]
|
172
|
+
end
|
173
|
+
|
174
|
+
def category
|
175
|
+
:source_control
|
176
|
+
end
|
177
|
+
|
178
|
+
def is_supported?(platform)
|
179
|
+
true
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_ADD_LABELS_RESPONSE = :GITHUB_ADD_LABELS_RESPONSE
|
8
|
+
GITHUB_ADD_LABELS_JSON = :GITHUB_ADD_LABELS_JSON
|
9
|
+
GITHUB_ADD_LABELS_STATUS_CODE = :GITHUB_ADD_LABELS_STATUS_CODE
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubAddLabelsAction < 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
|
+
labels = params[:labels]
|
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 labels provided, pass using `labels: ['bug', 'feature']`") if labels.nil? || labels.empty?
|
25
|
+
|
26
|
+
# Prepare request parameters
|
27
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/labels"
|
28
|
+
|
29
|
+
# Build body parameters
|
30
|
+
body_params = {
|
31
|
+
labels: labels
|
32
|
+
}
|
33
|
+
|
34
|
+
# Make the request
|
35
|
+
UI.message("Adding labels to 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: :post,
|
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 labels for confirmation
|
64
|
+
if response.is_a?(Array) && !response.empty?
|
65
|
+
label_names = response.map { |label| label['name'] }.join(', ')
|
66
|
+
UI.success("Successfully added labels to issue ##{issue_number}: #{label_names}")
|
67
|
+
else
|
68
|
+
UI.success("Successfully updated issue ##{issue_number}")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set the shared values
|
72
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_LABELS_STATUS_CODE] = status_code
|
73
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_LABELS_RESPONSE] = response
|
74
|
+
Actions.lane_context[SharedValues::GITHUB_ADD_LABELS_JSON] = response
|
75
|
+
|
76
|
+
return result
|
77
|
+
end
|
78
|
+
|
79
|
+
#####################################################
|
80
|
+
# @!group Documentation
|
81
|
+
#####################################################
|
82
|
+
|
83
|
+
def description
|
84
|
+
"Adds labels to a GitHub issue"
|
85
|
+
end
|
86
|
+
|
87
|
+
def details
|
88
|
+
[
|
89
|
+
"This action adds one or more labels to a specific issue in a GitHub repository.",
|
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#add-labels-to-an-issue)"
|
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: :issue_number,
|
130
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
131
|
+
description: "The issue number to add labels to",
|
132
|
+
optional: false,
|
133
|
+
type: Integer),
|
134
|
+
FastlaneCore::ConfigItem.new(key: :labels,
|
135
|
+
description: "Array of label names to add to the issue",
|
136
|
+
optional: false,
|
137
|
+
type: Array,
|
138
|
+
verify_block: proc do |value|
|
139
|
+
UI.user_error!("No labels provided, pass using `labels: ['bug']`") if value.nil? || value.empty?
|
140
|
+
end)
|
141
|
+
]
|
142
|
+
end
|
143
|
+
|
144
|
+
def output
|
145
|
+
[
|
146
|
+
['GITHUB_ADD_LABELS_STATUS_CODE', 'The status code returned from the GitHub API'],
|
147
|
+
['GITHUB_ADD_LABELS_RESPONSE', 'The full response from the GitHub API'],
|
148
|
+
['GITHUB_ADD_LABELS_JSON', 'The JSON data returned from the GitHub API']
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
152
|
+
def return_value
|
153
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
154
|
+
end
|
155
|
+
|
156
|
+
def authors
|
157
|
+
["crazymanish"]
|
158
|
+
end
|
159
|
+
|
160
|
+
def example_code
|
161
|
+
[
|
162
|
+
'github_add_labels(
|
163
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
164
|
+
repo_owner: "fastlane",
|
165
|
+
repo_name: "fastlane",
|
166
|
+
issue_number: 123,
|
167
|
+
labels: ["bug", "enhancement"]
|
168
|
+
)',
|
169
|
+
'# You can also access the response data
|
170
|
+
result = github_add_labels(
|
171
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
172
|
+
repo_owner: "fastlane",
|
173
|
+
repo_name: "fastlane",
|
174
|
+
issue_number: 123,
|
175
|
+
labels: ["bug", "critical"]
|
176
|
+
)
|
177
|
+
UI.message("Labels added: #{result[:json].map { |label| label["name"] }.join(", ")}")'
|
178
|
+
]
|
179
|
+
end
|
180
|
+
|
181
|
+
def category
|
182
|
+
:source_control
|
183
|
+
end
|
184
|
+
|
185
|
+
def is_supported?(platform)
|
186
|
+
true
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
class GithubApiAction < Action
|
7
|
+
def self.run(params)
|
8
|
+
UI.message("The github_api plugin is working!")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.description
|
12
|
+
"A fastlane plugin forGitHub APIs."
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.authors
|
16
|
+
["crazymanish"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.return_value
|
20
|
+
# If your method provides a return value, you can describe here what it does
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.details
|
24
|
+
# Optional:
|
25
|
+
"A fastlane plugin forGitHub APIs. 🚀"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.available_options
|
29
|
+
[
|
30
|
+
# FastlaneCore::ConfigItem.new(key: :your_option,
|
31
|
+
# env_name: "GITHUB_API_YOUR_OPTION",
|
32
|
+
# description: "A description of your option",
|
33
|
+
# optional: false,
|
34
|
+
# type: String)
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.is_supported?(platform)
|
39
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
40
|
+
# See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
|
41
|
+
#
|
42
|
+
# [:ios, :mac, :android].include?(platform)
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|