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,187 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_SUBMIT_PULL_REVIEW_STATUS_CODE = :GITHUB_SUBMIT_PULL_REVIEW_STATUS_CODE
|
8
|
+
GITHUB_SUBMIT_PULL_REVIEW_RESPONSE = :GITHUB_SUBMIT_PULL_REVIEW_RESPONSE
|
9
|
+
GITHUB_SUBMIT_PULL_REVIEW_JSON = :GITHUB_SUBMIT_PULL_REVIEW_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubSubmitPullReviewAction < 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
|
+
event = params[:event]
|
24
|
+
body = params[:body]
|
25
|
+
comments = params[:comments]
|
26
|
+
|
27
|
+
# Build the body for the request
|
28
|
+
request_body = {}
|
29
|
+
request_body[:event] = event if event
|
30
|
+
request_body[:body] = body if body
|
31
|
+
request_body[:comments] = comments if comments && !comments.empty?
|
32
|
+
|
33
|
+
# Build the path
|
34
|
+
path = "/repos/#{repo_owner}/#{repo_name}/pulls/#{pull_number}/reviews"
|
35
|
+
|
36
|
+
UI.message("Submitting a review for pull request ##{pull_number} in #{repo_owner}/#{repo_name}")
|
37
|
+
|
38
|
+
response = Helper::GithubApiHelper.github_api_request(
|
39
|
+
token: api_token,
|
40
|
+
path: path,
|
41
|
+
params: request_body,
|
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
|
+
if status_code.between?(200, 299)
|
55
|
+
UI.success("Successfully submitted a #{event} review for pull request ##{pull_number}")
|
56
|
+
else
|
57
|
+
UI.error("Error submitting review: #{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_SUBMIT_PULL_REVIEW_STATUS_CODE] = status_code
|
65
|
+
Actions.lane_context[SharedValues::GITHUB_SUBMIT_PULL_REVIEW_RESPONSE] = response[:body]
|
66
|
+
Actions.lane_context[SharedValues::GITHUB_SUBMIT_PULL_REVIEW_JSON] = json_response
|
67
|
+
|
68
|
+
return result
|
69
|
+
end
|
70
|
+
|
71
|
+
#####################################################
|
72
|
+
# @!group Documentation
|
73
|
+
#####################################################
|
74
|
+
|
75
|
+
def description
|
76
|
+
"Create a review for a pull request"
|
77
|
+
end
|
78
|
+
|
79
|
+
def details
|
80
|
+
[
|
81
|
+
"Creates a new review for a pull request.",
|
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/pulls/reviews#create-a-review-for-a-pull-request"
|
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: "Owner of the repository",
|
107
|
+
optional: false),
|
108
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
109
|
+
env_name: "GITHUB_API_REPO_NAME",
|
110
|
+
description: "Name of the repository",
|
111
|
+
optional: false),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :pull_number,
|
113
|
+
env_name: "GITHUB_API_PULL_NUMBER",
|
114
|
+
description: "The number of the pull request",
|
115
|
+
optional: false,
|
116
|
+
type: Integer),
|
117
|
+
FastlaneCore::ConfigItem.new(key: :event,
|
118
|
+
env_name: "GITHUB_API_REVIEW_EVENT",
|
119
|
+
description: "The review action (APPROVE, REQUEST_CHANGES, COMMENT)",
|
120
|
+
optional: true,
|
121
|
+
type: String,
|
122
|
+
default_value: "COMMENT",
|
123
|
+
verify_block: proc do |value|
|
124
|
+
UI.user_error!("Event must be one of: APPROVE, REQUEST_CHANGES, COMMENT") unless ['APPROVE', 'REQUEST_CHANGES', 'COMMENT'].include?(value)
|
125
|
+
end),
|
126
|
+
FastlaneCore::ConfigItem.new(key: :body,
|
127
|
+
env_name: "GITHUB_API_REVIEW_BODY",
|
128
|
+
description: "The body text of the review",
|
129
|
+
optional: true,
|
130
|
+
type: String),
|
131
|
+
FastlaneCore::ConfigItem.new(key: :comments,
|
132
|
+
env_name: "GITHUB_API_REVIEW_COMMENTS",
|
133
|
+
description: "Comments to add to the review (array of hashes with path, position, body)",
|
134
|
+
optional: true,
|
135
|
+
type: Array)
|
136
|
+
]
|
137
|
+
end
|
138
|
+
|
139
|
+
def output
|
140
|
+
[
|
141
|
+
['GITHUB_SUBMIT_PULL_REVIEW_STATUS_CODE', 'The status code returned by the GitHub API'],
|
142
|
+
['GITHUB_SUBMIT_PULL_REVIEW_RESPONSE', 'The full response body returned by the GitHub API'],
|
143
|
+
['GITHUB_SUBMIT_PULL_REVIEW_JSON', 'The parsed JSON response returned by the GitHub API']
|
144
|
+
]
|
145
|
+
end
|
146
|
+
|
147
|
+
def return_value
|
148
|
+
"Returns a hash containing the status code, response body, and parsed JSON response from the GitHub API."
|
149
|
+
end
|
150
|
+
|
151
|
+
def authors
|
152
|
+
["crazymanish"]
|
153
|
+
end
|
154
|
+
|
155
|
+
def is_supported?(platform)
|
156
|
+
true
|
157
|
+
end
|
158
|
+
|
159
|
+
def example_code
|
160
|
+
[
|
161
|
+
'github_submit_pull_review(
|
162
|
+
repo_owner: "octocat",
|
163
|
+
repo_name: "Hello-World",
|
164
|
+
pull_number: 42,
|
165
|
+
event: "APPROVE",
|
166
|
+
body: "Looks good! 👍"
|
167
|
+
)',
|
168
|
+
'github_submit_pull_review(
|
169
|
+
repo_owner: "octocat",
|
170
|
+
repo_name: "Hello-World",
|
171
|
+
pull_number: 42,
|
172
|
+
event: "REQUEST_CHANGES",
|
173
|
+
body: "Please fix these issues before merging.",
|
174
|
+
comments: [
|
175
|
+
{
|
176
|
+
path: "file.rb",
|
177
|
+
position: 10,
|
178
|
+
body: "Consider refactoring this section."
|
179
|
+
}
|
180
|
+
]
|
181
|
+
)'
|
182
|
+
]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_UNLOCK_ISSUE_STATUS_CODE = :GITHUB_UNLOCK_ISSUE_STATUS_CODE
|
8
|
+
GITHUB_UNLOCK_ISSUE_RESPONSE = :GITHUB_UNLOCK_ISSUE_RESPONSE
|
9
|
+
GITHUB_UNLOCK_ISSUE_JSON = :GITHUB_UNLOCK_ISSUE_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubUnlockIssueAction < 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
|
+
|
24
|
+
# Validate parameters
|
25
|
+
UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
|
26
|
+
|
27
|
+
# Build the path
|
28
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}/lock"
|
29
|
+
|
30
|
+
UI.message("Unlocking issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
31
|
+
response = Helper::GithubApiHelper.github_api_request(
|
32
|
+
token: api_token,
|
33
|
+
path: path,
|
34
|
+
method: :delete,
|
35
|
+
server_url: server_url
|
36
|
+
)
|
37
|
+
|
38
|
+
status_code = response[:status]
|
39
|
+
json_response = response[:json]
|
40
|
+
result = {
|
41
|
+
status: status_code,
|
42
|
+
body: response[:body],
|
43
|
+
json: json_response
|
44
|
+
}
|
45
|
+
|
46
|
+
if status_code.between?(200, 299) || status_code == 204
|
47
|
+
UI.success("Successfully unlocked issue ##{issue_number}")
|
48
|
+
else
|
49
|
+
UI.error("Error unlocking issue: #{status_code}")
|
50
|
+
UI.error(response[:body])
|
51
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
52
|
+
return nil
|
53
|
+
end
|
54
|
+
|
55
|
+
# Store the results in shared values
|
56
|
+
Actions.lane_context[SharedValues::GITHUB_UNLOCK_ISSUE_STATUS_CODE] = status_code
|
57
|
+
Actions.lane_context[SharedValues::GITHUB_UNLOCK_ISSUE_RESPONSE] = response[:body]
|
58
|
+
Actions.lane_context[SharedValues::GITHUB_UNLOCK_ISSUE_JSON] = json_response
|
59
|
+
|
60
|
+
return result
|
61
|
+
end
|
62
|
+
|
63
|
+
#####################################################
|
64
|
+
# @!group Documentation
|
65
|
+
#####################################################
|
66
|
+
|
67
|
+
def description
|
68
|
+
"Unlocks a GitHub issue"
|
69
|
+
end
|
70
|
+
|
71
|
+
def details
|
72
|
+
[
|
73
|
+
"Unlocks an issue in a GitHub repository, allowing comments to be added.",
|
74
|
+
"You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new).",
|
75
|
+
"API Documentation: https://docs.github.com/en/rest/issues/issues#unlock-an-issue"
|
76
|
+
].join("\n")
|
77
|
+
end
|
78
|
+
|
79
|
+
def available_options
|
80
|
+
[
|
81
|
+
FastlaneCore::ConfigItem.new(key: :api_token,
|
82
|
+
env_name: "GITHUB_API_TOKEN",
|
83
|
+
description: "GitHub API token",
|
84
|
+
optional: false,
|
85
|
+
sensitive: true,
|
86
|
+
code_gen_sensitive: true,
|
87
|
+
default_value: ENV["GITHUB_API_TOKEN"],
|
88
|
+
verify_block: proc do |value|
|
89
|
+
UI.user_error!("No GitHub API token given, pass using `api_token: 'token'`") if value.to_s.empty?
|
90
|
+
end),
|
91
|
+
FastlaneCore::ConfigItem.new(key: :server_url,
|
92
|
+
env_name: "GITHUB_API_SERVER_URL",
|
93
|
+
description: "GitHub API server URL",
|
94
|
+
optional: true,
|
95
|
+
default_value: "https://api.github.com"),
|
96
|
+
FastlaneCore::ConfigItem.new(key: :repo_owner,
|
97
|
+
env_name: "GITHUB_API_REPO_OWNER",
|
98
|
+
description: "Repository owner (organization or username)",
|
99
|
+
optional: false,
|
100
|
+
type: String,
|
101
|
+
verify_block: proc do |value|
|
102
|
+
UI.user_error!("No repository owner provided, pass using `repo_owner: 'owner'`") if value.to_s.empty?
|
103
|
+
end),
|
104
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
105
|
+
env_name: "GITHUB_API_REPO_NAME",
|
106
|
+
description: "Repository name",
|
107
|
+
optional: false,
|
108
|
+
type: String,
|
109
|
+
verify_block: proc do |value|
|
110
|
+
UI.user_error!("No repository name provided, pass using `repo_name: 'name'`") if value.to_s.empty?
|
111
|
+
end),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :issue_number,
|
113
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
114
|
+
description: "The issue number to unlock",
|
115
|
+
optional: false,
|
116
|
+
type: Integer)
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
def output
|
121
|
+
[
|
122
|
+
['GITHUB_UNLOCK_ISSUE_STATUS_CODE', 'The status code returned from the GitHub API'],
|
123
|
+
['GITHUB_UNLOCK_ISSUE_RESPONSE', 'The full response body from the GitHub API'],
|
124
|
+
['GITHUB_UNLOCK_ISSUE_JSON', 'The parsed JSON returned from the GitHub API']
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
def return_value
|
129
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
130
|
+
end
|
131
|
+
|
132
|
+
def authors
|
133
|
+
["crazymanish"]
|
134
|
+
end
|
135
|
+
|
136
|
+
def example_code
|
137
|
+
[
|
138
|
+
'github_unlock_issue(
|
139
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
140
|
+
repo_owner: "fastlane",
|
141
|
+
repo_name: "fastlane",
|
142
|
+
issue_number: 123
|
143
|
+
)'
|
144
|
+
]
|
145
|
+
end
|
146
|
+
|
147
|
+
def category
|
148
|
+
:source_control
|
149
|
+
end
|
150
|
+
|
151
|
+
def is_supported?(platform)
|
152
|
+
true
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/github_api_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
GITHUB_UPDATE_ISSUE_STATUS_CODE = :GITHUB_UPDATE_ISSUE_STATUS_CODE
|
8
|
+
GITHUB_UPDATE_ISSUE_RESPONSE = :GITHUB_UPDATE_ISSUE_RESPONSE
|
9
|
+
GITHUB_UPDATE_ISSUE_JSON = :GITHUB_UPDATE_ISSUE_JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
class GithubUpdateIssueAction < 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
|
+
|
24
|
+
# Validate parameters
|
25
|
+
UI.user_error!("No GitHub issue number given, pass using `issue_number: 123`") unless issue_number.to_s.length > 0
|
26
|
+
|
27
|
+
# Build the path
|
28
|
+
path = "/repos/#{repo_owner}/#{repo_name}/issues/#{issue_number}"
|
29
|
+
|
30
|
+
# Build body parameters
|
31
|
+
body_params = {}
|
32
|
+
body_params[:title] = params[:title] if params[:title]
|
33
|
+
body_params[:body] = params[:body] if params[:body]
|
34
|
+
body_params[:state] = params[:state] if params[:state]
|
35
|
+
body_params[:assignees] = params[:assignees] if params[:assignees]
|
36
|
+
body_params[:milestone] = params[:milestone] if params[:milestone]
|
37
|
+
body_params[:labels] = params[:labels] if params[:labels]
|
38
|
+
|
39
|
+
UI.message("Updating issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
40
|
+
response = Helper::GithubApiHelper.github_api_request(
|
41
|
+
token: api_token,
|
42
|
+
path: path,
|
43
|
+
params: body_params,
|
44
|
+
method: :patch,
|
45
|
+
server_url: server_url
|
46
|
+
)
|
47
|
+
|
48
|
+
status_code = response[:status]
|
49
|
+
json_response = response[:json]
|
50
|
+
result = {
|
51
|
+
status: status_code,
|
52
|
+
body: response[:body],
|
53
|
+
json: json_response
|
54
|
+
}
|
55
|
+
|
56
|
+
if status_code.between?(200, 299)
|
57
|
+
UI.success("Successfully updated issue ##{issue_number} in #{repo_owner}/#{repo_name}")
|
58
|
+
else
|
59
|
+
UI.error("Error updating issue: #{status_code}")
|
60
|
+
UI.error(response[:body])
|
61
|
+
UI.user_error!("GitHub API returned #{status_code}: #{response[:body]}")
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
|
65
|
+
# Store the results in shared values
|
66
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_ISSUE_STATUS_CODE] = status_code
|
67
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_ISSUE_RESPONSE] = response[:body]
|
68
|
+
Actions.lane_context[SharedValues::GITHUB_UPDATE_ISSUE_JSON] = json_response
|
69
|
+
|
70
|
+
return result
|
71
|
+
end
|
72
|
+
|
73
|
+
#####################################################
|
74
|
+
# @!group Documentation
|
75
|
+
#####################################################
|
76
|
+
|
77
|
+
def description
|
78
|
+
"Updates an existing GitHub issue"
|
79
|
+
end
|
80
|
+
|
81
|
+
def details
|
82
|
+
[
|
83
|
+
"Updates an existing issue in a GitHub repository with the specified parameters.",
|
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/issues#update-an-issue"
|
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
|
+
FastlaneCore::ConfigItem.new(key: :repo_name,
|
112
|
+
env_name: "GITHUB_API_REPO_NAME",
|
113
|
+
description: "Repository name",
|
114
|
+
optional: false,
|
115
|
+
type: String),
|
116
|
+
FastlaneCore::ConfigItem.new(key: :issue_number,
|
117
|
+
env_name: "GITHUB_API_ISSUE_NUMBER",
|
118
|
+
description: "The issue number to update",
|
119
|
+
optional: false,
|
120
|
+
type: Integer),
|
121
|
+
FastlaneCore::ConfigItem.new(key: :title,
|
122
|
+
description: "The title of the issue",
|
123
|
+
optional: true,
|
124
|
+
type: String),
|
125
|
+
FastlaneCore::ConfigItem.new(key: :body,
|
126
|
+
description: "The body content of the issue",
|
127
|
+
optional: true,
|
128
|
+
type: String),
|
129
|
+
FastlaneCore::ConfigItem.new(key: :state,
|
130
|
+
description: "State of the issue (open or closed)",
|
131
|
+
optional: true,
|
132
|
+
type: String,
|
133
|
+
verify_block: proc do |value|
|
134
|
+
UI.user_error!("State must be 'open' or 'closed'") unless ['open', 'closed'].include?(value)
|
135
|
+
end),
|
136
|
+
FastlaneCore::ConfigItem.new(key: :assignees,
|
137
|
+
description: "Array of logins for users to assign to the issue",
|
138
|
+
optional: true,
|
139
|
+
type: Array),
|
140
|
+
FastlaneCore::ConfigItem.new(key: :milestone,
|
141
|
+
description: "The milestone number to associate with this issue",
|
142
|
+
optional: true,
|
143
|
+
type: Integer),
|
144
|
+
FastlaneCore::ConfigItem.new(key: :labels,
|
145
|
+
description: "Array of labels to associate with this issue",
|
146
|
+
optional: true,
|
147
|
+
type: Array)
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
def output
|
152
|
+
[
|
153
|
+
['GITHUB_UPDATE_ISSUE_STATUS_CODE', 'The status code returned from the GitHub API'],
|
154
|
+
['GITHUB_UPDATE_ISSUE_RESPONSE', 'The full response body from the GitHub API'],
|
155
|
+
['GITHUB_UPDATE_ISSUE_JSON', 'The parsed JSON returned from the GitHub API']
|
156
|
+
]
|
157
|
+
end
|
158
|
+
|
159
|
+
def return_value
|
160
|
+
"A hash including the HTTP status code (:status), the response body (:body), and the parsed JSON (:json)."
|
161
|
+
end
|
162
|
+
|
163
|
+
def authors
|
164
|
+
["crazymanish"]
|
165
|
+
end
|
166
|
+
|
167
|
+
def example_code
|
168
|
+
[
|
169
|
+
'github_update_issue(
|
170
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
171
|
+
repo_owner: "fastlane",
|
172
|
+
repo_name: "fastlane",
|
173
|
+
issue_number: 123,
|
174
|
+
title: "Updated Title",
|
175
|
+
body: "Updated description",
|
176
|
+
state: "closed",
|
177
|
+
assignees: ["username1", "username2"],
|
178
|
+
labels: ["bug", "enhancement"]
|
179
|
+
)',
|
180
|
+
'# You can also access the response data
|
181
|
+
result = github_update_issue(
|
182
|
+
api_token: ENV["GITHUB_API_TOKEN"],
|
183
|
+
repo_owner: "fastlane",
|
184
|
+
repo_name: "fastlane",
|
185
|
+
issue_number: 123,
|
186
|
+
state: "closed"
|
187
|
+
)
|
188
|
+
UI.message("Updated issue title: #{result[:json]["title"]}")'
|
189
|
+
]
|
190
|
+
end
|
191
|
+
|
192
|
+
def category
|
193
|
+
:source_control
|
194
|
+
end
|
195
|
+
|
196
|
+
def is_supported?(platform)
|
197
|
+
true
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|